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", {