diff --git a/novelwriter/gui/projtree.py b/novelwriter/gui/projtree.py index 20878bc4..b32bae4b 100644 --- a/novelwriter/gui/projtree.py +++ b/novelwriter/gui/projtree.py @@ -953,25 +953,19 @@ class GuiProjectTree(QTreeView): if model := self._getModel(): if point is None: point = self.visualRect(self.currentIndex()).center() - - if ( - point is not None - and (node := self._getNode(self.currentIndex())) - and (indices := self._selectedRows()) - ): - ctxMenu = _TreeContextMenu(self, model, node, indices) - if node is SHARED.project.tree.trash: - ctxMenu.buildTrashMenu() - elif len(indices) > 1: - ctxMenu.buildMultiSelectMenu() - else: - ctxMenu.buildSingleSelectMenu() - - if viewport := self.viewport(): - ctxMenu.exec(viewport.mapToGlobal(point)) - - ctxMenu.setParent(None) - + if point is not None: + index = self.indexAt(point) + if (node := self._getNode(index)) and (indices := self._selectedRows()): + ctxMenu = _TreeContextMenu(self, model, node, indices) + if node is SHARED.project.tree.trash: + ctxMenu.buildTrashMenu() + elif len(indices) > 1: + ctxMenu.buildMultiSelectMenu() + else: + ctxMenu.buildSingleSelectMenu() + if viewport := self.viewport(): + ctxMenu.exec(viewport.mapToGlobal(point)) + ctxMenu.setParent(None) return ##