fix: add left-click check for tree button handlers (#6903)

This commit is contained in:
Elian Doran 2025-09-07 22:53:42 +03:00 committed by GitHub
commit 22835108be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 17 deletions

View File

@ -62,7 +62,7 @@ class ContextMenu {
if (this.isMobile) {
this.$cover.on("click", () => this.hide());
} else {
$(document).on("click", (e) => this.hide());
$(document).on("mouseup", (e) => this.hide());
}
}
@ -225,9 +225,10 @@ class ContextMenu {
$item.on("mouseup", (e) => {
// Prevent submenu from failing to expand on mobile
if (!this.isMobile || !("items" in item && item.items)) {
e.stopPropagation();
// Hide the content menu on mouse up to prevent the mouse event from propagating to the elements below.
this.hide();
if (("command" in item) || ("handler" in item)) {
this.hide();
}
return false;
}
});

View File

@ -219,21 +219,22 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
this.$tree = this.$widget.find(".tree");
this.$treeActions = this.$widget.find(".tree-actions");
this.$tree.on("mousedown", ".unhoist-button", () => hoistedNoteService.unhoist());
this.$tree.on("mousedown", ".refresh-search-button", (e) => this.refreshSearch(e));
this.$tree.on("mousedown", ".add-note-button", (e) => {
const node = $.ui.fancytree.getNode(e as unknown as Event);
const parentNotePath = treeService.getNotePath(node);
this.$tree.on("mousedown", (e: JQuery.MouseDownEvent) => {
const target = e.target as HTMLElement;
if (e.button !== 0) return;
noteCreateService.createNote(parentNotePath, {
isProtected: node.data.isProtected
});
});
this.$tree.on("mousedown", ".enter-workspace-button", (e) => {
const node = $.ui.fancytree.getNode(e as unknown as Event);
this.triggerCommand("hoistNote", { noteId: node.data.noteId });
if (target.classList.contains("unhoist-button")) {
hoistedNoteService.unhoist();
} else if (target.classList.contains("refresh-search-button")) {
this.refreshSearch(e);
} else if (target.classList.contains("add-note-button")) {
const node = $.ui.fancytree.getNode(e as unknown as Event);
const parentNotePath = treeService.getNotePath(node);
noteCreateService.createNote(parentNotePath, { isProtected: node.data.isProtected });
} else if (target.classList.contains("enter-workspace-button")) {
const node = $.ui.fancytree.getNode(e as unknown as Event);
this.triggerCommand("hoistNote", { noteId: node.data.noteId });
}
});
// fancytree doesn't support middle click, so this is a way to support it