From 59ebc59190bc1ddf16a1fdec6626495affb10480 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Tue, 23 Apr 2024 23:28:41 +0800 Subject: [PATCH] :bug: fix https://github.com/siyuan-note/siyuan/issues/10933 --- app/src/protyle/toolbar/index.ts | 7 ++++++- app/src/protyle/wysiwyg/index.ts | 5 +++-- app/src/protyle/wysiwyg/keydown.ts | 5 ++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts index 806e5bdd2..a737b1cbe 100644 --- a/app/src/protyle/toolbar/index.ts +++ b/app/src/protyle/toolbar/index.ts @@ -456,6 +456,11 @@ export class Toolbar { } inlineElement.setAttribute("data-type", [...new Set(rangeTypes)].join(" ")); inlineElement.textContent = Constants.ZWSP; + // 在 a 元素中 ctrl+m 需继承其链接,也许不需要?没有用户反馈之前先保持现装 + // if (type !== "a" && rangeTypes.includes("a") && nextElement.dataset.type.split(" ").includes("a") && + // nextElement.isSameNode(previousElement)) { + // inlineElement.setAttribute("data-href", nextElement.getAttribute("data-href")); + // } setFontStyle(inlineElement, textObj); newNodes.push(inlineElement); } else { @@ -1478,7 +1483,7 @@ export class Toolbar { k: inputElement.value, }, (response) => { let searchHTML = ""; - response.data.blocks.forEach((item: { path: string, content: string,name:string }, index: number) => { + response.data.blocks.forEach((item: { path: string, content: string, name: string }, index: number) => { searchHTML += `
${item.name} ${item.content} diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index f94782d3f..52a8238f0 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -1998,7 +1998,7 @@ export class WYSIWYG { const blockRefElement = hasClosestByAttribute(event.target, "data-type", "block-ref"); const aElement = hasClosestByAttribute(event.target, "data-type", "a") || hasClosestByClassName(event.target, "av__celltext--url"); // 数据库中资源文件、链接、电话、邮箱单元格 - let aLink = aElement ? aElement.getAttribute("data-href") : ""; + let aLink = aElement ? (aElement.getAttribute("data-href") || "") : ""; if (aElement && !aLink && aElement.classList.contains("av__celltext--url")) { aLink = aElement.textContent.trim(); if (aElement.dataset.type === "phone") { @@ -2121,7 +2121,8 @@ export class WYSIWYG { return; } - if (aElement && range.toString() === "") { + // 如果aLink 为空时,当 data-type="a inline-math" 可继续后续操作 + if (aElement && range.toString() === "" && aLink) { event.stopPropagation(); event.preventDefault(); let linkAddress = Lute.UnEscapeHTMLStr(aLink); diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts index 5c16332d3..afb94f83a 100644 --- a/app/src/protyle/wysiwyg/keydown.ts +++ b/app/src/protyle/wysiwyg/keydown.ts @@ -171,6 +171,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { nodeElement.querySelector("wbr").remove(); // 光标位于引用结尾后 ctrl+b 偶尔会失效 range = cloneRange; + // 会导致 protyle.toolbar.range 和 range 不一致,先在有问题的地方重置一下 https://github.com/siyuan-note/siyuan/issues/10933 } if (!window.siyuan.menus.menu.element.classList.contains("fn__none") && @@ -594,6 +595,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { return; } const selectText = range.toString(); + // 上下左右光标移动 if (!event.altKey && !event.shiftKey && isNotCtrl(event) && !event.isComposing && (event.key.indexOf("Arrow") > -1)) { // 需使用 editabled,否则代码块会把语言字数算入 @@ -1242,7 +1244,8 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { return false; } if (matchHotKey(menuItem.hotkey, event)) { - protyle.toolbar.range = getEditorRange(protyle.wysiwyg.element); + // 设置 lastHTMLs 会导致 protyle.toolbar.range 和 range 不一致,需重置一下 https://github.com/siyuan-note/siyuan/issues/10933 + protyle.toolbar.range = range; if (["block-ref"].includes(menuItem.name) && protyle.toolbar.range.toString() === "") { return true; }