From 4244c1877903871d416addda3a32c8f7e3d65b8e Mon Sep 17 00:00:00 2001 From: Vanessa Date: Sat, 17 May 2025 16:25:15 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E6=B2=A1=E6=9C=89=E9=80=89=E4=B8=AD?= =?UTF-8?q?=E6=96=87=E6=9C=AC=E7=B2=98=E8=B4=B4=E9=93=BE=E6=8E=A5=E4=B8=8D?= =?UTF-8?q?=E5=BA=94=E9=80=89=E4=B8=AD=E6=95=B4=E4=B8=AA=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/protyle/toolbar/index.ts | 2 +- app/src/protyle/util/paste.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts index 6965ccbda..56c0c042d 100644 --- a/app/src/protyle/toolbar/index.ts +++ b/app/src/protyle/toolbar/index.ts @@ -193,7 +193,7 @@ export class Toolbar { startElement = startElement.parentElement; } else if (startElement.childElementCount > 0 && startElement.childNodes[range.startOffset]?.nodeType !== 3) { startElement = startElement.childNodes[range.startOffset] as HTMLElement; - if (startElement.tagName === "WBR") { + if (startElement?.tagName === "WBR") { startElement = startElement.parentElement; } } diff --git a/app/src/protyle/util/paste.ts b/app/src/protyle/util/paste.ts index 69872b1fa..6bc714047 100644 --- a/app/src/protyle/util/paste.ts +++ b/app/src/protyle/util/paste.ts @@ -544,10 +544,14 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven } } if (linkElement) { + const selectText = range.toString(); protyle.toolbar.setInlineMark(protyle, "a", "range", { type: "a", - color: `${linkElement.getAttribute("href")}${Constants.ZWSP}${range.toString()}` + color: `${linkElement.getAttribute("href")}${Constants.ZWSP}${selectText || linkElement.textContent}` }); + if (!selectText) { + range.collapse(false); + } return; } fetchPost("/api/lute/html2BlockDOM", {