mirror of
https://github.com/TagStudioDev/TagStudio.git
synced 2026-02-01 07:39:10 +00:00
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>
This commit is contained in:
committed by
GitHub
parent
00001bbf0b
commit
969b1674f0
@@ -97,7 +97,20 @@ class BrowsingState:
|
||||
return cls(query=search_query)
|
||||
|
||||
@classmethod
|
||||
def from_tag_id(cls, tag_id: int | str) -> "BrowsingState":
|
||||
def from_tag_id(
|
||||
cls, tag_id: int | str, state: "BrowsingState | None" = None
|
||||
) -> "BrowsingState":
|
||||
"""Create and return a BrowsingState object given a tag ID.
|
||||
|
||||
Args:
|
||||
tag_id(int): The tag ID to search for.
|
||||
state(BrowsingState|None): An optional BrowsingState object to use
|
||||
existing options from, such as sorting options.
|
||||
|
||||
"""
|
||||
logger.warning(state)
|
||||
if state:
|
||||
return state.with_search_query(f"tag_id:{str(tag_id)}")
|
||||
return cls(query=f"tag_id:{str(tag_id)}")
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -38,14 +38,18 @@ class TagBoxWidget(TagBoxWidgetView):
|
||||
case TagClickActionOption.OPEN_EDIT:
|
||||
self._on_edit(tag)
|
||||
case TagClickActionOption.SET_SEARCH:
|
||||
self.__driver.update_browsing_state(BrowsingState.from_tag_id(tag.id))
|
||||
self.__driver.update_browsing_state(
|
||||
BrowsingState.from_tag_id(tag.id, self.__driver.browsing_history.current)
|
||||
)
|
||||
case TagClickActionOption.ADD_TO_SEARCH:
|
||||
# NOTE: modifying the ast and then setting that would be nicer
|
||||
# than this string manipulation, but also much more complex,
|
||||
# due to needing to implement a visitor that turns an AST to a string
|
||||
# So if that exists when you read this, change the following accordingly.
|
||||
current = self.__driver.browsing_history.current
|
||||
suffix = BrowsingState.from_tag_id(tag.id).query
|
||||
suffix = BrowsingState.from_tag_id(
|
||||
tag.id, self.__driver.browsing_history.current
|
||||
).query
|
||||
assert suffix is not None
|
||||
self.__driver.update_browsing_state(
|
||||
current.with_search_query(
|
||||
@@ -90,4 +94,6 @@ class TagBoxWidget(TagBoxWidgetView):
|
||||
@override
|
||||
def _on_search(self, tag: Tag) -> None: # type: ignore[misc]
|
||||
self.__driver.main_window.search_field.setText(f"tag_id:{tag.id}")
|
||||
self.__driver.update_browsing_state(BrowsingState.from_tag_id(tag.id))
|
||||
self.__driver.update_browsing_state(
|
||||
BrowsingState.from_tag_id(tag.id, self.__driver.browsing_history.current)
|
||||
)
|
||||
|
||||
@@ -316,7 +316,9 @@ class TagSearchPanel(PanelWidget):
|
||||
tag_widget.search_for_tag_action.triggered.connect(
|
||||
lambda checked=False, tag_id=tag.id, driver=self.driver: (
|
||||
driver.main_window.search_field.setText(f"tag_id:{tag_id}"),
|
||||
driver.update_browsing_state(BrowsingState.from_tag_id(tag_id)),
|
||||
driver.update_browsing_state(
|
||||
BrowsingState.from_tag_id(tag_id, driver.browsing_history.current)
|
||||
),
|
||||
)
|
||||
)
|
||||
tag_widget.search_for_tag_action.setEnabled(True)
|
||||
|
||||
Reference in New Issue
Block a user