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.
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
Also related to issue #114642.
(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
*** Issue 119650 has been marked as a duplicate of this issue. ***
moving opened issues from TM <= 6.1 to TM=Dev
This should be probably fixed in 7.0 if possible.
reproducible with 090410
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.