From c2444572912413395eb3ad11043ed81151da3cda Mon Sep 17 00:00:00 2001 From: cweijan Date: Mon, 15 Jul 2024 23:11:24 +0800 Subject: [PATCH] Fix can't paste on MacOS. --- .gitignore | 3 ++- .vscodeignore | 3 ++- resource/vditor/util.js | 35 ++++++++++++++--------------------- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index bcaef67..4788c9c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ node_modules .vscode-test/ *.vsix package-lock.json -.DS_Store \ No newline at end of file +.DS_Store +yarn.lock \ No newline at end of file diff --git a/.vscodeignore b/.vscodeignore index fdc05fd..cc4d20d 100644 --- a/.vscodeignore +++ b/.vscodeignore @@ -15,4 +15,5 @@ vditor/ build.js public/ lib.js -backlog.md \ No newline at end of file +backlog.md +yarn.lock \ No newline at end of file diff --git a/resource/vditor/util.js b/resource/vditor/util.js index 232bc87..aaaf027 100644 --- a/resource/vditor/util.js +++ b/resource/vditor/util.js @@ -292,34 +292,27 @@ export const autoSymbol = (handler, editor) => { } const isMac = navigator.userAgent.includes('Mac OS'); window.addEventListener('keydown', e => { - if (isMac && isCompose(e) && e.altKey) { - e.preventDefault() - } if (matchShortcut('^⌘e', e) || matchShortcut('^!e', e)) { e.stopPropagation(); e.preventDefault(); return handler.emit("editInVSCode", true); } if (e.code == 'F12') return handler.emit('developerTool') - if (isCompose(e) && e.code == "KeyV") { - if (e.shiftKey) { - navigator.clipboard.readText().then(text => { - if (!text) return; - document.execCommand('insertText', false, text.trim()); - }) - } else { - if (document.getSelection()?.toString()) { document.execCommand("delete") } + if (isCompose(e)) { + if (e.altKey && isMac) { + e.preventDefault() + } + if (e.code == 'KeyV') { + if (e.shiftKey) { + navigator.clipboard.readText().then(text => { + if (!text) return; + document.execCommand('insertText', false, text.trim()); + }) + e.stopPropagation(); + } + e.preventDefault() } - // vscodeEvent.emit('command', 'office.markdown.paste') - e.stopPropagation() - return; } - // 之前某个vscode版本有bug保存不了, 所以在这里触发, 不过现在不会了 - // if (isCompose(e) && e.code == "KeyS" && !e.shiftKey) { - // vscodeEvent.emit("doSave", editor.getValue()) - // e.stopPropagation() - // return; - // } if (!keyCodes.includes(e.keyCode)) return; const selectText = document.getSelection().toString(); if (selectText != "") { return; } @@ -333,7 +326,7 @@ export const autoSymbol = (handler, editor) => { document.execCommand('insertText', false, e.key); document.getSelection().modify('move', 'left', 'character') } - }, true) + }, isMac ? true : undefined) window.onresize = () => { document.getElementById('vditor').style.height = `${document.documentElement.clientHeight}px`