diff --git a/src/actions/actions.ts b/src/actions/actions.ts index 5cb6cefd..baa0a179 100644 --- a/src/actions/actions.ts +++ b/src/actions/actions.ts @@ -131,12 +131,7 @@ export const actions: Action[] = [ }), parseKeysExact(['a'], [Mode.Normal], (vimState, editor) => { - editor.selections = editor.selections.map((selection) => { - const newPosition = positionUtils.right(editor.document, selection.active); - return new vscode.Selection(newPosition, newPosition); - }); - - enterInsertMode(vimState); + enterInsertMode(vimState, false); setModeCursorStyle(vimState.mode, editor); removeTypeSubscription(vimState); }), diff --git a/src/modes.ts b/src/modes.ts index f0610dbc..4b10bf9d 100644 --- a/src/modes.ts +++ b/src/modes.ts @@ -4,12 +4,14 @@ import { HelixState } from './helix_state_types'; import { Mode } from './modes_types'; import { removeTypeSubscription } from './type_subscription'; -export function enterInsertMode(helixState: HelixState): void { +export function enterInsertMode(helixState: HelixState, before = true): void { // To fix https://github.com/jasonwilliams/vscode-helix/issues/14 we should clear selections on entering insert mode // Helix doesn't clear selections on insert but doesn't overwrite the selection either, so our best option is to just clear them const editor = helixState.editorState.activeEditor!; - const activeSelection = editor.selection.active; - editor.selections = [new vscode.Selection(activeSelection, activeSelection)]; + editor.selections = editor.selections.map((selection) => { + const position = before ? selection.anchor : selection.active; + return new vscode.Selection(position, position); + }); helixState.mode = Mode.Insert; setModeContext('extension.helixKeymap.insertMode');