|
@@ -6,7 +6,7 @@ import {initDockMenu} from "./dock";
|
|
import {initFileMenu, initNavigationMenu} from "./navigation";
|
|
import {initFileMenu, initNavigationMenu} from "./navigation";
|
|
import {initTabMenu} from "./tab";
|
|
import {initTabMenu} from "./tab";
|
|
/// #endif
|
|
/// #endif
|
|
-import {Menu} from "./Menu";
|
|
|
|
|
|
+import {Menu, MenuItem} from "./Menu";
|
|
import {hasClosestByClassName, hasTopClosestByTag} from "../protyle/util/hasClosest";
|
|
import {hasClosestByClassName, hasTopClosestByTag} from "../protyle/util/hasClosest";
|
|
import {App} from "../index";
|
|
import {App} from "../index";
|
|
|
|
|
|
@@ -22,6 +22,11 @@ export class Menus {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
let target = event.target as HTMLElement;
|
|
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 // ⌃⇥ 后点击会为空
|
|
while (target && target.parentElement // ⌃⇥ 后点击会为空
|
|
&& !target.parentElement.isEqualNode(document.querySelector("body"))) {
|
|
&& !target.parentElement.isEqualNode(document.querySelector("body"))) {
|
|
event.preventDefault();
|
|
event.preventDefault();
|
|
@@ -34,9 +39,7 @@ export class Menus {
|
|
});
|
|
});
|
|
event.stopPropagation();
|
|
event.stopPropagation();
|
|
break;
|
|
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")) {
|
|
if (target.querySelector(".b3-list-item__text").classList.contains("ft__on-surface")) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -45,9 +48,7 @@ export class Menus {
|
|
initNavigationMenu(app, target).popup({x: event.clientX, y: event.clientY});
|
|
initNavigationMenu(app, target).popup({x: event.clientX, y: event.clientY});
|
|
event.stopPropagation();
|
|
event.stopPropagation();
|
|
break;
|
|
break;
|
|
- }
|
|
|
|
-
|
|
|
|
- if (dataType === "navigation-file") {
|
|
|
|
|
|
+ } else if (dataType === "navigation-file") {
|
|
this.unselect();
|
|
this.unselect();
|
|
// navigation 文件上:删除/重命名/打开文件位置/导出
|
|
// navigation 文件上:删除/重命名/打开文件位置/导出
|
|
initFileMenu(app, this.getDir(target), target.getAttribute("data-path"), target).popup({
|
|
initFileMenu(app, this.getDir(target), target.getAttribute("data-path"), target).popup({
|
|
@@ -56,29 +57,64 @@ export class Menus {
|
|
});
|
|
});
|
|
event.stopPropagation();
|
|
event.stopPropagation();
|
|
break;
|
|
break;
|
|
- }
|
|
|
|
-
|
|
|
|
- if (dataType === "search-item") {
|
|
|
|
|
|
+ } else if (dataType === "search-item") {
|
|
const nodeId = target.getAttribute("data-node-id");
|
|
const nodeId = target.getAttribute("data-node-id");
|
|
if (nodeId) {
|
|
if (nodeId) {
|
|
initSearchMenu(nodeId).popup({x: event.clientX, y: event.clientY});
|
|
initSearchMenu(nodeId).popup({x: event.clientX, y: event.clientY});
|
|
}
|
|
}
|
|
event.stopPropagation();
|
|
event.stopPropagation();
|
|
break;
|
|
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});
|
|
initDockMenu(target).popup({x: event.clientX, y: event.clientY});
|
|
event.stopPropagation();
|
|
event.stopPropagation();
|
|
break;
|
|
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;
|
|
target = target.parentElement;
|
|
}
|
|
}
|
|
}, false);
|
|
}, false);
|