From dea3a1d99c2c12fcc71277033102777e8016733f Mon Sep 17 00:00:00 2001 From: xconverge Date: Sun, 21 Aug 2016 16:44:47 -0700 Subject: [PATCH 1/3] updating the undo tree when using bracket operators slightly --- src/mode/modeHandler.ts | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/mode/modeHandler.ts b/src/mode/modeHandler.ts index b8220949143..e90cab84774 100644 --- a/src/mode/modeHandler.ts +++ b/src/mode/modeHandler.ts @@ -742,12 +742,31 @@ export class ModeHandler implements vscode.Disposable { } } - // [({< keys all start a new undo state. + ranRepeatableAction = ranRepeatableAction && vimState.currentMode === ModeName.Normal; + ranAction = ranAction && vimState.currentMode === ModeName.Normal; + + // }])> keys all start a new undo state when directly next to an {[(< opening character const key = vimState.recordedState.actionKeys[vimState.recordedState.actionKeys.length - 1]; - ranRepeatableAction = (ranRepeatableAction && vimState.currentMode === ModeName.Normal) || - (vimState.currentMode === ModeName.Insert && "<[({".indexOf(key) !== -1); - ranAction = ranAction && vimState.currentMode === ModeName.Normal; + if (vimState.currentMode === ModeName.Insert) { + const letterToTheLeft = TextEditor.getLineAt(vimState.cursorPosition).text[vimState.cursorPosition.character - 2]; + switch (key) { + case "}": + if (letterToTheLeft === "{") { ranRepeatableAction = true; } + break; + case "]": + if (letterToTheLeft === "[") { ranRepeatableAction = true; } + break; + case ")": + if (letterToTheLeft === "(") { ranRepeatableAction = true; } + break; + case ">": + if (letterToTheLeft === "<") { ranRepeatableAction = true; } + break; + default: + break; + } + } // Record down previous action and flush temporary state From 12fb0bd6cb059377db17826156242206fa4bcdb7 Mon Sep 17 00:00:00 2001 From: xconverge Date: Mon, 22 Aug 2016 07:55:21 -0700 Subject: [PATCH 2/3] Moved bracket undo point check to a new function --- src/mode/modeHandler.ts | 53 ++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/src/mode/modeHandler.ts b/src/mode/modeHandler.ts index e90cab84774..819977dbed2 100644 --- a/src/mode/modeHandler.ts +++ b/src/mode/modeHandler.ts @@ -742,34 +742,10 @@ export class ModeHandler implements vscode.Disposable { } } - ranRepeatableAction = ranRepeatableAction && vimState.currentMode === ModeName.Normal; + ranRepeatableAction = (ranRepeatableAction && vimState.currentMode === ModeName.Normal) || this.createUndoPointForBrackets(vimState); ranAction = ranAction && vimState.currentMode === ModeName.Normal; - // }])> keys all start a new undo state when directly next to an {[(< opening character - const key = vimState.recordedState.actionKeys[vimState.recordedState.actionKeys.length - 1]; - - if (vimState.currentMode === ModeName.Insert) { - const letterToTheLeft = TextEditor.getLineAt(vimState.cursorPosition).text[vimState.cursorPosition.character - 2]; - switch (key) { - case "}": - if (letterToTheLeft === "{") { ranRepeatableAction = true; } - break; - case "]": - if (letterToTheLeft === "[") { ranRepeatableAction = true; } - break; - case ")": - if (letterToTheLeft === "(") { ranRepeatableAction = true; } - break; - case ">": - if (letterToTheLeft === "<") { ranRepeatableAction = true; } - break; - default: - break; - } - } - // Record down previous action and flush temporary state - if (ranRepeatableAction) { vimState.previousFullAction = vimState.recordedState; } @@ -1092,6 +1068,33 @@ export class ModeHandler implements vscode.Disposable { ModeHandler._statusBarItem.show(); } + // Return true if a new undo point should be created based on the keypress + private createUndoPointForBrackets(vimState: VimState): boolean { + // }])> keys all start a new undo state when directly next to an {[(< opening character + const key = vimState.recordedState.actionKeys[vimState.recordedState.actionKeys.length - 1]; + + if (vimState.currentMode === ModeName.Insert) { + const letterToTheLeft = TextEditor.getLineAt(vimState.cursorPosition).text[vimState.cursorPosition.character - 2]; + switch (key) { + case "}": + if (letterToTheLeft === "{") { return true; } + break; + case "]": + if (letterToTheLeft === "[") { return true; } + break; + case ")": + if (letterToTheLeft === "(") { return true; } + break; + case ">": + if (letterToTheLeft === "<") { return true; } + break; + default: + return false; + } + } + return false; + } + dispose() { // do nothing } From 26de81193e9a7510d1b21a69bbde28b3496ca824 Mon Sep 17 00:00:00 2001 From: xconverge Date: Mon, 22 Aug 2016 18:21:55 -0700 Subject: [PATCH 3/3] fix buffer underrun issue with getting text on line --- src/mode/modeHandler.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/mode/modeHandler.ts b/src/mode/modeHandler.ts index 819977dbed2..c09727d9185 100644 --- a/src/mode/modeHandler.ts +++ b/src/mode/modeHandler.ts @@ -1074,6 +1074,11 @@ export class ModeHandler implements vscode.Disposable { const key = vimState.recordedState.actionKeys[vimState.recordedState.actionKeys.length - 1]; if (vimState.currentMode === ModeName.Insert) { + + if (TextEditor.getLineAt(vimState.cursorPosition).text.length <= 1) { + return false; + } + const letterToTheLeft = TextEditor.getLineAt(vimState.cursorPosition).text[vimState.cursorPosition.character - 2]; switch (key) { case "}":