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,7 +640,12 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
});
}
this.$tree.on('contextmenu', '.fancytree-node', e => {
let touchStart;
this.tree = $.ui.fancytree.getTree(this.$tree);
}
showContextMenu(e) {
const node = $.ui.fancytree.getNode(e);
const note = froca.getNoteFromCache(node.data.noteId);
@ -630,11 +660,6 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
treeContextMenu.show(e);
});
}
return false; // blocks default browser right click menu
});
this.tree = $.ui.fancytree.getTree(this.$tree);
}
prepareRootNode() {