diff --git a/src/actions/commands/insert.ts b/src/actions/commands/insert.ts index 4e7c89f0c2aa..4d3b3bf6ee43 100644 --- a/src/actions/commands/insert.ts +++ b/src/actions/commands/insert.ts @@ -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; diff --git a/test/mode/modeInsert.test.ts b/test/mode/modeInsert.test.ts index ca30bc44b7b3..41b64235c0aa 100644 --- a/test/mode/modeInsert.test.ts +++ b/test/mode/modeInsert.test.ts @@ -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', + end: ['ab|c '], + }); + test('Can handle digraph insert', async () => { await modeHandler.handleMultipleKeyEvents([ 'i',