diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/SurroundWithBracketsStrategy.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/SurroundWithBracketsStrategy.java index ab289bb5033..41dee55d993 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/SurroundWithBracketsStrategy.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/SurroundWithBracketsStrategy.java @@ -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); @@ -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); diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/SourceViewer.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/SourceViewer.java index 527a9d1891c..4b18e2cf592 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/SourceViewer.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/SourceViewer.java @@ -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; @@ -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; @@ -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 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); diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/SourceViewerConfiguration.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/SourceViewerConfiguration.java index 9c892ab4db5..2b6f97d46e2 100644 --- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/SourceViewerConfiguration.java +++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/SourceViewerConfiguration.java @@ -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; @@ -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) }; } /**