Skip to content
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

updating the undo tree when using bracket operators slightly #634

Merged
merged 3 commits into from
Aug 24, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this work when vimState.cursorPosition.character - 2 is less than 0?

switch (key) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is getting a little unwieldy, could you pull it into a separate function?

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

Expand Down