From 1bdab8436dab8d74c7e4cb4c677a81f432bd3a51 Mon Sep 17 00:00:00 2001 From: jasonwilliams Date: Mon, 29 Jan 2024 22:07:10 +0000 Subject: [PATCH] - Clear selections on insert fixes #14 - Fix #15 --- src/actions/motions.ts | 12 ++++++++++-- src/modes.ts | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/actions/motions.ts b/src/actions/motions.ts index 4237c35a..3de58ac8 100644 --- a/src/actions/motions.ts +++ b/src/actions/motions.ts @@ -19,18 +19,26 @@ import { whitespaceWordRanges, wordRanges } from '../word_utils'; import KeyMap from './keymaps'; export const motions: Action[] = [ - parseKeysExact([KeyMap.Motions.MoveRight], [Mode.Normal, Mode.Visual], (vimState, editor) => { + parseKeysExact([KeyMap.Motions.MoveRight], [Mode.Visual], (vimState, editor) => { execMotion(vimState, editor, ({ document, position }) => { return positionUtils.rightNormal(document, position, vimState.resolveCount()); }); }), - parseKeysExact([KeyMap.Motions.MoveLeft], [Mode.Normal, Mode.Visual], (vimState, editor) => { + parseKeysExact([KeyMap.Motions.MoveLeft], [Mode.Visual], (vimState, editor) => { execMotion(vimState, editor, ({ position }) => { return positionUtils.left(position, vimState.resolveCount()); }); }), + parseKeysExact([KeyMap.Motions.MoveRight], [Mode.Normal], () => { + vscode.commands.executeCommand('cursorRight'); + }), + + parseKeysExact([KeyMap.Motions.MoveLeft], [Mode.Normal], () => { + vscode.commands.executeCommand('cursorLeft'); + }), + parseKeysExact([KeyMap.Motions.MoveUp], [Mode.Normal], (_vimState, _editor) => { vscode.commands.executeCommand('cursorMove', { to: 'up', diff --git a/src/modes.ts b/src/modes.ts index 0ce75ef2..f0610dbc 100644 --- a/src/modes.ts +++ b/src/modes.ts @@ -5,6 +5,12 @@ import { Mode } from './modes_types'; import { removeTypeSubscription } from './type_subscription'; export function enterInsertMode(helixState: HelixState): 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)]; + helixState.mode = Mode.Insert; setModeContext('extension.helixKeymap.insertMode'); helixState.commandLine.setText('', helixState);