From d998d0c2e1ae722f1d9e3497bee5c20b4d6621cc Mon Sep 17 00:00:00 2001 From: Alexandr Evstigneev Date: Fri, 15 May 2020 15:32:49 +0300 Subject: [PATCH] IDEA-240930 do not highlight both pairs of braces in case: `)(...` IDEA-CR-62605 GitOrigin-RevId: 1d7b1f6054ee75e67cd6c0a751833a380e106640 --- .../BraceHighlightingHandler.java | 2 +- .../highlighting/BraceMatchingUtil.java | 22 ++++++++++--------- .../braceHighlighter/insideSecondBlock.java | 1 + .../insideSecondBlock.java.txt | 1 + .../insideSecondBlock.java | 1 + .../insideSecondBlock.java.txt | 1 + 6 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 platform/lang-impl/testData/editor/braceHighlighter/insideSecondBlock.java create mode 100644 platform/lang-impl/testData/editor/braceHighlighter/insideSecondBlock.java.txt create mode 100644 platform/lang-impl/testData/editor/braceHighlighterBlock/insideSecondBlock.java create mode 100644 platform/lang-impl/testData/editor/braceHighlighterBlock/insideSecondBlock.java.txt diff --git a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceHighlightingHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceHighlightingHandler.java index 88f04ea29c21..4a9acf9a5e2c 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceHighlightingHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceHighlightingHandler.java @@ -185,7 +185,7 @@ public class BraceHighlightingHandler { BraceHighlightingAndNavigationContext context = BraceMatchingUtil.computeHighlightingAndNavigationContext(myEditor, myPsiFile); if (context != null) { - doHighlight(context.currentBraceOffset, false); + doHighlight(context.currentBraceOffset, context.isCaretAfterBrace); offset = context.currentBraceOffset; } else if (offset > 0 && offset < chars.length()) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceMatchingUtil.java b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceMatchingUtil.java index 44659a96fed4..dd81363ef15e 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceMatchingUtil.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceMatchingUtil.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.highlighting; @@ -93,30 +93,30 @@ public class BraceMatchingUtil { if (editor.getSettings().isBlockCursor()) { if (isBeforeLeftBrace && matchBrace(text, fileType, iterator, true)) { - return new BraceHighlightingAndNavigationContext(offsetTokenStart, iterator.getStart()); + return new BraceHighlightingAndNavigationContext(offsetTokenStart, iterator.getStart(), false); } else if (isBeforeRightBrace && matchBrace(text, fileType, iterator, false)) { - return new BraceHighlightingAndNavigationContext(offsetTokenStart, iterator.getStart()); + return new BraceHighlightingAndNavigationContext(offsetTokenStart, iterator.getStart(), false); } else if (isAfterRightBrace && matchBrace(text, preOffsetFileType, preOffsetIterator, false)) { - return new BraceHighlightingAndNavigationContext(preOffsetTokenStart, preOffsetIterator.getStart()); + return new BraceHighlightingAndNavigationContext(preOffsetTokenStart, preOffsetIterator.getStart(), true); } else if (isAfterLeftBrace && matchBrace(text, preOffsetFileType, preOffsetIterator, true)) { - return new BraceHighlightingAndNavigationContext(preOffsetTokenStart, preOffsetIterator.getStart()); + return new BraceHighlightingAndNavigationContext(preOffsetTokenStart, preOffsetIterator.getStart(), true); } } else { if (isAfterRightBrace && matchBrace(text, preOffsetFileType, preOffsetIterator, false)) { - return new BraceHighlightingAndNavigationContext(preOffsetTokenStart, preOffsetIterator.getStart()); + return new BraceHighlightingAndNavigationContext(preOffsetTokenStart, preOffsetIterator.getStart(), true); } else if (isBeforeLeftBrace && matchBrace(text, fileType, iterator, true)) { - return new BraceHighlightingAndNavigationContext(offsetTokenStart, iterator.getEnd()); + return new BraceHighlightingAndNavigationContext(offsetTokenStart, iterator.getEnd(), false); } else if (isAfterLeftBrace && matchBrace(text, preOffsetFileType, preOffsetIterator, true)) { - return new BraceHighlightingAndNavigationContext(preOffsetTokenStart, preOffsetIterator.getEnd()); + return new BraceHighlightingAndNavigationContext(preOffsetTokenStart, preOffsetIterator.getEnd(), true); } else if (isBeforeRightBrace && matchBrace(text, fileType, iterator, false)) { - return new BraceHighlightingAndNavigationContext(offsetTokenStart, iterator.getStart()); + return new BraceHighlightingAndNavigationContext(offsetTokenStart, iterator.getStart(), false); } } return null; @@ -541,10 +541,12 @@ public class BraceMatchingUtil { public static final class BraceHighlightingAndNavigationContext { public final int currentBraceOffset; public final int navigationOffset; + public final boolean isCaretAfterBrace; - public BraceHighlightingAndNavigationContext(int currentBraceOffset, int navigationOffset) { + public BraceHighlightingAndNavigationContext(int currentBraceOffset, int navigationOffset, boolean isCaretAfterBrace) { this.currentBraceOffset = currentBraceOffset; this.navigationOffset = navigationOffset; + this.isCaretAfterBrace = isCaretAfterBrace; } } } diff --git a/platform/lang-impl/testData/editor/braceHighlighter/insideSecondBlock.java b/platform/lang-impl/testData/editor/braceHighlighter/insideSecondBlock.java new file mode 100644 index 000000000000..fdfdd3f9de37 --- /dev/null +++ b/platform/lang-impl/testData/editor/braceHighlighter/insideSecondBlock.java @@ -0,0 +1 @@ +int[ ][ ]; \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/braceHighlighter/insideSecondBlock.java.txt b/platform/lang-impl/testData/editor/braceHighlighter/insideSecondBlock.java.txt new file mode 100644 index 000000000000..aa99d8e77764 --- /dev/null +++ b/platform/lang-impl/testData/editor/braceHighlighter/insideSecondBlock.java.txt @@ -0,0 +1 @@ +int[ ][ ]; \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/braceHighlighterBlock/insideSecondBlock.java b/platform/lang-impl/testData/editor/braceHighlighterBlock/insideSecondBlock.java new file mode 100644 index 000000000000..fdfdd3f9de37 --- /dev/null +++ b/platform/lang-impl/testData/editor/braceHighlighterBlock/insideSecondBlock.java @@ -0,0 +1 @@ +int[ ][ ]; \ No newline at end of file diff --git a/platform/lang-impl/testData/editor/braceHighlighterBlock/insideSecondBlock.java.txt b/platform/lang-impl/testData/editor/braceHighlighterBlock/insideSecondBlock.java.txt new file mode 100644 index 000000000000..aa99d8e77764 --- /dev/null +++ b/platform/lang-impl/testData/editor/braceHighlighterBlock/insideSecondBlock.java.txt @@ -0,0 +1 @@ +int[ ][ ]; \ No newline at end of file