Skip to content

Commit

Permalink
Fix can't paste on MacOS.
Browse files Browse the repository at this point in the history
  • Loading branch information
cweijan committed Jul 15, 2024
1 parent 5c1072d commit c244457
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_modules
.vscode-test/
*.vsix
package-lock.json
.DS_Store
.DS_Store
yarn.lock
3 changes: 2 additions & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ vditor/
build.js
public/
lib.js
backlog.md
backlog.md
yarn.lock
35 changes: 14 additions & 21 deletions resource/vditor/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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`
Expand Down

0 comments on commit c244457

Please sign in to comment.