diff --git a/bundles/org.eclipse.jface.text/META-INF/MANIFEST.MF b/bundles/org.eclipse.jface.text/META-INF/MANIFEST.MF index 0ce5366cbf8..18a02e31871 100644 --- a/bundles/org.eclipse.jface.text/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.jface.text/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.jface.text -Bundle-Version: 3.25.0.qualifier +Bundle-Version: 3.25.100.qualifier Bundle-Vendor: %providerName Bundle-Localization: plugin Export-Package: diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java index 984998fe4bc..ca4a0299de8 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java @@ -17,6 +17,7 @@ *******************************************************************************/ package org.eclipse.jface.text; +import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -73,6 +74,7 @@ import org.eclipse.jface.internal.text.StickyHoverManager; import org.eclipse.jface.util.Geometry; import org.eclipse.jface.util.OpenStrategy; +import org.eclipse.jface.util.Throttler; import org.eclipse.jface.viewers.IPostSelectionProvider; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; @@ -1456,6 +1458,7 @@ public void documentRewriteSessionChanged(DocumentRewriteSessionEvent event) { /** The viewer's text widget */ private StyledText fTextWidget; + private Throttler throttledPostSelection; /** The viewer's input document */ private IDocument fDocument; /** The viewer's visible document */ @@ -1716,7 +1719,7 @@ protected IDocumentAdapter createDocumentAdapter() { * @param styles the SWT style bits for the viewer's control */ protected void createControl(Composite parent, int styles) { - + throttledPostSelection= new Throttler(parent.getDisplay(), Duration.ofMillis(getEmptySelectionChangedEventDelay()), this::postSelectionChanged); fTextWidget= createTextWidget(parent, styles); // Support scroll page upon MOD1+MouseWheel @@ -2613,26 +2616,22 @@ private void queuePostSelectionChanged(final boolean fireEqualSelection) { fNumberOfPostSelectionChangedEvents[0]++; fFireEqualPostSelectionChange|= fireEqualSelection; - display.timerExec(getEmptySelectionChangedEventDelay(), new Runnable() { - final int id= fNumberOfPostSelectionChangedEvents[0]; - @Override - public void run() { - if (id == fNumberOfPostSelectionChangedEvents[0]) { - // Check again because this is executed after the delay - if (getDisplay() != null) { - Point selection= fTextWidget.getSelectionRange(); - if (selection != null) { - IRegion r= widgetRange2ModelRange(new Region(selection.x, selection.y)); - if (fFireEqualPostSelectionChange || (r != null && !r.equals(fLastSentPostSelectionChange)) || r == null) { - fLastSentPostSelectionChange= r; - fFireEqualPostSelectionChange= false; - firePostSelectionChanged(selection.x, selection.y); - } - } - } - } + throttledPostSelection.throttledExec(); + } + + private void postSelectionChanged() { + if (fTextWidget == null || fTextWidget.isDisposed()) { + return; + } + Point selection= fTextWidget.getSelectionRange(); + if (selection != null) { + IRegion r= widgetRange2ModelRange(new Region(selection.x, selection.y)); + if (fFireEqualPostSelectionChange || (r != null && !r.equals(fLastSentPostSelectionChange)) || r == null) { + fLastSentPostSelectionChange= r; + fFireEqualPostSelectionChange= false; + firePostSelectionChanged(selection.x, selection.y); } - }); + } } /** diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/multipageeditor/MultiVariablePageTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/multipageeditor/MultiVariablePageTest.java index e07b8238011..b71d3df0963 100644 --- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/multipageeditor/MultiVariablePageTest.java +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/multipageeditor/MultiVariablePageTest.java @@ -150,7 +150,7 @@ public void testPostSelection() throws Throwable { IPostSelectionProvider postProvider = (IPostSelectionProvider) sp; fPostCalled = 0; - ISelectionChangedListener listener = event -> ++fPostCalled; + ISelectionChangedListener listener = event -> fPostCalled += sp != event.getSelectionProvider() ? 1 : 0; try { postProvider.addPostSelectionChangedListener(listener); diff --git a/tests/org.eclipse.ui.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.ui.tests/META-INF/MANIFEST.MF index ab36f1aa765..981ba74ff48 100644 --- a/tests/org.eclipse.ui.tests/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.ui.tests/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Eclipse UI Tests Bundle-SymbolicName: org.eclipse.ui.tests; singleton:=true -Bundle-Version: 3.15.1500.qualifier +Bundle-Version: 3.15.1600.qualifier Eclipse-BundleShape: dir Bundle-Activator: org.eclipse.ui.tests.TestPlugin Bundle-Vendor: Eclipse.org