This commit is contained in:
Vanessa 2023-10-17 11:37:05 +08:00
parent 505d339f6e
commit 9a814f58f0
3 changed files with 43 additions and 30 deletions

View file

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