Skip to content

Commit

Permalink
Change search/filter type based on search text length
Browse files Browse the repository at this point in the history
  • Loading branch information
goanpeca committed Jun 4, 2024
1 parent e0679c6 commit ddff56d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions napari_plugin_manager/qt_plugin_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,15 +686,17 @@ def tag_unavailable(self, metadata: npe2.PackageMetadata):
widget.action_button.setEnabled(False)
widget.warning_tooltip.setVisible(True)

def filter(self, text: str):
def filter(self, text: str, starts_with_chars: int = 1):
"""Filter items to those containing `text`."""
if text:
# PySide has some issues, so we compare using id
# See: https://bugreports.qt.io/browse/PYSIDE-74
shown = [
id(it)
for it in self.findItems(text, Qt.MatchFlag.MatchContains)
]
flag = (
Qt.MatchFlag.MatchStartsWith
if len(text) <= starts_with_chars
else Qt.MatchFlag.MatchContains
)
shown = [id(it) for it in self.findItems(text, flag)]
for i in range(self.count()):
item = self.item(i)
item.setHidden(id(item) not in shown)
Expand Down

0 comments on commit ddff56d

Please sign in to comment.