<C-u> in insert mode deletes line break when used at start of line

Fixes #6429
This commit is contained in:
Jason Fields 2021-04-06 23:21:43 -04:00
parent 594b308597
commit 057cfc58ed
2 changed files with 40 additions and 20 deletions

View File

@ -536,13 +536,20 @@ class CommandCtrlUInInsertMode extends BaseCommand {
keys = ['<C-u>'];
public async exec(position: Position, vimState: VimState): Promise<void> {
const start = position.isInLeadingWhitespace(vimState.document)
? position.getLineBegin()
: position.getLineBeginRespectingIndent(vimState.document);
let start: Position;
if (position.character === 0) {
start = position.getLeftThroughLineBreaks(true);
} else if (position.isInLeadingWhitespace(vimState.document)) {
start = position.getLineBegin();
} else {
start = position.getLineBeginRespectingIndent(vimState.document);
}
vimState.recordedState.transformer.addTransformation({
type: 'deleteRange',
range: new Range(start, position),
});
vimState.cursorStopPosition = start;
vimState.cursorStartPosition = start;
}

View File

@ -131,25 +131,38 @@ suite('Mode Insert', () => {
end: ['foo|bar'],
});
newTest({
title: '<C-u> deletes to start of line',
start: ['text |text'],
keysPressed: 'i<C-u>',
end: ['|text'],
});
suite('<C-u>', () => {
newTest({
title: '<C-u> deletes to start of line',
start: ['text |text'],
keysPressed: 'i<C-u>',
end: ['|text'],
endMode: Mode.Insert,
});
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 characters',
start: ['{', ' foo: |true', '}'],
keysPressed: 'i<C-u>',
end: ['{', ' |true', '}'],
endMode: Mode.Insert,
});
newTest({
title: 'Can handle <C-u> on leading whitespace',
start: ['{', ' |true', '}'],
keysPressed: 'i<C-u>',
end: ['{', '|true', '}'],
newTest({
title: 'Can handle <C-u> on leading whitespace',
start: ['{', ' |true', '}'],
keysPressed: 'i<C-u>',
end: ['{', '|true', '}'],
endMode: Mode.Insert,
});
newTest({
title: '<C-u> at start of line deletes line break',
start: ['one', '|two', 'three'],
keysPressed: 'i<C-u>',
end: ['one|two', 'three'],
endMode: Mode.Insert,
});
});
test('Correctly places the cursor after deleting the previous line break', async () => {