Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 343522

Summary: TextViewer post Selection does not seem to fire if text is changed
Product: [Eclipse Project] Platform Reporter: Artur Kronenberg <artur.kronenberg>
Component: TextAssignee: Platform-Text-Inbox <platform-text-inbox>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, remy.suen
Version: 3.6.2   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Artur Kronenberg CLA 2011-04-21 08:52:24 EDT
Hi,

In my application, I have a validation going on where I validate against a database. To not do that on every ModifyEvent I registered a PostSelectionListener to my TextViewer. Everything seems to work except for one thing which I think should be working too:

If you modify the text and the  previous and future text are not of equal length, a SelectionEvent is fired. However if you remove 1 character and add 1 character right away there is no even fired for that.

So doing this quickly:

1234 // 1st input
123  // 2nd input
1235 // 3rd input 

will not fire a selection event even though selection has changed.

Is this behavior intended? If it is, can I work around that or do I have to implement my own PostSelectionListener for the TextViewer's modify event? 

Kind regards,

-- Artur
Comment 1 Dani Megert CLA 2011-04-21 09:15:26 EDT
This works as designed: the post selection listener fires if the selection changed after the given delay. If the selection is the same, then nothing happens.

It looks like what you want is to trigger the work after the text has been changed but not on each keystroke. To do that you should use a reconciler. See org.eclipse.jface.text.source.SourceViewerConfiguration.getReconciler(ISourceViewer) for details. You might also want to look at:
http://www.eclipse.org/eclipse/platform-text/eclipseCon/2006/texteditorrecipes.zip