mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 06:51:17 +07:00
SSR: Auto-insert pair $ fixes (IDEA-216174)
GitOrigin-RevId: a7ecbd48b2cf895a3f062ce33abfe33bc959f8b3
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0fb2b5ea46
commit
cb63283035
+17
-12
@@ -84,23 +84,28 @@ public class StructuralSearchTypedHandler extends TypedHandlerDelegate {
|
||||
final Caret caret = caretModel.getCurrentCaret();
|
||||
final LogicalPosition position = caret.getLogicalPosition();
|
||||
final int lineStart = document.getLineStartOffset(position.line);
|
||||
final int lineEnd = document.getLineEndOffset(position.line);
|
||||
final CharSequence text = document.getCharsSequence();
|
||||
final int index = lineStart + position.column;
|
||||
if (index < text.length() && text.charAt(index) == '$') {
|
||||
caret.setSelection(index, index + 1);
|
||||
final int offset = lineStart + position.column;
|
||||
final boolean nextIsDollar = offset < text.length() && text.charAt(offset) == '$';
|
||||
if (hasOddDollar(text, lineStart, offset) && nextIsDollar) {
|
||||
caret.setSelection(offset, offset + 1);
|
||||
}
|
||||
final CharSequence line = text.subSequence(lineStart, lineStart + position.column);
|
||||
boolean $ = false;
|
||||
for (int i = 0, max = line.length(); i < max; i++) {
|
||||
if (line.charAt(i) == '$') {
|
||||
$ = !$;
|
||||
}
|
||||
}
|
||||
if (!$) {
|
||||
document.insertString(lineStart + position.column, "$");
|
||||
else if (!hasOddDollar(text, lineStart, lineEnd)) {
|
||||
document.insertString(offset, "$");
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result.CONTINUE;
|
||||
}
|
||||
|
||||
static boolean hasOddDollar(CharSequence text, int start, int end) {
|
||||
boolean $ = false;
|
||||
for (int i = start; i < end; i++) {
|
||||
if (text.charAt(i) == '$') {
|
||||
$ = !$;
|
||||
}
|
||||
}
|
||||
return $;
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -33,6 +33,18 @@ public class StructuralSearchTypedHandlerTest extends BasePlatformTestCase {
|
||||
"$x$<caret> y$<caret>$z $<selection>abc<caret></selection>$");
|
||||
}
|
||||
|
||||
public void testOneDollar() {
|
||||
doTest("asdf<caret>$asdf", "asdf$<caret>$asdf");
|
||||
}
|
||||
|
||||
public void testOddDollar1() {
|
||||
doTest("<caret>ba$", "$<caret>ba$");
|
||||
}
|
||||
|
||||
public void testOddDollar2() {
|
||||
doTest("$ietske<caret>", "$ietske$<caret>");
|
||||
}
|
||||
|
||||
private void doTest(@NotNull String before, @NotNull String after) {
|
||||
myFixture.configureByText(FileTypes.PLAIN_TEXT, before);
|
||||
final Editor editor = myFixture.getEditor();
|
||||
|
||||
Reference in New Issue
Block a user