Skip to content

Commit caebd77

Browse files
committed
Fix bug that prevents other surrounders to act
Subtle issue: I returned null on my surround-with range adjuster which would prevent the whole surround framework to test and apply other surrounders. This fixes #85
1 parent 4d77518 commit caebd77

4 files changed

Lines changed: 17 additions & 4 deletions

File tree

src/de/halirutan/mathematica/codeinsight/editoractions/enter/MathematicaEnterInsideFunctionHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ public Result preprocessEnter(@NotNull final PsiFile file,
136136
if (project != null) {
137137
CodeStyleManager.getInstance(project).adjustLineIndent(editor.getDocument(), caretOffset.get() + 1);
138138
}
139+
PsiDocumentManager.getInstance(file.getProject()).commitDocument(document);
139140
return Result.DefaultForceIndent;
140141
}
141142

src/de/halirutan/mathematica/codeinsight/surround/AbstractSurrounder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.intellij.openapi.util.TextRange;
3030
import com.intellij.psi.PsiElement;
3131
import com.intellij.util.IncorrectOperationException;
32+
import de.halirutan.mathematica.lang.psi.api.MathematicaPsiFile;
3233
import org.jetbrains.annotations.NotNull;
3334
import org.jetbrains.annotations.Nullable;
3435

@@ -42,7 +43,7 @@ abstract class AbstractSurrounder implements Surrounder {
4243

4344
@Override
4445
public boolean isApplicable(@NotNull PsiElement[] elements) {
45-
return true;
46+
return elements.length > 0 && elements[0].getContainingFile() instanceof MathematicaPsiFile;
4647
}
4748

4849
protected abstract String getOpening();

src/de/halirutan/mathematica/codeinsight/surround/MathematicaSurroundDescriptor.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.intellij.psi.PsiElement;
2727
import com.intellij.psi.PsiFile;
2828
import com.intellij.psi.util.PsiTreeUtil;
29+
import de.halirutan.mathematica.lang.psi.api.MathematicaPsiFile;
2930
import org.jetbrains.annotations.NotNull;
3031

3132
/**
@@ -54,7 +55,10 @@ public boolean isExclusive() {
5455
@NotNull
5556
@Override
5657
public PsiElement[] getElementsToSurround(PsiFile file, int startOffset, int endOffset) {
57-
return findElementsInRange(file, startOffset, endOffset);
58+
if (file instanceof MathematicaPsiFile) {
59+
return findElementsInRange(file, startOffset, endOffset);
60+
}
61+
return PsiElement.EMPTY_ARRAY;
5862
}
5963

6064
private PsiElement[] findElementsInRange(PsiFile file, int startOffset, int endOffset) {

src/de/halirutan/mathematica/codeinsight/surround/MathematicaSurroundWithRangeAdjuster.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.intellij.psi.util.PsiUtilBase;
3434
import de.halirutan.mathematica.lang.MathematicaLanguage;
3535
import de.halirutan.mathematica.lang.psi.api.Expression;
36+
import de.halirutan.mathematica.lang.psi.api.MathematicaPsiFile;
3637
import org.jetbrains.annotations.Nullable;
3738

3839
/**
@@ -48,12 +49,18 @@ public class MathematicaSurroundWithRangeAdjuster implements SurroundWithRangeAd
4849
@Nullable
4950
@Override
5051
public TextRange adjustSurroundWithRange(PsiFile file, TextRange selectedRange) {
51-
return adjustSurroundWithRange(file, selectedRange, true);
52+
if (file instanceof MathematicaPsiFile) {
53+
return adjustSurroundWithRange(file, selectedRange, true);
54+
}
55+
return selectedRange;
5256
}
5357

5458
@Nullable
5559
@Override
5660
public TextRange adjustSurroundWithRange(PsiFile file, TextRange selectedRange, boolean hasSelection) {
61+
if (!(file instanceof MathematicaPsiFile)) {
62+
return selectedRange;
63+
}
5764
int startOffset = selectedRange.getStartOffset();
5865
int endOffset = selectedRange.getEndOffset();
5966
if (endOffset < startOffset) {
@@ -103,6 +110,6 @@ public TextRange adjustSurroundWithRange(PsiFile file, TextRange selectedRange,
103110
return bestExpression.getTextRange();
104111
}
105112
}
106-
return null;
113+
return selectedRange;
107114
}
108115
}

0 commit comments

Comments
 (0)