Skip to content

Commit

Permalink
Fix Issues introduced by PR #2051
Browse files Browse the repository at this point in the history
Fixes #2600
Review points implementation
  • Loading branch information
lathapatil authored and merks committed Dec 13, 2024
1 parent 8bd169c commit b7d5b14
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public SurroundWithBracketsStrategy(ISourceViewer sourceViewer) {

@Override
public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
if (bracketsMap.containsKey(command.text)) {
if (command.text != null && bracketsMap.containsKey(command.text)) {
try {
ITextSelection selection= (ITextSelection) sourceViewer.getSelectionProvider().getSelection();
ITextSelection selection= command.fSelection;
if (selection != null && selection.getLength() > 0) {
String selectedText= document.get(selection.getOffset(), selection.getLength());
String closingBracket= bracketsMap.get(command.text);
Expand All @@ -51,12 +51,7 @@ public void customizeDocumentCommand(IDocument document, DocumentCommand command
command.shiftsCaret= false;

// Run this in a UI thread asynchronously to ensure the selection is updated correctly
sourceViewer.getTextWidget().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
sourceViewer.setSelectedRange(command.offset + 1, selectedText.length());
}
});
sourceViewer.getTextWidget().getDisplay().asyncExec(() -> sourceViewer.setSelectedRange(command.offset + 1, selectedText.length()));
}
} catch (BadLocationException e) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.eclipse.jface.text.source;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Stack;
Expand Down Expand Up @@ -59,7 +58,6 @@
import org.eclipse.jface.text.ITextViewerLifecycle;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.SurroundWithBracketsStrategy;
import org.eclipse.jface.text.TextViewer;
import org.eclipse.jface.text.codemining.ICodeMiningProvider;
import org.eclipse.jface.text.contentassist.IContentAssistant;
Expand Down Expand Up @@ -546,12 +544,7 @@ public void configure(SourceViewerConfiguration configuration) {
String[] types= configuration.getConfiguredContentTypes(this);
for (String t : types) {

IAutoEditStrategy[] autoEditStrategies= configuration.getAutoEditStrategies(this, t);
List<IAutoEditStrategy> autoEditStrategiesList= new ArrayList<>(Arrays.asList(autoEditStrategies));
autoEditStrategiesList.add(new SurroundWithBracketsStrategy(this));
IAutoEditStrategy[] newStrategies= autoEditStrategiesList.toArray(new IAutoEditStrategy[0]);

doSetAutoEditStrategies(newStrategies, t);
doSetAutoEditStrategies(configuration.getAutoEditStrategies(this, t), t);
setTextDoubleClickStrategy(configuration.getDoubleClickStrategy(this, t), t);

int[] stateMasks= configuration.getConfiguredTextHoverStateMasks(this, t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.ITextViewerExtension2;
import org.eclipse.jface.text.IUndoManager;
import org.eclipse.jface.text.SurroundWithBracketsStrategy;
import org.eclipse.jface.text.TextViewerUndoManager;
import org.eclipse.jface.text.codemining.ICodeMiningProvider;
import org.eclipse.jface.text.contentassist.IContentAssistant;
Expand Down Expand Up @@ -190,7 +191,7 @@ public org.eclipse.jface.text.IAutoIndentStrategy getAutoIndentStrategy(ISourceV
* @since 3.1
*/
public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
return new IAutoEditStrategy[] { getAutoIndentStrategy(sourceViewer, contentType) };
return new IAutoEditStrategy[] { getAutoIndentStrategy(sourceViewer, contentType), new SurroundWithBracketsStrategy(sourceViewer) };
}

/**
Expand Down

0 comments on commit b7d5b14

Please sign in to comment.