🎨 没有选中文本粘贴链接不应选中整个链接

This commit is contained in:
Vanessa 2025-05-17 16:25:15 +08:00
parent 2aeaecf78c
commit 4244c18779
2 changed files with 6 additions and 2 deletions

View file

@ -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;
}
}

View file

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