Fix #256037: wrong indentation caused by incorrect bracket matcing - #307271
Fix #256037: wrong indentation caused by incorrect bracket matcing#307271Leonor Azevedo (leonor-a-a-ist) wants to merge 1 commit into
Conversation
…atcing When typing a closing bracket immediately before another closing token, the auto-indent logic could start searching from the wrong column. This sometimes led to matching the wrong opening bracket, causing incorrect indentation. This has been fixed by using the cursor column (where the closing bracket is inserted) as the search bound, or 0 when no valid opening bracket is found. Added regression tests covering different scenarios, including cases like } before ) and ], and ] before ), with varying initial indentation levels.
|
@microsoft-github-policy-service agree company="Instituto Superior Técnico" |
There was a problem hiding this comment.
Pull request overview
Fixes an editor auto-indent edge case where typing a closing bracket immediately before another closing token could cause bracket matching to start from the wrong column, resulting in incorrect indentation. This adjusts the bracket-match search bound to use the cursor column and adds regression tests covering the reported scenarios.
Changes:
- Adjust electric character indentation logic to bound bracket-matching by the cursor column.
- Add regression tests for cases like
}before],]before), and}before)under varying indentation states.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/vs/editor/common/cursor/cursorTypeEditOperations.ts | Updates electric-character indentation bracket-match starting column to avoid mismatching when another closing token follows. |
| src/vs/editor/test/browser/controller/cursor.test.ts | Adds regression tests reproducing issue #256037 and validating correct indentation outcomes. |
| const lastOpenBracketIndex = (lineTokens.getLineContent() + ch).lastIndexOf(electricAction.matchOpenBracket); | ||
| const endColumn = lastOpenBracketIndex === -1 ? 0 : position.column; |
There was a problem hiding this comment.
lastOpenBracketIndex is misleading here because electricAction.matchOpenBracket actually contains the closing bracket text (e.g. } / ] / )), not an opening bracket. Consider renaming this local to something like lastClosingBracketIndex (or removing it entirely if it’s only used for the === -1 check) to avoid future confusion when touching this indentation logic.
| const lastOpenBracketIndex = (lineTokens.getLineContent() + ch).lastIndexOf(electricAction.matchOpenBracket); | |
| const endColumn = lastOpenBracketIndex === -1 ? 0 : position.column; | |
| const lastClosingBracketIndex = (lineTokens.getLineContent() + ch).lastIndexOf(electricAction.matchOpenBracket); | |
| const endColumn = lastClosingBracketIndex === -1 ? 0 : position.column; |
|
Aiday Marlen Kyzy (@aiday-mar) |
When typing a closing bracket immediately before another closing token, the auto-indent logic could start searching from the wrong column. This sometimes led to matching the wrong opening bracket, causing incorrect indentation.
This has been fixed by using the cursor column (where the closing bracket is inserted) as the search bound, or 0 when no valid opening bracket is found.
Added regression tests covering different scenarios, including cases like } before ) and ], and ] before ), with varying initial indentation levels.
Fixes #256037