mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-03-13 16:06:13 +01:00
This commit is contained in:
parent
701d4e8924
commit
a1f8339d4b
3 changed files with 31 additions and 20 deletions
|
|
@ -58,12 +58,14 @@ export class Link extends ToolbarItem {
|
|||
}
|
||||
}
|
||||
|
||||
export const removeLink = (linkElement: HTMLElement, range: Range) => {
|
||||
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>";
|
||||
focusByWbr(linkParentElement, range);
|
||||
if (range) {
|
||||
focusByWbr(linkParentElement, range);
|
||||
}
|
||||
} else {
|
||||
types.find((itemType, index) => {
|
||||
if ("a" === itemType) {
|
||||
|
|
@ -73,8 +75,10 @@ export const removeLink = (linkElement: HTMLElement, range: Range) => {
|
|||
});
|
||||
linkElement.setAttribute("data-type", types.join(" "));
|
||||
linkElement.removeAttribute("data-href");
|
||||
range.selectNodeContents(linkElement);
|
||||
range.collapse(false);
|
||||
focusByRange(range);
|
||||
if (range) {
|
||||
range.selectNodeContents(linkElement);
|
||||
range.collapse(false);
|
||||
focusByRange(range);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -807,9 +807,13 @@ export class Toolbar {
|
|||
refElement.innerHTML = "*";
|
||||
}
|
||||
this.range.setStartAfter(refElement);
|
||||
focusByRange(this.range);
|
||||
if (getSelection().rangeCount === 0) {
|
||||
focusByRange(this.range);
|
||||
}
|
||||
} else {
|
||||
focusByWbr(nodeElement, this.range);
|
||||
if (getSelection().rangeCount === 0) {
|
||||
focusByWbr(nodeElement, this.range);
|
||||
}
|
||||
}
|
||||
nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
|
||||
updateTransaction(protyle, id, nodeElement.outerHTML, html);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue