This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 114555 - highlight search results incorrect after editting changes
Summary: highlight search results incorrect after editting changes
Status: RESOLVED WORKSFORME
Alias: None
Product: editor
Classification: Unclassified
Component: Search (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: David Strupl
URL:
Keywords:
: 119650 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-09-03 20:02 UTC by err
Modified: 2010-10-05 12:38 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description err 2007-09-03 20:02:05 UTC
There are two problems around o.n.m.e.lib2.highlighting.TextSearchHighlighting, the first is a potential race condition
with OffsetsBag, the second is need to recalculate highlights after changes. (Found this doing jVi's search highlight).

== race condition with OffsetsBag ==
Given following after search for "foo" all lines are highlighted
foo
foo foo
foo
foo
Select and delete the second line, the highlight of the third and fourth line disappear. This can be traced to
    public void removeUpdate(DocumentEvent e) {
        this.bag.removeHighlights(e.getOffset() - 1, e.getOffset() + e.getLength() - 1, false);
    }
Both the bag and TextSearchHighlighting respond to the removeUpdate and too many highlights are affected. There are two
issues I think
1) listener race condition. Maybe a bag should have an "addDocumentListener" so it can forward the event after it does
its thing, or have other versions of HighlightChangeEvent that embeds the document event. (NOTE: the code adds the
listeners in the "right" order and comments on it, but the java Document API says "order of delivery is not guaranteed".)
2) Assuming the bag goes first, its not obvious from the documentation what action the hightlighting should take. In
OffsetsBag, there no mention of behavior after doc mods. In particular, what should be done if a hightlighted area is
completely removed? There's a comment in AbstractGapOffset, "The offsets inside the removal area will be moved to its
begining.", so are there a bunch of zero length highlights left laying around? In any case, on a removeUpdate
e.getLength() should never be used for determining bag.removeHighlights()

== recalculate highlights after change ==
Continuing with the initial example, and assuming the first problem is fixed, if you delete some lines and then undo,
the re-inserted lines are not highlighted. Or if I add a new line with "foo" on it, shouldn't it be highlighted. Note
that fixing this, takes care of the first problem.

I solved this problem in jVi by adding "fillInTheBag(startOffset, endOffset, replaceAll)" method, and use it from the
document listeners. jVi sets startOffset and endOffset so complete lines around the change are recalculated; done for
both remove and insert. FYI, the replaceAll flag is used like
                    if(replaceAll) {
                        bag.setHighlights(newBag);
                    } else {
                        int bug = -1;
                        bag.removeHighlights(startOffset, endOffset+bug, false);
                        bag.addAllHighlights(newBag.getHighlights(startOffset,
                                                                  endOffset));
                    }

BTW, newBag.discard() is never called in TextSearchHighlighting
Comment 1 Vitezslav Stejskal 2007-09-06 11:04:45 UTC
Also related to issue #114642.
Comment 2 err 2007-09-06 17:32:59 UTC
(I'm too long winded, I'll sumarize, clearly I hope)
The other issue seems only slightly related. This issue addresses two problems
- "double remove". The bag's document listener will shrink highlights as needed, TextSerachHighlighting does not need to
call removeHighlights with a length; however if a hightlighted area is deleted, the bag shinks it to zero length AFAICT,
it is unclear how to remove those. An interesting example, with search string "java" is
  javajavajava
what should be done after the middle java is removed from the document?
- "recalculate after change". If search string in "abcd" and document has
  abXXcd
what should happen if the XX is deleted. undo of text containing matched string is another example
Comment 3 Vitezslav Stejskal 2007-10-22 15:53:46 UTC
*** Issue 119650 has been marked as a duplicate of this issue. ***
Comment 4 Jiri Prox 2008-04-11 00:41:44 UTC
moving opened issues from TM <= 6.1 to TM=Dev
Comment 5 Max Sauer 2008-11-14 14:05:52 UTC
This should be probably fixed in 7.0 if possible.
Comment 6 Sergey Petrov 2009-04-10 15:40:23 UTC
reproducible with 090410
Comment 7 David Strupl 2010-10-05 12:38:45 UTC
I have just tried in the current dev (with the new view hierarchy) and the examples seem to work ok. Marking this report as wors for me. If something is still broken please reopen and describe the scenario that doesn't work. Thanks.