Skip to content

Commit

Permalink
Do not auto symbol when using chinese keyboard.
Browse files Browse the repository at this point in the history
  • Loading branch information
cweijan committed Mar 4, 2024
1 parent 7e4ed0b commit 2fa3536
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions resource/vditor/index.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -69,7 +69,7 @@ handler.on("open", (md) => {
onToolbarClick(editor)
}
})
autoSymbal(handler,editor);
autoSymbol(handler,editor);
createContextMenu(editor)
imageParser(config.viewAbsoluteLocal)
scrollEditor(md.scrollTop)
Expand Down
10 changes: 4 additions & 6 deletions resource/vditor/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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 == '{') {
Expand Down

0 comments on commit 2fa3536

Please sign in to comment.