- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delete matching bracket upon backspace #1267
Merged
+54
−2
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
33c3b1a
Merge pull request #1 from VSCodeVim/master
ursuscamp 794ad41
delete matching brackets when the opening bracket is deleted
99e1b0d
check for autoClosingBrackets before deleting a closing bracket
75e2cae
adding quote characters to bracket deletion
04a81ae
minor tweaks for using const and removing unnecessary branch
93d9859
Merge branch 'master' into master
ursuscamp 8b62526
Merge branch 'master' into master
ursuscamp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
delete matching brackets when the opening bracket is deleted
- v1.29.0
- v1.28.1
- v1.28.0
- v1.27.3
- v1.27.2
- v1.27.1
- v1.27.0
- v1.26.2
- v1.26.1
- v1.26.0
- v1.25.2
- v1.25.1
- v1.24.3
- v1.24.2
- v1.24.1
- v1.24.0
- v1.23.2
- v1.23.1
- v1.23.0
- v1.22.2
- v1.22.1
- v1.22.0
- v1.21.10
- v1.21.9
- v1.21.8
- v1.21.7
- v1.21.6
- v1.21.5
- v1.21.4
- v1.21.3
- v1.21.2
- v1.21.1
- v1.21.0
- v1.20.3
- v1.20.2
- v1.20.1
- v1.20.0
- v1.19.3
- v1.19.2
- v1.19.1
- v1.19.0
- v1.18.9
- v1.18.8
- v1.18.7
- v1.18.5
- v1.18.4
- v1.18.3
- v1.18.2
- v1.18.0
- v1.17.1
- v1.17.0
- v1.16.0
- v1.15.0
- v1.14.5
- v1.14.4
- v1.14.3
- v1.14.2
- v1.14.1
- v1.14.0
- v1.13.1
- v1.13.0
- v1.12.4
- v1.12.3
- v1.12.0
- v1.11.3
- v1.11.2
- v1.11.1
- v1.11.0
- v1.10.2
- v1.10.1
- v1.10.0
- v1.9.0
- v1.8.2
- v1.8.1
- v1.8.0
- v1.7.1
- v1.7.0
- v1.4.0
- v1.3.0
- v1.2.0
- v1.1.0
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v0.17.3
- v0.17.2
- v0.17.1
- v0.17.0
- v0.16.14
- v0.16.13
- v0.16.12
- v0.16.11
- v0.16.10
- v0.16.9
- v0.16.8
- v0.16.7
- v0.16.6
- v0.16.5
- v0.16.4
- v0.16.3
- v0.16.2
- v0.16.1
- v0.16.0
- v0.15.7
- v0.15.6
- v0.15.5
- v0.15.4
- v0.15.3
- v0.15.2
- v0.15.1
- v0.15.0
- v0.14.2
- v0.14.1
- v0.14.0
- v0.13.1
- v0.13.0
- v0.12.0
- v0.11.6
- v0.11.5
- v0.11.4
- v0.11.3
- v0.11.2
- v0.11.1
- v0.11.0
- v0.10.13
- v0.10.12
- v0.10.11
- v0.10.10
- v0.10.9
- v0.10.8
- v0.10.7
- v0.10.6
- v0.10.5
- v0.10.4
- v0.10.3
- v0.10.2
- v0.10.1
- v0.10.0
- v0.9.0
- v0.8.7
- v0.8.6
- v0.8.5
- v0.8.4
- v0.8.3
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.1
- v0.7.0
- v0.6.20
- v0.6.19
- v0.6.18
- v0.6.17
- v0.6.16
- v0.6.13
- v0.6.11
- v0.6.10
- v0.6.9
- v0.6.8
- v0.6.7
- v0.6.6
- v0.6.5
- v0.6.4
- v0.6.3
- v0.6.0
- v0.5.3
- rm
- beta
- 0.6.15
- 0.6.14
- 0.6.12
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { Position } from './../motion/position'; | ||
import { Position, PositionDiff } from './../motion/position'; | ||
import * as vscode from 'vscode'; | ||
|
||
/** | ||
* PairMatcher finds the position matching the given character, respecting nested | ||
|
@@ -62,4 +63,29 @@ export class PairMatcher { | |
// TODO(bell) | ||
return undefined; | ||
} | ||
|
||
/** | ||
* Given a current position, find an immediate following bracket and return the range. If | ||
* no matching bracket is found immediately following the opening bracket, return undefined. | ||
*/ | ||
static immediateMatchingBracket(currentPosition: Position): vscode.Range | undefined { | ||
let deleteRange = new vscode.Range(currentPosition, currentPosition.getLeftThroughLineBreaks()); | ||
let deleteText = vscode.window.activeTextEditor.document.getText(deleteRange); | ||
let matchRange: vscode.Range | undefined; | ||
let isNextMatch = false; | ||
|
||
if ("{[(<".indexOf(deleteText) > -1) { | ||
let matchPosition = currentPosition.add(new PositionDiff(0, 1)); | ||
if (matchPosition) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need this |
||
matchRange = new vscode.Range(matchPosition, matchPosition.getLeftThroughLineBreaks()); | ||
isNextMatch = vscode.window.activeTextEditor.document.getText(matchRange) === PairMatcher.pairings[deleteText].match; | ||
} | ||
} | ||
|
||
if (isNextMatch && matchRange) { | ||
return matchRange; | ||
} | ||
|
||
return undefined; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can make all these declarations
const
.