diff --git a/resource/vditor/index.js b/resource/vditor/index.js index 4b17e21..3d463aa 100644 --- a/resource/vditor/index.js +++ b/resource/vditor/index.js @@ -1,4 +1,4 @@ -import { openLink, hotKeys, imageParser, toolbar, autoSymbal, onToolbarClick, createContextMenu, scrollEditor } from "./util.js"; +import { openLink, hotKeys, imageParser, toolbar, autoSymbol, onToolbarClick, createContextMenu, scrollEditor } from "./util.js"; handler.on("open", (md) => { const { config, language } = md; @@ -69,7 +69,7 @@ handler.on("open", (md) => { onToolbarClick(editor) } }) - autoSymbal(handler,editor); + autoSymbol(handler,editor); createContextMenu(editor) imageParser(config.viewAbsoluteLocal) scrollEditor(md.scrollTop) diff --git a/resource/vditor/util.js b/resource/vditor/util.js index 26288c0..88394e3 100644 --- a/resource/vditor/util.js +++ b/resource/vditor/util.js @@ -260,8 +260,9 @@ export const imageParser = (viewAbsoluteLocal) => { /** * 自动补全符号 */ -const keys = ['"', "{", "("]; -export const autoSymbal = (handler, editor) => { +// const keys = ['"', "{", "("]; +const keyCodes = [222,219,57]; +export const autoSymbol = (handler, editor) => { let _exec = document.execCommand.bind(document) document.execCommand = (cmd, ...args) => { if (cmd === 'delete') { @@ -293,12 +294,9 @@ export const autoSymbal = (handler, editor) => { // e.stopPropagation() // return; // } - if (!keys.includes(e.key)) { - return; - } + if (!keyCodes.includes(e.keyCode)) return; const selectText = document.getSelection().toString(); if (selectText != "") { return; } - if (e.key == '(') { document.execCommand('insertText', false, ')'); } else if (e.key == '{') {