Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disable left click when context menu opening #3805

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/public/app/menus/context_menu.js
Expand Up @@ -5,6 +5,8 @@ class ContextMenu {
this.$widget = $("#context-menu-container");
this.dateContextMenuOpenedMs = 0;

this.hideHandlers = [];

$(document).on('click', () => this.hide());
}

Expand All @@ -20,6 +22,8 @@ class ContextMenu {
this.positionMenu();

this.dateContextMenuOpenedMs = Date.now();

return this;
}

positionMenu() {
Expand Down Expand Up @@ -148,8 +152,22 @@ class ContextMenu {
// we might filter out right clicks, but then it's better if even right clicks close the context menu
if (Date.now() - this.dateContextMenuOpenedMs > 300) {
this.$widget.hide();

setTimeout(() => {
this.hideHandlers.forEach(fn => {
fn(this);
});
}, 0);

}
}
onHide(fn) {
this.hideHandlers.push(fn);
return () => {
const fnIndex = this.hideHandlers.findIndex(v => v === fn);
this.hideHandlers.splice(fnIndex, 1);
};
}
}

const contextMenu = new ContextMenu();
Expand Down
8 changes: 4 additions & 4 deletions src/public/app/menus/link_context_menu.js
Expand Up @@ -2,21 +2,21 @@ import contextMenu from "./context_menu.js";
import appContext from "../components/app_context.js";

function openContextMenu(notePath, hoistedNoteId, e) {
contextMenu.show({
return contextMenu.show({
x: e.pageX,
y: e.pageY,
items: [
{title: "Open note in a new tab", command: "openNoteInNewTab", uiIcon: "bx bx-empty"},
{title: "Open note in a new split", command: "openNoteInNewSplit", uiIcon: "bx bx-dock-right"},
{title: "Open note in a new window", command: "openNoteInNewWindow", uiIcon: "bx bx-window-open"}
],
selectMenuItemHandler: ({command}) => {
selectMenuItemHandler: async ({command}) => {
if (!hoistedNoteId) {
hoistedNoteId = appContext.tabManager.getActiveContext().hoistedNoteId;
}

if (command === 'openNoteInNewTab') {
appContext.tabManager.openContextWithNote(notePath, { hoistedNoteId });
appContext.tabManager.openContextWithNote(notePath, {hoistedNoteId});
}
else if (command === 'openNoteInNewSplit') {
const subContexts = appContext.tabManager.getActiveContext().getSubContexts();
Expand All @@ -28,7 +28,7 @@ function openContextMenu(notePath, hoistedNoteId, e) {
appContext.triggerCommand('openInWindow', {notePath, hoistedNoteId});
}
}
});
})
}

export default {
Expand Down
17 changes: 14 additions & 3 deletions src/public/app/widgets/note_map.js
Expand Up @@ -57,7 +57,7 @@ export default class NoteMapWidget extends NoteContextAwareWidget {

window.addEventListener('resize', () => this.setDimensions(), false);

this.$widget.find(".map-type-switcher button").on("click", async e => {
this.$widget.find(".map-type-switcher button").on("click", async e => {
const type = $(e.target).closest("button").attr("data-type");

await attributeService.setLabel(this.noteId, 'mapType', type);
Expand Down Expand Up @@ -91,6 +91,8 @@ export default class NoteMapWidget extends NoteContextAwareWidget {

await libraryLoader.requireLibrary(libraryLoader.FORCE_GRAPH);

let isContextMenuOpening = false

this.graph = ForceGraph()(this.$container[0])
.width(this.$container.width())
.height(this.$container.height())
Expand All @@ -112,8 +114,17 @@ export default class NoteMapWidget extends NoteContextAwareWidget {
.linkDirectionalArrowRelPos(1)
.linkWidth(1)
.linkColor(() => this.css.mutedTextColor)
.onNodeClick(node => appContext.tabManager.getActiveContext().setNote(node.id))
.onNodeRightClick((node, e) => linkContextMenuService.openContextMenu(node.id, null, e));
.onNodeClick(node => {
if (!isContextMenuOpening) {
appContext.tabManager.getActiveContext().setNote(node.id)
}
})
.onNodeRightClick(async (node, e) => {
isContextMenuOpening = true;

const contextMenu = await linkContextMenuService.openContextMenu(node.id, null, e);
const removeHideHandler = contextMenu.onHide(() => {isContextMenuOpening = false; removeHideHandler()});
});

if (this.mapType === 'link') {
this.graph
Expand Down