Skip to content

Commit

Permalink
Incorrect auto-insertion of } on Enter #216 : implementation attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
xonixx committed Jul 6, 2024
1 parent 8503909 commit 9a48618
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ protected Pair<PsiElement, Integer> calculateOffsetToInsertClosingBrace(

AwkStatement awkStatement = (AwkStatement) AwkUtil.findFirstMatchedDeep(awkFile, AwkStatement.class::isInstance);

System.out.println("zzz:"+CharArrayUtil.shiftForwardUntil(text, offset, "\n")+":"+(offset + awkStatement.getTextLength()+1));

if (awkStatement == null) {
return Pair.create(null, CharArrayUtil.shiftForwardUntil(text, offset, "\n"));
}

System.out.println("zzz:"+CharArrayUtil.shiftForwardUntil(text, offset, "\n")+":"+(offset + awkStatement.getTextLength()+1));
System.out.println("awkStatement="+awkStatement.getTextLength());
System.out.println("awkStatement="+awkStatement.getText());

Expand Down
12 changes: 9 additions & 3 deletions src/test/java/intellij_awk/AwkBracesAndQuoteAutoCloseTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,21 @@ public void testEnterCurlyBrace7() {
public void testEnterCurlyBrace8() {
doTest('\n', "function f()\n{<caret>print 123", "function f()\n{\n <caret>print 123\n}");
}
public void testEnterCurlyBrace9() {
public void testEnterCurlyBrace9_1() {
doTestEnterCurlyBraceComplex("if (2)");
}
public void testEnterCurlyBrace10() {
public void testEnterCurlyBrace9_2() {
doTestEnterCurlyBraceComplex("while (2)");
}
public void testEnterCurlyBrace11() {
public void testEnterCurlyBrace9_3() {
doTestEnterCurlyBraceComplex("for(;;)");
}
public void testEnterCurlyBrace10() {
doTest(
'\n',
"function f() {\n if(1){<caret>\n}",
"function f() {\n if(1){\n <caret>\n }\n}");
}

private void doTestEnterCurlyBraceComplex(String opener) {
doTest(
Expand Down

0 comments on commit 9a48618

Please sign in to comment.