diff --git a/php.editor/src/org/netbeans/modules/php/editor/PHPBracesMatcher.java b/php.editor/src/org/netbeans/modules/php/editor/PHPBracesMatcher.java --- a/php.editor/src/org/netbeans/modules/php/editor/PHPBracesMatcher.java +++ b/php.editor/src/org/netbeans/modules/php/editor/PHPBracesMatcher.java @@ -79,6 +79,11 @@ TokenSequence ts = LexUtilities.getPHPTokenSequence(doc, offset); if (ts != null) { + // #240157 + if (searchForward(ts, offset)){ + return null; + } + ts.move(offset); if (!ts.moveNext()) { @@ -159,6 +164,11 @@ TokenSequence ts = LexUtilities.getPHPTokenSequence(doc, offset); if (ts != null) { + // #240157 + if (searchForward(ts, offset)){ + return null; + } + ts.move(offset); if (!ts.moveNext()) { @@ -212,4 +222,38 @@ } } + private boolean searchForward(TokenSequence ts, int offset) { + // if there is a brace token just before a caret position, search foward + // e.g. if (isSomething()^), if (isSomething())^{ + // "^" is the caret + if (context.isSearchingBackward()) { + ts.move(offset); + if (ts.movePrevious()) { + Token previousToken = ts.token(); + if (previousToken != null && isBraceToken(previousToken)) { + return true; + } + } + } + return false; + } + + private static boolean isBraceToken(Token token) { + PHPTokenId id = token.id(); + return LexUtilities.textEquals(token.text(), '(') // NOI18N + || LexUtilities.textEquals(token.text(), ')') // NOI18N + || id == PHPTokenId.PHP_CURLY_OPEN + || id == PHPTokenId.PHP_CURLY_CLOSE + || LexUtilities.textEquals(token.text(), '[') // NOI18N + || LexUtilities.textEquals(token.text(), ']') // NOI18N + || LexUtilities.textEquals(token.text(), '$', '{') // NOI18N + || LexUtilities.textEquals(token.text(), ':') // NOI18N + || id == PHPTokenId.PHP_ENDFOR + || id == PHPTokenId.PHP_ENDFOREACH + || id == PHPTokenId.PHP_ENDIF + || id == PHPTokenId.PHP_ENDSWITCH + || id == PHPTokenId.PHP_ENDWHILE + || id == PHPTokenId.PHP_ELSEIF + || id == PHPTokenId.PHP_ELSE; + } }