From fb951a7cecbde8bd21388bd73324cbf5c8767c56 Mon Sep 17 00:00:00 2001 From: Opisek Date: Mon, 18 Dec 2023 12:34:46 +0100 Subject: [PATCH] moved remapping logic to index.ts via exposed remap function (#145) --- src/index.ts | 9 ++++++--- src/vim.js | 14 ++++---------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/index.ts b/src/index.ts index 830537c..d652311 100644 --- a/src/index.ts +++ b/src/index.ts @@ -197,12 +197,15 @@ const vimPlugin = ViewPlugin.fromClass( decorations = Decoration.none; waitForCopy = false; handleKey(e: KeyboardEvent, view: EditorView) { - const key = CodeMirror.vimKey(e); - const cm = this.cm; - if (!key) return; + const rawKey = CodeMirror.vimKey(e); + if (!rawKey) return; + const cm = this.cm; let vim = cm.state.vim; if (!vim) return; + + const key = vim.expectLiteralNext ? rawKey : Vim.langmapRemapKey(rawKey); + // clear search highlight if ( key == "" && diff --git a/src/vim.js b/src/vim.js index 7eea2eb..390986f 100644 --- a/src/vim.js +++ b/src/vim.js @@ -851,6 +851,9 @@ export function initVim(CodeMirror) { langmap: function(langmapString, remapCtrl = true) { updateLangmap(langmapString, remapCtrl); }, + langmapRemapKey: function(key) { + return langmapRemapKey(key); + }, // TODO: Expose setOption and getOption as instance methods. Need to decide how to namespace // them, or somehow make them work with the existing CodeMirror setOption/getOption API. setOption: setOption, @@ -883,11 +886,9 @@ export function initVim(CodeMirror) { * execute the bound command if a a key is matched. The function always * returns true. */ - findKey: function(cm, rawKey, origin) { + findKey: function(cm, key, origin) { var vim = maybeInitVimState(cm); - let key = vim.expectLiteralNext ? rawKey : langmapRemapKey(rawKey); - function handleMacroRecording() { var macroModeState = vimGlobalState.macroModeState; if (macroModeState.isRecording) { @@ -2684,10 +2685,6 @@ export function initVim(CodeMirror) { cm.scrollTo(null, y); }, replayMacro: function(cm, actionArgs, vim) { - // when replaying a macro, we must not "double remap" characters - const savedLangMap = langmap; - langmap = parseLangmap(''); - var registerName = actionArgs.selectedCharacter; var repeat = actionArgs.repeat; var macroModeState = vimGlobalState.macroModeState; @@ -2699,9 +2696,6 @@ export function initVim(CodeMirror) { while(repeat--){ executeMacroRegister(cm, vim, macroModeState, registerName); } - - // restore langmap - langmap = savedLangMap; }, enterMacroRecordMode: function(cm, actionArgs) { var macroModeState = vimGlobalState.macroModeState;