Skip to content

Commit

Permalink
Apply the changes in the SWT thread of the text widget
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Feb 11, 2024
1 parent 792018e commit 1d5bd08
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.custom.StyledText;

import aQute.bnd.help.Syntax;

Expand All @@ -52,10 +52,18 @@ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int
String prefix = matcher.group(1);
ICompletionProposal[] found = proposals(prefix, offset);
if (found.length == 1) {
found[0].apply(document);
Display.getDefault().execute(() -> viewer.setSelectedRange(
offset + (found[0].getDisplayString().length() - prefix.length() + 2), 0));
return new ICompletionProposal[0];
StyledText widget = viewer.getTextWidget();
if (widget != null) {
widget.getDisplay().execute(() -> {
if (widget.isDisposed()) {
return;
}
found[0].apply(document);
viewer.setSelectedRange(
offset + (found[0].getDisplayString().length() - prefix.length() + 2), 0);
});
return new ICompletionProposal[0];
}
}
return found;
}
Expand Down

0 comments on commit 1d5bd08

Please sign in to comment.