fix(mobile): display of context menu on iOS

This commit is contained in:
Elian Doran 2024-12-28 10:57:03 +02:00
parent 12eff0fef5
commit bd10babd1b
No known key found for this signature in database
2 changed files with 76 additions and 50 deletions

View File

@ -53,6 +53,7 @@ class ContextMenu {
}
async show<T extends CommandNames>(options: ContextMenuOptions<T>) {
console.warn(new Error().stack);
this.options = options;
if (this.$widget.hasClass("show")) {

View File

@ -601,7 +601,32 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
}
});
if (!utils.isMobile()) {
const isMobile = utils.isMobile();
if (isMobile) {
let showTimeout;
this.$tree.on("touchstart", ".fancytree-node", (e) => {
touchStart = new Date().getTime();
showTimeout = setTimeout(() => {
this.showContextMenu(e);
}, 300)
});
this.$tree.on("touchmove", ".fancytree-node", (e) => {
clearTimeout(showTimeout);
});
this.$tree.on("touchend", ".fancytree-node", (e) => {
clearTimeout(showTimeout);
e.preventDefault();
});
} else {
this.$tree.on('contextmenu', '.fancytree-node', e => {
this.showContextMenu(e);
return false; // blocks default browser right click menu
});
this.getHotKeys().then(hotKeys => {
for (const key in hotKeys) {
const handler = hotKeys[key];
@ -615,28 +640,28 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
});
}
this.$tree.on('contextmenu', '.fancytree-node', e => {
const node = $.ui.fancytree.getNode(e);
const note = froca.getNoteFromCache(node.data.noteId);
if (note.isLaunchBarConfig()) {
import("../menus/launcher_context_menu.js").then(({default: LauncherContextMenu}) => {
const launcherContextMenu = new LauncherContextMenu(this, node);
launcherContextMenu.show(e);
});
} else {
import("../menus/tree_context_menu.js").then(({default: TreeContextMenu}) => {
const treeContextMenu = new TreeContextMenu(this, node);
treeContextMenu.show(e);
});
}
return false; // blocks default browser right click menu
});
let touchStart;
this.tree = $.ui.fancytree.getTree(this.$tree);
}
showContextMenu(e) {
const node = $.ui.fancytree.getNode(e);
const note = froca.getNoteFromCache(node.data.noteId);
if (note.isLaunchBarConfig()) {
import("../menus/launcher_context_menu.js").then(({default: LauncherContextMenu}) => {
const launcherContextMenu = new LauncherContextMenu(this, node);
launcherContextMenu.show(e);
});
} else {
import("../menus/tree_context_menu.js").then(({default: TreeContextMenu}) => {
const treeContextMenu = new TreeContextMenu(this, node);
treeContextMenu.show(e);
});
}
}
prepareRootNode() {
return this.prepareNode(froca.getBranch('none_root'));
}