Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextViewer: use Throttler for firePostSelectionChanged #1695 #1703

Merged
merged 2 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bundles/org.eclipse.jface.text/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1456,6 +1458,7 @@

/** The viewer's text widget */
private StyledText fTextWidget;
private Throttler throttledPostSelection;
/** The viewer's input document */
private IDocument fDocument;
/** The viewer's visible document */
Expand Down Expand Up @@ -1716,7 +1719,7 @@
* @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
Expand Down Expand Up @@ -2613,26 +2616,22 @@

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);
}
});
}
}

/**
Expand Down Expand Up @@ -3396,7 +3395,7 @@
* @return ISlaveDocumentManager
* @since 2.1
*/
protected ISlaveDocumentManager createSlaveDocumentManager() {

Check warning on line 3398 in bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler and API Tools

Other

NORMAL: TextViewer illegally instantiates ChildDocumentManager
return new ChildDocumentManager();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/org.eclipse.ui.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading