Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

nsIFind: searching in dynamically inserted content

10 views
Skip to first unread message

Jan Odvarko

unread,
Apr 14, 2009, 3:36:55 PM4/14/09
to
I am using nsIFind & nsIDOMRange to search within a Firebug panel (an
HTML page) for specific text. All works fine until I need to search
also within dynamically inserted content.

The scenario is as follows.

#1) The page, displays a list of expandable items. If an item is
expanded, its body is dynamically inserted into the page (just another
piece of HTML).

#2) The search should include current HTML on the page and also all
bodies that don't have to exist on the page (typically all items are
collapsed).

#3) If the search algorithm, finds out that the specified text is
within a body that is *not* currently displayed, the body (HTML) is
dynamically inserted (visually, the item is automatically expanded).

#4) The new created DOM is immediately used to create a DOM range and
passed to range-finder (nsIFind). But it always returns null even if
the text is there (I can see it on the page)...

If I execute the step #4 asynchronously, it works and the finder
returns proper range (nsIDOMRange).

Is it possible that the page must be somehow relayouted before it's
ready for the search? If this theory is correct, can I force the page
to be relayouted synchronously?

Thanks for any tips!
(I am currently quite struggling with this)

Honza

Boris Zbarsky

unread,
Apr 14, 2009, 3:57:17 PM4/14/09
to
Jan Odvarko wrote:
> #4) The new created DOM is immediately used to create a DOM range and
> passed to range-finder (nsIFind). But it always returns null even if
> the text is there (I can see it on the page)...
>
> If I execute the step #4 asynchronously, it works and the finder
> returns proper range (nsIDOMRange).

Does doing |document.body.offsetWidth;| on the document in question
between inserting the new DOM nodes and making the nsIFind call make
things work?

-Boris

Jan Odvarko

unread,
Apr 14, 2009, 4:22:57 PM4/14/09
to
> Does doing |document.body.offsetWidth;| on the document in question
> between inserting the new DOM nodes and making the nsIFind call make
> things work?
Oh yea, this is the magic I needed, thanks!
So, I guess reading this property, forces page layout?
Honza


Robert O'Callahan

unread,
Apr 14, 2009, 5:03:43 PM4/14/09
to

Yes.

This means that nsIFind just needs to call FlushPendingNotifications in
the appropriate methods.

Rob

Boris Zbarsky

unread,
Apr 14, 2009, 5:38:55 PM4/14/09
to
Robert O'Callahan wrote:
> This means that nsIFind just needs to call FlushPendingNotifications in
> the appropriate methods.

Exactly. Jan, can you please file a bug on this?

-Boris

Jan Odvarko

unread,
Apr 15, 2009, 1:40:18 AM4/15/09
to
> Jan, can you please file a bug on this?
Sure, here is the bug:
https://bugzilla.mozilla.org/show_bug.cgi?id=488427

Honza

0 new messages