diff --git a/app/src/protyle/hint/index.ts b/app/src/protyle/hint/index.ts index 95b42ecbe..86e68db92 100644 --- a/app/src/protyle/hint/index.ts +++ b/app/src/protyle/hint/index.ts @@ -36,7 +36,8 @@ export class Hint { public timeId: number; public element: HTMLDivElement; public enableSlash = true; - public enableEmoji = false; + private enableEmoji = true; + public enableExtend = false; public splitChar = ""; public lastIndex = -1; @@ -122,6 +123,10 @@ ${unicode2Emoji(emoji.unicode, true)}`; clearTimeout(this.timeId); return; } + if (!this.enableExtend) { + clearTimeout(this.timeId); + return; + } protyle.toolbar.range = getSelection().getRangeAt(0); const start = getSelectionOffset(protyle.toolbar.range.startContainer as HTMLElement, protyle.wysiwyg.element).start; const currentLineValue = protyle.toolbar.range.startContainer.textContent.substring(0, start) || ""; @@ -194,7 +199,7 @@ ${unicode2Emoji(emoji.unicode, true)}`; data.forEach((hintData, i) => { // https://github.com/siyuan-note/siyuan/issues/1229 提示时,新建文件不应默认选中 let focusClass = ""; - if ((i === 1 && data[i].focus ) || + if ((i === 1 && data[i].focus) || (i === 0 && (data.length === 1 || !data[1].focus))) { focusClass = " b3-list-item--focus"; } @@ -327,7 +332,7 @@ ${unicode2Emoji(emoji.unicode, true)}`; panelElement.nextElementSibling.classList.remove("fn__none"); } } else { - this.element.innerHTML = `
+ this.element.innerHTML = `
${filterEmoji(value, 256, true)}
${unicode2Emoji("2b50", true)}
@@ -365,6 +370,7 @@ ${unicode2Emoji(emoji.unicode, true)}`; if (!nodeElement) { return; } + this.enableExtend = false let id = ""; if (nodeElement) { id = nodeElement.getAttribute("data-node-id"); @@ -466,6 +472,7 @@ ${unicode2Emoji(emoji.unicode, true)}`; blockRender(protyle, protyle.wysiwyg.element); return; } else if (this.splitChar === "/" || this.splitChar === "、") { + this.enableExtend = true; if (value === "((" || value === "{{") { if (value === "((") { hintRef("", protyle); @@ -533,7 +540,6 @@ ${unicode2Emoji(emoji.unicode, true)}`; range.deleteContents(); range.insertNode(document.createTextNode(":")); range.collapse(false); - this.enableEmoji = true; this.genEmojiHTML(protyle); return; } else if (value.indexOf("style") > -1) { @@ -774,11 +780,10 @@ ${unicode2Emoji(emoji.unicode, true)}`; return undefined; } // 冒号前为数字或冒号不进行emoji提示 - if (this.splitChar === ":" && ( - /\d/.test(currentLineValue.substr(this.lastIndex - 1, 1)) || - currentLineValue.substr(this.lastIndex - 1, 2) === "::" - )) { - this.enableEmoji = false; + if (this.splitChar === ":") { + this.enableEmoji = !(/\d/.test(currentLineValue.substr(this.lastIndex - 1, 1)) || + currentLineValue.substr(this.lastIndex - 1, 2) === "::"); + } const lineArray = currentLineValue.split(this.splitChar); const lastItem = lineArray[lineArray.length - 1]; diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index 0611cf7d5..4e1c9c2ef 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -1415,8 +1415,8 @@ export class WYSIWYG { input(protyle, blockElement, range, true); // 搜狗拼音数字后面句号变为点;Mac 反向双引号无法输入 }); } else { - if (event.data === ":") { - protyle.hint.enableEmoji = true; + if ([":", "(", "【", "(", "[", "{", "「", "#", "/", "、"].includes(event.data)) { + protyle.hint.enableExtend = true; } input(protyle, blockElement, range, true); } @@ -1906,7 +1906,7 @@ export class WYSIWYG { pushBack(protyle, newRange); /// #endif }, (isMobile() || window.webkit?.messageHandlers) ? 520 : 0); // Android/iPad 双击慢了出不来 - protyle.hint.enableEmoji = false; + protyle.hint.enableExtend = false; if (window.siyuan.shiftIsPressed) { event.preventDefault(); event.stopPropagation(); diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts index 969a616c9..c87038534 100644 --- a/app/src/protyle/wysiwyg/keydown.ts +++ b/app/src/protyle/wysiwyg/keydown.ts @@ -576,7 +576,6 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { // 上下左右光标移动 if (!event.altKey && !event.shiftKey && !isCtrl(event) && !event.isComposing && (event.key.indexOf("Arrow") > -1)) { - protyle.hint.enableEmoji = false; // 需使用 editabled,否则代码块会把语言字数算入 const nodeEditableElement = getContenteditableElement(nodeElement) || nodeElement; const position = getSelectionOffset(nodeEditableElement, protyle.wysiwyg.element, range); @@ -1156,7 +1155,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { !protyle.hint.element.classList.contains("fn__none") || !protyle.toolbar.subElement.classList.contains("fn__none")) { hideElements(["toolbar", "hint", "util"], protyle); - protyle.hint.enableEmoji = false; + protyle.hint.enableExtend = false; } else if (nodeElement.classList.contains("protyle-wysiwyg--select")) { hideElements(["select"], protyle); countBlockWord([], protyle.block.rootID);