From 21bedd347d4091e0f9697f84fee8df02acd196a5 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Fri, 30 Sep 2022 22:44:39 +0800 Subject: [PATCH] :bug: fix https://github.com/siyuan-note/siyuan/issues/6020 --- app/src/protyle/hint/index.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/app/src/protyle/hint/index.ts b/app/src/protyle/hint/index.ts index 4da0d4df2..1866e2753 100644 --- a/app/src/protyle/hint/index.ts +++ b/app/src/protyle/hint/index.ts @@ -123,15 +123,14 @@ ${unicode2Emoji(emoji.unicode, true)}`; clearTimeout(this.timeId); return; } - const range = getSelection().getRangeAt(0); - const start = getSelectionOffset(range.startContainer as HTMLElement, protyle.wysiwyg.element).start; - const currentLineValue = range.startContainer.textContent.substring(0, start) || ""; + 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) || ""; const key = this.getKey(currentLineValue, protyle.options.hint.extend); - if (typeof key === "undefined" || ( // 除 emoji 提示外,其余在 tag/inline math/inline-code 内移动不进行提示 this.splitChar !== ":" && - (protyle.toolbar.getCurrentType(range).length > 0 || hasClosestByAttribute(range.startContainer, "data-type", "NodeCodeBlock")) + (protyle.toolbar.getCurrentType(protyle.toolbar.range).length > 0 || hasClosestByAttribute(protyle.toolbar.range.startContainer, "data-type", "NodeCodeBlock")) ) ) { this.element.classList.add("fn__none"); @@ -369,9 +368,9 @@ ${unicode2Emoji(emoji.unicode, true)}`; public fill(value: string, protyle: IProtyle) { hideElements(["hint", "toolbar"], protyle); - const range: Range = getEditorRange(protyle.wysiwyg.element); - - let nodeElement = hasClosestBlock(range.startContainer) as HTMLElement; + protyle.toolbar.range = getEditorRange(protyle.wysiwyg.element); + const range = protyle.toolbar.range; + let nodeElement = hasClosestBlock(protyle.toolbar.range.startContainer) as HTMLElement; if (!nodeElement) { return; } @@ -533,7 +532,6 @@ ${unicode2Emoji(emoji.unicode, true)}`; } else if (Constants.INLINE_TYPE.includes(value)) { range.deleteContents(); focusByRange(range); - protyle.toolbar.range = range; if (["a", "block-ref", "inline-math", "inline-memo", "text"].includes(value)) { protyle.toolbar.element.querySelector(`[data-type="${value}"]`).dispatchEvent(new CustomEvent("block-ref" === value ? getEventName() : "click")); return;