diff --git a/src/public/javascripts/context_menu.js b/src/public/javascripts/context_menu.js index fc5cc7f0f..09242180f 100644 --- a/src/public/javascripts/context_menu.js +++ b/src/public/javascripts/context_menu.js @@ -95,9 +95,17 @@ const contextMenu = (function() { ], beforeOpen: (event, ui) => { const node = $.ui.fancytree.getNode(ui.target); + const nt = noteTree.getNoteTree(node.data.noteTreeId); + const note = noteTree.getNote(node.data.noteId); + const parentNote = noteTree.getNote(nt.parentNoteId); + // Modify menu entries depending on node status - $tree.contextmenu("enableEntry", "pasteAfter", clipboardIds.length > 0); - $tree.contextmenu("enableEntry", "pasteInto", clipboardIds.length > 0); + $tree.contextmenu("enableEntry", "pasteAfter", clipboardIds.length > 0 && (!parentNote || parentNote.type !== 'search')); + $tree.contextmenu("enableEntry", "pasteInto", clipboardIds.length > 0 && note.type !== 'search'); + $tree.contextmenu("enableEntry", "insertNoteHere", !parentNote || parentNote.type !== 'search'); + $tree.contextmenu("enableEntry", "insertChildNote", note.type !== 'search'); + $tree.contextmenu("enableEntry", "importSubTree", note.type !== 'search'); + $tree.contextmenu("enableEntry", "exportSubTree", note.type !== 'search'); // Activate node on right-click node.setActive(); diff --git a/src/public/javascripts/note_tree.js b/src/public/javascripts/note_tree.js index 068121c30..f61b0189b 100644 --- a/src/public/javascripts/note_tree.js +++ b/src/public/javascripts/note_tree.js @@ -204,7 +204,7 @@ const noteTree = (function() { title: escapeHtml(title), extraClasses: getExtraClasses(note), refKey: noteId, - expanded: noteTree.isExpanded + expanded: note.type !== 'search' && noteTree.isExpanded }; const hasChildren = parentToChildren[noteId] && parentToChildren[noteId].length > 0; @@ -212,7 +212,7 @@ const noteTree = (function() { if (hasChildren || note.type === 'search') { node.folder = true; - if (node.expanded) { + if (node.expanded && note.type !== 'search') { node.children = prepareNoteTreeInner(noteId); } else { @@ -889,6 +889,10 @@ const noteTree = (function() { return notesTreeMap[noteTreeId]; } + function getNote(noteId) { + return noteIdToNote[noteId]; + } + $(document).bind('keydown', 'ctrl+o', e => { const node = getCurrentNode(); const parentNoteId = node.data.parentNoteId; @@ -965,6 +969,7 @@ const noteTree = (function() { sortAlphabetically, noteExists, getInstanceName, - getNoteTree + getNoteTree, + getNote }; })(); \ No newline at end of file