Skip to content

Commit

Permalink
Handle backspace on first character of all-space line correctly (VSCo…
Browse files Browse the repository at this point in the history
…deVim#3916)

* Handle backspace on first character of all-space line correctly

Fixes VSCodeVim#3915

* Code review: Use \s in regex
  • Loading branch information
J-Fields authored and stevenguh committed Aug 27, 2019
1 parent cb3a9fc commit 334798a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/actions/commands/insert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,15 @@ export class CommandInsertInInsertMode extends BaseCommand {
range: new Range(selection.start as Position, selection.end as Position),
});
} else {
if (line.length > 0 && line.match(/^ +$/) && configuration.expandtab) {
// If the line is empty except whitespace, backspace should return to
// the next lowest level of indentation.
if (
position.character > 0 &&
line.length > 0 &&
line.match(/^\s+$/) &&
configuration.expandtab
) {
// If the line is empty except whitespace and we're not on the first
// character of the line, backspace should return to the next lowest
// level of indentation.

const tabSize = vimState.editor.options.tabSize as number;
const desiredLineLength = Math.floor((position.character - 1) / tabSize) * tabSize;
Expand Down
8 changes: 8 additions & 0 deletions test/mode/modeInsert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,14 @@ suite('Mode Insert', () => {
end: ['fun', 'fun', 'fun', 'fun', 'fu|n', 'foobar'],
});

// This corner case caused an issue, see #3915
newTest({
title: 'Can handle backspace at beginning of line with all spaces',
start: ['abc', '| '],
keysPressed: 'i<BS><Esc>',
end: ['ab|c '],
});

test('Can handle digraph insert', async () => {
await modeHandler.handleMultipleKeyEvents([
'i',
Expand Down

0 comments on commit 334798a

Please sign in to comment.