diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts
index 556943f7f..9bf332a5c 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: HTMLElement
window.siyuan.menus.menu.remove();
let anchorElement: HTMLInputElement;
window.siyuan.menus.menu.append(new MenuItem({
+ iconHTML: "",
label: ``,
}).element);
window.siyuan.menus.menu.append(new MenuItem({
+ iconHTML: "",
label: ``,
bind(menuItemElement) {
anchorElement = menuItemElement.querySelector("input");
@@ -105,6 +107,15 @@ export const fileAnnotationRefMenu = (protyle: IProtyle, refElement: HTMLElement
refElement.outerHTML = refElement.textContent + "";
}
}).element);
+ window.siyuan.menus.menu.append(new MenuItem({
+ label: `${window.siyuan.languages.turnInto} ${window.siyuan.languages.text}`,
+ 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, focusText
label: `${window.siyuan.languages.turnInto} ${window.siyuan.languages.text}`,
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, focusText
linkElement.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.ts
index 8f13380b7..294cf2daa 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, "") + "";
- 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.ts
index e49c8f839..64ed3607d 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, "") + "";
+ 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);
+ }
+ }
+};