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

feat: Update <C-u> insert mode behavior #2805

Merged
merged 2 commits into from
Jul 4, 2018
Merged
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions src/actions/commands/insert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,10 @@ class CommandCtrlUInInsertMode extends BaseCommand {
keys = ['<C-u>'];

public async exec(position: Position, vimState: VimState): Promise<VimState> {
const start = position.getLineBegin();
const stop = position.getLineEnd();
await TextEditor.delete(new vscode.Range(start, stop));
const start = position.isInLeadingWhitespace()
? position.getLineBegin()
: position.getLineBeginRespectingIndent();
await TextEditor.delete(new vscode.Range(start, position));
vimState.cursorPosition = start;
vimState.cursorStartPosition = start;
return vimState;
Expand Down
39 changes: 39 additions & 0 deletions test/mode/modeInsert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,45 @@ suite('Mode Insert', () => {
end: ['foo|bar'],
});

test("Can handle '<C-u>'", async () => {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason you decided to write the test in this style vs the newTest? IMO, should be OK to have this in the style of the newTest like the ones you have below.

Copy link
Author

Choose a reason for hiding this comment

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

I just mimiced the tests above for <C-w>, I'll change it to the newTest style. 👍

await modeHandler.handleMultipleKeyEvents([
'i',
't',
'e',
'x',
't',
' ',
't',
'e',
'x',
't',
'<Esc>',
'^',
'l',
'l',
'l',
'l',
'a',
'<C-u>',
]);

assertEqualLines(['text']);
});

newTest({
title: 'Can handle <C-u> on leading characters',
start: ['{', ' foo: |true', '}'],
keysPressed: 'i<C-u>',
end: ['{', ' |true', '}'],
});

newTest({
title: 'Can handle <C-u> on leading whitespace',
start: ['{', ' |true', '}'],
keysPressed: 'i<C-u>',
end: ['{', '|true', '}'],
});

test('Correctly places the cursor after deleting the previous line break', async () => {
await modeHandler.handleMultipleKeyEvents([
'i',
Expand Down