Skip to content
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
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) {
Copy link
Member

@sratz sratz Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the javadoc of this method says

For backward compatibility, this implementation always returns an array containing the result of {@link #getAutoIndentStrategy(ISourceViewer, String)}.

So we are now breaking this compatibility contract?

return new IAutoEditStrategy[] { getAutoIndentStrategy(sourceViewer, contentType) };
return new IAutoEditStrategy[] { getAutoIndentStrategy(sourceViewer, contentType), new SurroundWithBracketsStrategy(sourceViewer) };
}

/**
Expand Down
Loading