This commit is contained in:
parent
1dc894a66b
commit
9cd7d77275
2 changed files with 57 additions and 20 deletions
|
@ -6,7 +6,7 @@ import {initDockMenu} from "./dock";
|
|||
import {initFileMenu, initNavigationMenu} from "./navigation";
|
||||
import {initTabMenu} from "./tab";
|
||||
/// #endif
|
||||
import {Menu} from "./Menu";
|
||||
import {Menu, MenuItem} from "./Menu";
|
||||
import {hasClosestByClassName, hasTopClosestByTag} from "../protyle/util/hasClosest";
|
||||
import {App} from "../index";
|
||||
|
||||
|
@ -22,6 +22,11 @@ export class Menus {
|
|||
return;
|
||||
}
|
||||
let target = event.target as HTMLElement;
|
||||
if (hasClosestByClassName(target, "av__panel") && !hasClosestByClassName(target, "b3-menu")) {
|
||||
document.querySelector(".av__panel").dispatchEvent(new CustomEvent("click", {detail: "close"}));
|
||||
event.stopPropagation();
|
||||
return;
|
||||
}
|
||||
while (target && target.parentElement // ⌃⇥ 后点击会为空
|
||||
&& !target.parentElement.isEqualNode(document.querySelector("body"))) {
|
||||
event.preventDefault();
|
||||
|
@ -34,9 +39,7 @@ export class Menus {
|
|||
});
|
||||
event.stopPropagation();
|
||||
break;
|
||||
}
|
||||
|
||||
if (dataType === "navigation-root" && !window.siyuan.config.readonly) {
|
||||
} else if (dataType === "navigation-root" && !window.siyuan.config.readonly) {
|
||||
if (target.querySelector(".b3-list-item__text").classList.contains("ft__on-surface")) {
|
||||
return;
|
||||
}
|
||||
|
@ -45,9 +48,7 @@ export class Menus {
|
|||
initNavigationMenu(app, target).popup({x: event.clientX, y: event.clientY});
|
||||
event.stopPropagation();
|
||||
break;
|
||||
}
|
||||
|
||||
if (dataType === "navigation-file") {
|
||||
} else if (dataType === "navigation-file") {
|
||||
this.unselect();
|
||||
// navigation 文件上:删除/重命名/打开文件位置/导出
|
||||
initFileMenu(app, this.getDir(target), target.getAttribute("data-path"), target).popup({
|
||||
|
@ -56,29 +57,64 @@ export class Menus {
|
|||
});
|
||||
event.stopPropagation();
|
||||
break;
|
||||
}
|
||||
|
||||
if (dataType === "search-item") {
|
||||
} else if (dataType === "search-item") {
|
||||
const nodeId = target.getAttribute("data-node-id");
|
||||
if (nodeId) {
|
||||
initSearchMenu(nodeId).popup({x: event.clientX, y: event.clientY});
|
||||
}
|
||||
event.stopPropagation();
|
||||
break;
|
||||
}
|
||||
|
||||
if (target.classList.contains("dock__item") && target.getAttribute("data-type")) {
|
||||
} else if (dataType && target.classList.contains("dock__item")) {
|
||||
initDockMenu(target).popup({x: event.clientX, y: event.clientY});
|
||||
event.stopPropagation();
|
||||
break;
|
||||
} else if (target.classList.contains("b3-text-field")) {
|
||||
window.siyuan.menus.menu.remove();
|
||||
if ((target as HTMLInputElement).selectionStart !== (target as HTMLInputElement).selectionEnd) {
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
icon: "iconCopy",
|
||||
accelerator: "⌘C",
|
||||
label: window.siyuan.languages.copy,
|
||||
click: () => {
|
||||
document.execCommand("copy");
|
||||
}
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
icon: "iconCut",
|
||||
accelerator: "⌘X",
|
||||
label: window.siyuan.languages.cut,
|
||||
click: () => {
|
||||
document.execCommand("cut");
|
||||
}
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
icon: "iconTrashcan",
|
||||
accelerator: "⌫",
|
||||
label: window.siyuan.languages.delete,
|
||||
click: () => {
|
||||
document.execCommand("delete");
|
||||
}
|
||||
}).element);
|
||||
}
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
label: window.siyuan.languages.paste,
|
||||
icon: "iconPaste",
|
||||
accelerator: "⌘V",
|
||||
click: async () => {
|
||||
document.execCommand("paste");
|
||||
}
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
label: window.siyuan.languages.selectAll,
|
||||
icon: "iconSelect",
|
||||
accelerator: "⌘A",
|
||||
click: () => {
|
||||
document.execCommand("selectAll");
|
||||
}
|
||||
}).element);
|
||||
window.siyuan.menus.menu.popup({x: event.clientX, y: event.clientY});
|
||||
target.focus()
|
||||
}
|
||||
|
||||
if (hasClosestByClassName(target, "av__panel") && !hasClosestByClassName(target, "b3-menu")) {
|
||||
document.querySelector(".av__panel").dispatchEvent(new CustomEvent("click", {detail: "close"}));
|
||||
event.stopPropagation();
|
||||
break;
|
||||
}
|
||||
|
||||
target = target.parentElement;
|
||||
}
|
||||
}, false);
|
||||
|
|
|
@ -239,6 +239,7 @@ export class Title {
|
|||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
label: window.siyuan.languages.selectAll,
|
||||
icon: "iconSelect",
|
||||
accelerator: "⌘A",
|
||||
click: () => {
|
||||
range.selectNodeContents(this.editElement);
|
||||
|
|
Loading…
Add table
Reference in a new issue