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; } } 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", "");