mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 15:32:23 -04:00
Enable Enter/Return search in all modes ...
... but don't trigger search if the key closes the editor. Also get rid of the on_click of the saved searches root which has already been removed on main.
This commit is contained in:
parent
4ab9e6caef
commit
1f500c1fb8
1 changed files with 7 additions and 15 deletions
|
@ -91,7 +91,6 @@ class SidebarItem:
|
||||||
self,
|
self,
|
||||||
name: str,
|
name: str,
|
||||||
icon: Union[str, ColoredIcon],
|
icon: Union[str, ColoredIcon],
|
||||||
on_click: Callable[[], None] = None,
|
|
||||||
search_node: Optional[SearchNode] = None,
|
search_node: Optional[SearchNode] = None,
|
||||||
on_expanded: Callable[[bool], None] = None,
|
on_expanded: Callable[[bool], None] = None,
|
||||||
expanded: bool = False,
|
expanded: bool = False,
|
||||||
|
@ -106,7 +105,6 @@ class SidebarItem:
|
||||||
self.icon = icon
|
self.icon = icon
|
||||||
self.item_type = item_type
|
self.item_type = item_type
|
||||||
self.id = id
|
self.id = id
|
||||||
self.on_click = on_click
|
|
||||||
self.search_node = search_node
|
self.search_node = search_node
|
||||||
self.on_expanded = on_expanded
|
self.on_expanded = on_expanded
|
||||||
self.children: List["SidebarItem"] = []
|
self.children: List["SidebarItem"] = []
|
||||||
|
@ -561,12 +559,13 @@ class SidebarTreeView(QTreeView):
|
||||||
super().mouseReleaseEvent(event)
|
super().mouseReleaseEvent(event)
|
||||||
if self.tool == SidebarTool.SEARCH and event.button() == Qt.LeftButton:
|
if self.tool == SidebarTool.SEARCH and event.button() == Qt.LeftButton:
|
||||||
idx = self.indexAt(event.pos())
|
idx = self.indexAt(event.pos())
|
||||||
self._on_click_index(idx)
|
self._search_for_indicated(idx)
|
||||||
|
|
||||||
def keyPressEvent(self, event: QKeyEvent) -> None:
|
def keyPressEvent(self, event: QKeyEvent) -> None:
|
||||||
if event.key() in (Qt.Key_Return, Qt.Key_Enter):
|
if event.key() in (Qt.Key_Return, Qt.Key_Enter):
|
||||||
idx = self.currentIndex()
|
idx = self.currentIndex()
|
||||||
self._on_click_index(idx)
|
if not self.isPersistentEditorOpen(idx):
|
||||||
|
self._search_for_indicated(idx)
|
||||||
else:
|
else:
|
||||||
super().keyPressEvent(event)
|
super().keyPressEvent(event)
|
||||||
|
|
||||||
|
@ -636,12 +635,10 @@ class SidebarTreeView(QTreeView):
|
||||||
self.browser.editor.saveNow(on_save)
|
self.browser.editor.saveNow(on_save)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _on_click_index(self, idx: QModelIndex) -> None:
|
def _search_for_indicated(self, index: QModelIndex) -> None:
|
||||||
if item := self.model().item_for_index(idx):
|
if item := self.model().item_for_index(index):
|
||||||
if item.on_click:
|
if search_node := item.search_node:
|
||||||
item.on_click()
|
self.update_search(search_node)
|
||||||
elif self.tool == SidebarTool.SEARCH and (search := item.search_node):
|
|
||||||
self.update_search(search)
|
|
||||||
|
|
||||||
def _on_expansion(self, idx: QModelIndex) -> None:
|
def _on_expansion(self, idx: QModelIndex) -> None:
|
||||||
if self.current_search:
|
if self.current_search:
|
||||||
|
@ -728,11 +725,6 @@ class SidebarTreeView(QTreeView):
|
||||||
type=SidebarItemType.SAVED_SEARCH_ROOT,
|
type=SidebarItemType.SAVED_SEARCH_ROOT,
|
||||||
)
|
)
|
||||||
|
|
||||||
def on_click() -> None:
|
|
||||||
self.show_context_menu(root, None)
|
|
||||||
|
|
||||||
root.on_click = on_click
|
|
||||||
|
|
||||||
for name, filt in sorted(saved.items()):
|
for name, filt in sorted(saved.items()):
|
||||||
item = SidebarItem(
|
item = SidebarItem(
|
||||||
name,
|
name,
|
||||||
|
|
Loading…
Reference in a new issue