An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: fix https://github.com/siyuan-note/siyuan/issues/9443
Vanessa9a814f58f00f
diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.tsindex 556943f7f5..9bf332a5c7 100644--- a/app/src/menus/protyle.ts+++ b/app/src/menus/protyle.ts@@ -38,7 +38,7 @@ import {renameAsset} from "../editor/rename";import {electronUndo} from "../protyle/undo";import {pushBack} from "../mobile/util/MobileBackFoward";import {copyPNG, exportAsset} from "./util";-import {removeLink} from "../protyle/toolbar/Link";+import {removeInlineType} from "../protyle/toolbar/util";import {alignImgCenter, alignImgLeft} from "../protyle/wysiwyg/commonHotkey";import {renameTag} from "../util/noRelyPCFunction";import {hideElements} from "../protyle/ui/hideElements";@@ -58,9 +58,11 @@ export const fileAnnotationRefMenu = (protyle: IProtyle, refElement: HTMLElementwindow.siyuan.menus.menu.remove();let anchorElement: HTMLInputElement;window.siyuan.menus.menu.append(new MenuItem({+ iconHTML: "",label: `<input style="margin: 4px 0" class="b3-text-field fn__block" value="${refElement.getAttribute("data-id") || ""}" readonly placeholder="ID">`,}).element);window.siyuan.menus.menu.append(new MenuItem({+ iconHTML: "",label: `<input style="margin: 4px 0" class="b3-text-field fn__block" data-type="anchor" placeholder="${window.siyuan.languages.anchor}">`,bind(menuItemElement) {anchorElement = menuItemElement.querySelector("input");@@ -105,6 +107,15 @@ export const fileAnnotationRefMenu = (protyle: IProtyle, refElement: HTMLElementrefElement.outerHTML = refElement.textContent + "<wbr>";}}).element);+ window.siyuan.menus.menu.append(new MenuItem({+ label: `${window.siyuan.languages.turnInto} <b>${window.siyuan.languages.text}</b>`,+ icon: "iconRefresh",+ click() {+ const html = nodeElement.outerHTML;+ removeInlineType(refElement, protyle.toolbar.range);+ updateTransaction(protyle, id, nodeElement.outerHTML, html);+ }+ }).element);if (protyle?.app?.plugins) {emitOpenMenu({@@ -950,12 +961,12 @@ export const linkMenu = (protyle: IProtyle, linkElement: HTMLElement, focusText}inputElement.value = anchor;inputElement.addEventListener("compositionend", () => {- linkElement.innerHTML = Lute.EscapeHTMLStr(inputElement.value.replace(/\n|\r\n|\r|\u2028|\u2029/g, "") || "");+ linkElement.innerHTML = Lute.EscapeHTMLStr(inputElement.value.replace(/\n|\r\n|\r|\u2028|\u2029/g, "") || "*");});inputElement.addEventListener("input", (event: KeyboardEvent) => {if (!event.isComposing) {// https://github.com/siyuan-note/siyuan/issues/4511- linkElement.innerHTML = Lute.EscapeHTMLStr(inputElement.value.replace(/\n|\r\n|\r|\u2028|\u2029/g, "")) || "";+ linkElement.innerHTML = Lute.EscapeHTMLStr(inputElement.value.replace(/\n|\r\n|\r|\u2028|\u2029/g, "")) || "*";}});inputElement.addEventListener("keydown", (event) => {@@ -1014,7 +1025,7 @@ export const linkMenu = (protyle: IProtyle, linkElement: HTMLElement, focusTextlabel: `${window.siyuan.languages.turnInto} <b>${window.siyuan.languages.text}</b>`,icon: "iconRefresh",click() {- removeLink(linkElement, protyle.toolbar.range);+ removeInlineType(linkElement, protyle.toolbar.range);updateTransaction(protyle, id, nodeElement.outerHTML, html);}}).element);@@ -1088,7 +1099,7 @@ export const linkMenu = (protyle: IProtyle, linkElement: HTMLElement, focusTextlinkElement.setAttribute("data-href", Lute.EscapeHTMLStr(textElements[0].value.replace(/\n|\r\n|\r|\u2028|\u2029/g, "")));const currentRange = getSelection().rangeCount === 0 ? undefined : getSelection().getRangeAt(0);if (linkElement.textContent === "" || linkElement.textContent === Constants.ZWSP) {- removeLink(linkElement, (currentRange && !protyle.element.contains(currentRange.startContainer)) ? protyle.toolbar.range : undefined);+ removeInlineType(linkElement, (currentRange && !protyle.element.contains(currentRange.startContainer)) ? protyle.toolbar.range : undefined);} else if (currentRange && !protyle.element.contains(currentRange.startContainer)) {protyle.toolbar.range.selectNodeContents(linkElement);protyle.toolbar.range.collapse(false);diff --git a/app/src/protyle/toolbar/Link.ts b/app/src/protyle/toolbar/Link.tsindex 8f13380b73..294cf2daaf 100644--- a/app/src/protyle/toolbar/Link.ts+++ b/app/src/protyle/toolbar/Link.ts@@ -56,28 +56,3 @@ export class Link extends ToolbarItem {});}}--export const removeLink = (linkElement: HTMLElement, range?: Range) => {- const types = linkElement.getAttribute("data-type").split(" ");- if (types.length === 1) {- const linkParentElement = linkElement.parentElement;- linkElement.outerHTML = linkElement.innerHTML.replace(Constants.ZWSP, "") + "<wbr>";- if (range) {- focusByWbr(linkParentElement, range);- }- } else {- types.find((itemType, index) => {- if ("a" === itemType) {- types.splice(index, 1);- return true;- }- });- linkElement.setAttribute("data-type", types.join(" "));- linkElement.removeAttribute("data-href");- if (range) {- range.selectNodeContents(linkElement);- range.collapse(false);- focusByRange(range);- }- }-};diff --git a/app/src/protyle/toolbar/util.ts b/app/src/protyle/toolbar/util.tsindex e49c8f839c..64ed3607d4 100644--- a/app/src/protyle/toolbar/util.ts+++ b/app/src/protyle/toolbar/util.ts@@ -1,4 +1,6 @@import {fetchPost} from "../../util/fetch";+import {Constants} from "../../constants";+import {focusByRange, focusByWbr} from "../util/selection";export const previewTemplate = (pathString: string, element: Element, parentId: string) => {if (!pathString) {@@ -60,3 +62,28 @@ export const removeSearchMark = (element: HTMLElement) => {element.setAttribute("data-type", element.getAttribute("data-type").replace("search-mark", "").trim());}};++export const removeInlineType = (linkElement: HTMLElement, range?: Range) => {+ const types = linkElement.getAttribute("data-type").split(" ");+ if (types.length === 1) {+ const linkParentElement = linkElement.parentElement;+ linkElement.outerHTML = linkElement.innerHTML.replace(Constants.ZWSP, "") + "<wbr>";+ if (range) {+ focusByWbr(linkParentElement, range);+ }+ } else {+ types.find((itemType, index) => {+ if ("a" === itemType) {+ types.splice(index, 1);+ return true;+ }+ });+ linkElement.setAttribute("data-type", types.join(" "));+ linkElement.removeAttribute("data-href");+ if (range) {+ range.selectNodeContents(linkElement);+ range.collapse(false);+ focusByRange(range);+ }+ }+};