Skip to content

Commit 969b167

Browse files
fix(search): pass current BrowsingState to from_tag_id() (#1038)
* fix(search): pass current BrowsingState to from_tag_id() * chore: fix docstring * fix: use existing query to build tag_id query Co-authored-by: Jann Stute <46534683+Computerdores@users.noreply.github.com> --------- Co-authored-by: Jann Stute <46534683+Computerdores@users.noreply.github.com>
1 parent 00001bb commit 969b167

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

src/tagstudio/core/library/alchemy/enums.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,20 @@ def from_search_query(cls, search_query: str) -> "BrowsingState":
9797
return cls(query=search_query)
9898

9999
@classmethod
100-
def from_tag_id(cls, tag_id: int | str) -> "BrowsingState":
100+
def from_tag_id(
101+
cls, tag_id: int | str, state: "BrowsingState | None" = None
102+
) -> "BrowsingState":
103+
"""Create and return a BrowsingState object given a tag ID.
104+
105+
Args:
106+
tag_id(int): The tag ID to search for.
107+
state(BrowsingState|None): An optional BrowsingState object to use
108+
existing options from, such as sorting options.
109+
110+
"""
111+
logger.warning(state)
112+
if state:
113+
return state.with_search_query(f"tag_id:{str(tag_id)}")
101114
return cls(query=f"tag_id:{str(tag_id)}")
102115

103116
@classmethod

src/tagstudio/qt/controller/components/tag_box_controller.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,18 @@ def _on_click(self, tag: Tag) -> None: # type: ignore[misc]
3838
case TagClickActionOption.OPEN_EDIT:
3939
self._on_edit(tag)
4040
case TagClickActionOption.SET_SEARCH:
41-
self.__driver.update_browsing_state(BrowsingState.from_tag_id(tag.id))
41+
self.__driver.update_browsing_state(
42+
BrowsingState.from_tag_id(tag.id, self.__driver.browsing_history.current)
43+
)
4244
case TagClickActionOption.ADD_TO_SEARCH:
4345
# NOTE: modifying the ast and then setting that would be nicer
4446
# than this string manipulation, but also much more complex,
4547
# due to needing to implement a visitor that turns an AST to a string
4648
# So if that exists when you read this, change the following accordingly.
4749
current = self.__driver.browsing_history.current
48-
suffix = BrowsingState.from_tag_id(tag.id).query
50+
suffix = BrowsingState.from_tag_id(
51+
tag.id, self.__driver.browsing_history.current
52+
).query
4953
assert suffix is not None
5054
self.__driver.update_browsing_state(
5155
current.with_search_query(
@@ -90,4 +94,6 @@ def _on_edit(self, tag: Tag) -> None: # type: ignore[misc]
9094
@override
9195
def _on_search(self, tag: Tag) -> None: # type: ignore[misc]
9296
self.__driver.main_window.search_field.setText(f"tag_id:{tag.id}")
93-
self.__driver.update_browsing_state(BrowsingState.from_tag_id(tag.id))
97+
self.__driver.update_browsing_state(
98+
BrowsingState.from_tag_id(tag.id, self.__driver.browsing_history.current)
99+
)

src/tagstudio/qt/modals/tag_search.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,9 @@ def set_tag_widget(self, tag: Tag | None, index: int):
316316
tag_widget.search_for_tag_action.triggered.connect(
317317
lambda checked=False, tag_id=tag.id, driver=self.driver: (
318318
driver.main_window.search_field.setText(f"tag_id:{tag_id}"),
319-
driver.update_browsing_state(BrowsingState.from_tag_id(tag_id)),
319+
driver.update_browsing_state(
320+
BrowsingState.from_tag_id(tag_id, driver.browsing_history.current)
321+
),
320322
)
321323
)
322324
tag_widget.search_for_tag_action.setEnabled(True)

0 commit comments

Comments
 (0)