From bfecf5160a13a1190b0667591ac634285e0bd874 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Thu, 10 Apr 2025 12:24:45 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/14534 --- app/src/protyle/toolbar/Font.ts | 8 ++++---- app/src/protyle/toolbar/index.ts | 19 ++++++++++++++----- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/app/src/protyle/toolbar/Font.ts b/app/src/protyle/toolbar/Font.ts index ce268b821..7faedc256 100644 --- a/app/src/protyle/toolbar/Font.ts +++ b/app/src/protyle/toolbar/Font.ts @@ -368,7 +368,7 @@ export const setFontStyle = (textElement: HTMLElement, textOption: ITextOption) export const hasSameTextStyle = (currentElement: HTMLElement, sideElement: HTMLElement, textObj: ITextOption) => { if (!textObj) { // https://github.com/siyuan-note/siyuan/issues/14019 - if (currentElement.nodeType !== 3 && sideElement.nodeType !== 3 && + if (currentElement && currentElement.nodeType !== 3 && sideElement.nodeType !== 3 && // 当为 span 时,都经过 isArrayEqual 判断 sideElement.style.color === currentElement.style.color && sideElement.style.webkitTextFillColor === currentElement.style.webkitTextFillColor && @@ -384,7 +384,7 @@ export const hasSameTextStyle = (currentElement: HTMLElement, sideElement: HTMLE return false; } if (textObj.type === "id") { - if (currentElement.nodeType !== 3) { + if (currentElement && currentElement.nodeType !== 3) { return currentElement.getAttribute("data-id") === sideElement.getAttribute("data-id") && currentElement.getAttribute("data-subtype") === sideElement.getAttribute("data-subtype") && currentElement.textContent === sideElement.textContent; @@ -396,7 +396,7 @@ export const hasSameTextStyle = (currentElement: HTMLElement, sideElement: HTMLE } if (textObj.type === "file-annotation-ref") { - if (currentElement.nodeType !== 3) { + if (currentElement && currentElement.nodeType !== 3) { return currentElement.getAttribute("data-id") === sideElement.getAttribute("data-id") && currentElement.textContent === sideElement.textContent; } @@ -409,7 +409,7 @@ export const hasSameTextStyle = (currentElement: HTMLElement, sideElement: HTMLE let textShadow = ""; let backgroundColor = ""; let fontSize = ""; - if (currentElement.nodeType !== 3) { + if (currentElement && currentElement.nodeType !== 3) { color = currentElement.style.color; webkitTextFillColor = currentElement.style.webkitTextFillColor; webkitTextStroke = currentElement.style.webkitTextStroke; diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts index 4eda229df..846217d4a 100644 --- a/app/src/protyle/toolbar/index.ts +++ b/app/src/protyle/toolbar/index.ts @@ -242,12 +242,21 @@ export class Toolbar { } const rangeTypes = this.getCurrentType(this.range); - // https://github.com/siyuan-note/siyuan/issues/6501 - // https://github.com/siyuan-note/siyuan/issues/12877 - if (rangeTypes.length === 1 && - ["block-ref", "virtual-block-ref", "file-annotation-ref", "a", "inline-memo", "inline-math", "tag"].includes(rangeTypes[0]) && type === "clear") { - return; + if (rangeTypes.length === 1) { + // https://github.com/siyuan-note/siyuan/issues/6501 + // https://github.com/siyuan-note/siyuan/issues/12877 + if (["block-ref", "virtual-block-ref", "file-annotation-ref", "a", "inline-memo", "inline-math", "tag"].includes(rangeTypes[0]) && type === "clear") { + return; + } + // https://github.com/siyuan-note/siyuan/issues/14534 + if (rangeTypes[0] === "text" && type === "text" && textObj && this.range.startContainer.nodeType === 3 && this.range.startContainer.isSameNode(this.range.endContainer)) { + const selectParentElement = this.range.startContainer.parentElement; + if (selectParentElement && hasSameTextStyle(null, selectParentElement, textObj)) { + return; + } + } } + const selectText = this.range.toString(); fixTableRange(this.range); let previousElement: HTMLElement;