From 0da7d32667083a3db5c71cb8c07c25a0abd9c167 Mon Sep 17 00:00:00 2001 From: Aaron Zipp Date: Mon, 22 Sep 2025 15:49:09 +0200 Subject: [PATCH 1/2] Prevent double dead keys from being inserted --- src/index.ts | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/src/index.ts b/src/index.ts index 904e61d..7316fb8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -320,33 +320,32 @@ const vimPlugin = ViewPlugin.fromClass( if (text === "\0\0") { return true; } - CodeMirror.signal(cm, 'inputEvent', { - type: "text", - text, - from, - to, - }); - if (text.length == 1 && vimPlugin.useNextTextInput) { - if (vim.expectLiteralNext && view.composing) { - vimPlugin.compositionText = text; - return false - } - if (vimPlugin.compositionText) { - var toRemove = vimPlugin.compositionText; - vimPlugin.compositionText = ''; - var head = view.state.selection.main.head - var textInDoc = view.state.sliceDoc(head - toRemove.length, head); - if (toRemove === textInDoc) { - var pos = cm.getCursor(); - cm.replaceRange('', cm.posFromIndex(head - toRemove.length), pos); + if (vimPlugin.useNextTextInput) { + vimPlugin.useNextTextInput = false; + if (text.length == 1) { + if (vim.expectLiteralNext && view.composing) { + vimPlugin.compositionText = text; + return true; } + if (vimPlugin.compositionText) { + var toRemove = vimPlugin.compositionText; + vimPlugin.compositionText = ''; + var head = view.state.selection.main.head + var textInDoc = view.state.sliceDoc(head - toRemove.length, head); + if (toRemove === textInDoc) { + var pos = cm.getCursor(); + cm.replaceRange('', cm.posFromIndex(head - toRemove.length), pos); + } + } + vimPlugin.handleKey({ + key: text, + preventDefault: ()=>{}, + stopPropagation: ()=>{} + }); + forceEndComposition(view); } - vimPlugin.handleKey({ - key: text, - preventDefault: ()=>{}, - stopPropagation: ()=>{} - }); - forceEndComposition(view); + return true; + } else { return true; } } From 1c1b65f4e9de99a66f2855ef03907058d7cb688c Mon Sep 17 00:00:00 2001 From: Aaron Zipp Date: Mon, 22 Sep 2025 16:19:09 +0200 Subject: [PATCH 2/2] Normalize dead key compositions --- src/vim.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/vim.js b/src/vim.js index 237858b..cb78e93 100644 --- a/src/vim.js +++ b/src/vim.js @@ -1216,6 +1216,10 @@ export function initVim(CM) { */ function vimKeyFromEvent(e, vim) { var key = e.key; + // Normalize repeated dead key compositions (e.g., "^^" -> "^", "йй" -> "й") + if (key.length > 1 && key.split('').every(c => c === key[0])) { + key = key[0]; + } if (ignoredKeys[key]) return; if (key.length > 1 && key[0] == "n") { key = key.replace("Numpad", "");