Browse Source

:art: fix https://github.com/siyuan-note/siyuan/issues/7052

Vanessa 2 years ago
parent
commit
3f77e6fe97

+ 14 - 9
app/src/protyle/hint/index.ts

@@ -36,7 +36,8 @@ export class Hint {
     public timeId: number;
     public timeId: number;
     public element: HTMLDivElement;
     public element: HTMLDivElement;
     public enableSlash = true;
     public enableSlash = true;
-    public enableEmoji = false;
+    private enableEmoji = true;
+    public enableExtend = false;
     public splitChar = "";
     public splitChar = "";
     public lastIndex = -1;
     public lastIndex = -1;
 
 
@@ -122,6 +123,10 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
             clearTimeout(this.timeId);
             clearTimeout(this.timeId);
             return;
             return;
         }
         }
+        if (!this.enableExtend) {
+            clearTimeout(this.timeId);
+            return;
+        }
         protyle.toolbar.range = getSelection().getRangeAt(0);
         protyle.toolbar.range = getSelection().getRangeAt(0);
         const start = getSelectionOffset(protyle.toolbar.range.startContainer as HTMLElement, protyle.wysiwyg.element).start;
         const start = getSelectionOffset(protyle.toolbar.range.startContainer as HTMLElement, protyle.wysiwyg.element).start;
         const currentLineValue = protyle.toolbar.range.startContainer.textContent.substring(0, start) || "";
         const currentLineValue = protyle.toolbar.range.startContainer.textContent.substring(0, start) || "";
@@ -194,7 +199,7 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
         data.forEach((hintData, i) => {
         data.forEach((hintData, i) => {
             // https://github.com/siyuan-note/siyuan/issues/1229 提示时,新建文件不应默认选中
             // https://github.com/siyuan-note/siyuan/issues/1229 提示时,新建文件不应默认选中
             let focusClass = "";
             let focusClass = "";
-            if ((i === 1 && data[i].focus ) ||
+            if ((i === 1 && data[i].focus) ||
                 (i === 0 && (data.length === 1 || !data[1].focus))) {
                 (i === 0 && (data.length === 1 || !data[1].focus))) {
                 focusClass = " b3-list-item--focus";
                 focusClass = " b3-list-item--focus";
             }
             }
@@ -327,7 +332,7 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
                 panelElement.nextElementSibling.classList.remove("fn__none");
                 panelElement.nextElementSibling.classList.remove("fn__none");
             }
             }
         } else {
         } else {
-            this.element.innerHTML = `<div class="emojis" style="height: auto;">
+            this.element.innerHTML = `<div class="emojis">
 <div class="emojis__panel">${filterEmoji(value, 256, true)}</div>
 <div class="emojis__panel">${filterEmoji(value, 256, true)}</div>
 <div class="fn__flex${value ? " fn__none" : ""}">
 <div class="fn__flex${value ? " fn__none" : ""}">
     <div data-type="0" class="emojis__type" aria-label="${window.siyuan.languages.recentEmoji}">${unicode2Emoji("2b50", true)}</div>
     <div data-type="0" class="emojis__type" aria-label="${window.siyuan.languages.recentEmoji}">${unicode2Emoji("2b50", true)}</div>
@@ -365,6 +370,7 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
         if (!nodeElement) {
         if (!nodeElement) {
             return;
             return;
         }
         }
+        this.enableExtend = false
         let id = "";
         let id = "";
         if (nodeElement) {
         if (nodeElement) {
             id = nodeElement.getAttribute("data-node-id");
             id = nodeElement.getAttribute("data-node-id");
@@ -466,6 +472,7 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
             blockRender(protyle, protyle.wysiwyg.element);
             blockRender(protyle, protyle.wysiwyg.element);
             return;
             return;
         } else if (this.splitChar === "/" || this.splitChar === "、") {
         } else if (this.splitChar === "/" || this.splitChar === "、") {
+            this.enableExtend = true;
             if (value === "((" || value === "{{") {
             if (value === "((" || value === "{{") {
                 if (value === "((") {
                 if (value === "((") {
                     hintRef("", protyle);
                     hintRef("", protyle);
@@ -533,7 +540,6 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
                 range.deleteContents();
                 range.deleteContents();
                 range.insertNode(document.createTextNode(":"));
                 range.insertNode(document.createTextNode(":"));
                 range.collapse(false);
                 range.collapse(false);
-                this.enableEmoji = true;
                 this.genEmojiHTML(protyle);
                 this.genEmojiHTML(protyle);
                 return;
                 return;
             } else if (value.indexOf("style") > -1) {
             } else if (value.indexOf("style") > -1) {
@@ -774,11 +780,10 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
             return undefined;
             return undefined;
         }
         }
         // 冒号前为数字或冒号不进行emoji提示
         // 冒号前为数字或冒号不进行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 lineArray = currentLineValue.split(this.splitChar);
         const lastItem = lineArray[lineArray.length - 1];
         const lastItem = lineArray[lineArray.length - 1];

+ 3 - 3
app/src/protyle/wysiwyg/index.ts

@@ -1415,8 +1415,8 @@ export class WYSIWYG {
                     input(protyle, blockElement, range, true); // 搜狗拼音数字后面句号变为点;Mac 反向双引号无法输入
                     input(protyle, blockElement, range, true); // 搜狗拼音数字后面句号变为点;Mac 反向双引号无法输入
                 });
                 });
             } else {
             } else {
-                if (event.data === ":") {
-                    protyle.hint.enableEmoji = true;
+                if ([":", "(", "【", "(", "[", "{", "「", "#", "/", "、"].includes(event.data)) {
+                    protyle.hint.enableExtend = true;
                 }
                 }
                 input(protyle, blockElement, range, true);
                 input(protyle, blockElement, range, true);
             }
             }
@@ -1906,7 +1906,7 @@ export class WYSIWYG {
                 pushBack(protyle, newRange);
                 pushBack(protyle, newRange);
                 /// #endif
                 /// #endif
             }, (isMobile() || window.webkit?.messageHandlers) ? 520 : 0); // Android/iPad 双击慢了出不来
             }, (isMobile() || window.webkit?.messageHandlers) ? 520 : 0); // Android/iPad 双击慢了出不来
-            protyle.hint.enableEmoji = false;
+            protyle.hint.enableExtend = false;
             if (window.siyuan.shiftIsPressed) {
             if (window.siyuan.shiftIsPressed) {
                 event.preventDefault();
                 event.preventDefault();
                 event.stopPropagation();
                 event.stopPropagation();

+ 1 - 2
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)) {
         if (!event.altKey && !event.shiftKey && !isCtrl(event) && !event.isComposing && (event.key.indexOf("Arrow") > -1)) {
-            protyle.hint.enableEmoji = false;
             // 需使用 editabled,否则代码块会把语言字数算入
             // 需使用 editabled,否则代码块会把语言字数算入
             const nodeEditableElement = getContenteditableElement(nodeElement) || nodeElement;
             const nodeEditableElement = getContenteditableElement(nodeElement) || nodeElement;
             const position = getSelectionOffset(nodeEditableElement, protyle.wysiwyg.element, range);
             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.hint.element.classList.contains("fn__none") ||
                 !protyle.toolbar.subElement.classList.contains("fn__none")) {
                 !protyle.toolbar.subElement.classList.contains("fn__none")) {
                 hideElements(["toolbar", "hint", "util"], protyle);
                 hideElements(["toolbar", "hint", "util"], protyle);
-                protyle.hint.enableEmoji = false;
+                protyle.hint.enableExtend = false;
             } else if (nodeElement.classList.contains("protyle-wysiwyg--select")) {
             } else if (nodeElement.classList.contains("protyle-wysiwyg--select")) {
                 hideElements(["select"], protyle);
                 hideElements(["select"], protyle);
                 countBlockWord([], protyle.block.rootID);
                 countBlockWord([], protyle.block.rootID);