Skip to content

fix: sort tag results #721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tagstudio/src/core/library/alchemy/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ def search_library(

def search_tags(
self,
name: str,
name: str | None,
) -> list[Tag]:
"""Return a list of Tag records matching the query."""
tag_limit = 100
Expand Down
26 changes: 14 additions & 12 deletions tagstudio/src/qt/modals/tag_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,26 +186,28 @@ def on_tag_modal_saved():

def update_tags(self, query: str | None = None):
logger.info("[Tag Search Super Class] Updating Tags")

# TODO: Look at recycling rather than deleting and re-initializing
while self.scroll_layout.count():
self.scroll_layout.takeAt(0).widget().deleteLater()

tag_results = self.lib.search_tags(name=query)
if len(tag_results) > 0:
self.first_tag_id = tag_results[0].id
else:
self.first_tag_id = None

for tag in tag_results:
if tag.id not in self.exclude:
results_1 = []
results_2 = []
for tag in tag_results:
if tag.id in self.exclude:
continue
elif query and tag.name.lower().startswith(query.lower()):
results_1.append(tag)
else:
results_2.append(tag)
results_1.sort(key=lambda tag: len(tag.name))
results_2.sort()
for tag in results_1 + results_2:
self.scroll_layout.addWidget(self.__build_row_item_widget(tag))

# If query doesnt exist add create button
if len(tag_results) == 0:
else:
# If query doesnt exist add create button
c = self.construct_tag_button(query)
self.scroll_layout.addWidget(c)

self.search_field.setFocus()

def on_return(self, text: str):
Expand Down
Loading