This commit is contained in:
parent
701d4e8924
commit
a1f8339d4b
3 changed files with 31 additions and 20 deletions
|
@ -59,17 +59,6 @@ export const refMenu = (app: App, protyle: IProtyle, element: HTMLElement) => {
|
|||
bind(menuItemElement) {
|
||||
const inputElement = menuItemElement.querySelector("input");
|
||||
inputElement.value = element.getAttribute("data-subtype") === "d" ? "" : element.textContent;
|
||||
inputElement.addEventListener("blur", (event) => {
|
||||
if (nodeElement.outerHTML !== oldHTML) {
|
||||
nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
|
||||
updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);
|
||||
oldHTML = nodeElement.outerHTML;
|
||||
}
|
||||
protyle.toolbar.range.selectNodeContents(element);
|
||||
protyle.toolbar.range.collapse(false);
|
||||
focusByRange(protyle.toolbar.range);
|
||||
event.stopPropagation();
|
||||
});
|
||||
inputElement.addEventListener("input", () => {
|
||||
if (inputElement.value) {
|
||||
// 不能使用 textContent,否则 < 会变为 <
|
||||
|
@ -290,6 +279,19 @@ export const refMenu = (app: App, protyle: IProtyle, element: HTMLElement) => {
|
|||
h: 26
|
||||
});
|
||||
window.siyuan.menus.menu.element.querySelector("input").select();
|
||||
window.siyuan.menus.menu.removeCB = () => {
|
||||
if (nodeElement.outerHTML !== oldHTML) {
|
||||
nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
|
||||
updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML);
|
||||
oldHTML = nodeElement.outerHTML;
|
||||
}
|
||||
const currentRange = getSelection().rangeCount === 0 ? undefined : getSelection().getRangeAt(0);
|
||||
if (currentRange && !protyle.element.contains(currentRange.startContainer)) {
|
||||
protyle.toolbar.range.selectNodeContents(element);
|
||||
protyle.toolbar.range.collapse(false);
|
||||
focusByRange(protyle.toolbar.range);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const contentMenu = (protyle: IProtyle, nodeElement: Element) => {
|
||||
|
@ -890,9 +892,10 @@ export const linkMenu = (app: App, protyle: IProtyle, linkElement: HTMLElement,
|
|||
linkElement.removeAttribute("data-title");
|
||||
}
|
||||
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, protyle.toolbar.range);
|
||||
} else {
|
||||
removeLink(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);
|
||||
focusByRange(protyle.toolbar.range);
|
||||
|
|
|
@ -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
Reference in a new issue