Merge pull request #1071 from xconverge/support-for-ctrl-o

fixes #1065
This commit is contained in:
Grant Mathews 2016-11-22 18:29:23 -05:00 committed by GitHub
commit 69e3b18c99
4 changed files with 49 additions and 2 deletions

View File

@ -181,6 +181,11 @@
"command": "extension.vim_ctrl+a",
"when": "editorTextFocus && vim.useCtrlKeys && !inDebugRepl"
},
{
"key": "ctrl+o",
"command": "extension.vim_ctrl+o",
"when": "editorTextFocus && vim.useCtrlKeys && !inDebugRepl"
},
{
"key": "ctrl+x",
"command": "extension.vim_ctrl+x",

View File

@ -664,6 +664,17 @@ class CommandInsertRegisterContent extends BaseCommand {
}
@RegisterAction
export class CommandOneNormalCommandInInsertMode extends BaseCommand {
modes = [ModeName.Insert];
keys = ["<C-o>"];
public async exec(position: Position, vimState: VimState): Promise<VimState> {
vimState.returnToInsertAfterCommand = true;
return await new CommandEscInsertMode().exec(position, vimState);
}
}
@RegisterAction
class CommandInsertRegisterContentInSearchMode extends BaseCommand {
modes = [ModeName.SearchInProgressMode];

View File

@ -98,6 +98,12 @@ export class VimState {
public focusChanged = false;
/**
* Used for command like <C-o> which allows you to return to insert after a command
*/
public returnToInsertAfterCommand = false;
public actionCount = 0;
/**
* Every time we invoke a VS Code command which might trigger Code's view update,
* we should postpone its view updating phase to avoid conflicting with our internal view updating mechanism.
@ -822,6 +828,18 @@ export class ModeHandler implements vscode.Disposable {
if (ranAction) {
vimState.recordedState = new RecordedState();
// Return to insert mode after 1 command in this case for <C-o>
if (vimState.returnToInsertAfterCommand) {
if (vimState.actionCount > 0) {
vimState.currentMode = ModeName.Insert;
vimState.returnToInsertAfterCommand = false;
vimState.actionCount = 0;
this.setCurrentModeByName(vimState);
} else {
vimState.actionCount++;
}
}
}
// track undo history

View File

@ -4,13 +4,18 @@ import {setupWorkspace, cleanUpWorkspace, assertEqualLines, assertEqual} from '.
import {ModeName} from '../../src/mode/mode';
import {TextEditor} from '../../src/textEditor';
import {ModeHandler} from "../../src/mode/modeHandler";
import { getTestingFunctions } from '../testSimplifier';
suite("Mode Insert", () => {
let modeHandler: ModeHandler;
let modeHandler: ModeHandler = new ModeHandler();
let {
newTest,
newTestOnly,
} = getTestingFunctions(modeHandler);
setup(async () => {
await setupWorkspace();
modeHandler = new ModeHandler();
});
@ -168,4 +173,12 @@ suite("Mode Insert", () => {
assertEqualLines([" "]);
});
newTest({
title: "Can perform <ctrl+o> to exit and perform one command in normal",
start: ['testtest|'],
keysPressed: 'a123<C-o>b123',
end: ['123|testtest123']
});
});