From 9f0fcd8cbc9577b41ef196f2ff5c1c9b71447216 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Mon, 17 Oct 2022 23:18:24 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/6233 --- app/src/protyle/toolbar/Font.ts | 13 ++++++++++--- app/src/protyle/toolbar/Link.ts | 14 +++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/src/protyle/toolbar/Font.ts b/app/src/protyle/toolbar/Font.ts index 4dc79f769..e250b182e 100644 --- a/app/src/protyle/toolbar/Font.ts +++ b/app/src/protyle/toolbar/Font.ts @@ -157,6 +157,15 @@ export const setFontStyle = (textElement: HTMLElement, textOption: ITextOption) textElement.setAttribute("data-subtype", blockRefData[1]); textElement.innerText = blockRefData[2]; }; + const setLink = (textOption: string) => { + const options = textOption.split(Constants.ZWSP) + textElement.setAttribute("data-href", options[0]); + textElement.removeAttribute("data-subtype"); + textElement.removeAttribute("data-id"); + if (options[1]) { + textElement.textContent = options[1]; + } + }; if (textOption) { switch (textOption.type) { @@ -188,9 +197,7 @@ export const setFontStyle = (textElement: HTMLElement, textOption: ITextOption) textElement.textContent = ""; break; case "a": - textElement.setAttribute("data-href", textOption.color); - textElement.removeAttribute("data-subtype"); - textElement.removeAttribute("data-id"); + setLink(textOption.color); break; case "inline-memo": textElement.removeAttribute("contenteditable"); diff --git a/app/src/protyle/toolbar/Link.ts b/app/src/protyle/toolbar/Link.ts index 2bea6ef49..bce6ed2a3 100644 --- a/app/src/protyle/toolbar/Link.ts +++ b/app/src/protyle/toolbar/Link.ts @@ -3,6 +3,7 @@ import {linkMenu} from "../../menus/protyle"; import {hasClosestBlock, hasClosestByAttribute} from "../util/hasClosest"; import {focusByRange, focusByWbr} from "../util/selection"; import {readText} from "../util/compatibility"; +import {Constants} from "../../constants"; export class Link extends ToolbarItem { public element: HTMLElement; @@ -27,20 +28,31 @@ export class Link extends ToolbarItem { const rangeString = range.toString().trim(); let dataHref = ""; + let dataText = ""; try { const clipText = await readText(); + // 选中链接时需忽略剪切板内容 https://ld246.com/article/1643035329737 if (protyle.lute.IsValidLinkDest(rangeString)) { dataHref = rangeString; } else if (protyle.lute.IsValidLinkDest(clipText)) { dataHref = clipText; + } else { + // 360 + const lastSpace = clipText.lastIndexOf(' ') + if (lastSpace > -1) { + if (protyle.lute.IsValidLinkDest(clipText.substring(lastSpace))) { + dataHref = clipText.substring(lastSpace); + dataText = clipText.substring(0, lastSpace); + } + } } } catch (e) { console.log(e); } protyle.toolbar.setInlineMark(protyle, "a", "range", { type: "a", - color: dataHref + color: dataHref + (dataText ? Constants.ZWSP + dataText : "") }); }); }