Skip to content

Commit

Permalink
Change entry search to be fuzzy.
Browse files Browse the repository at this point in the history
It is now only required to enter characters of the entry in the correct
order to find an entry.

Using the entries in the screenshot in the README.
'tr' would suggest the entry 'gtimelog: experimental rewrite (GH #31)'
because the 't' on index 1 is followed by an 'r' later in the entry
text.
  • Loading branch information
Michael Howitz committed Jan 24, 2022
1 parent 50aeccb commit 2fb0ac1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Changelog

- Focus the task entry on Ctrl+L (GH: #213).

- Change entry search to be fuzzy. It is now only required to enter characters
of the entry in the correct order to find an entry.


0.11.3 (2019-04-23)
~~~~~~~~~~~~~~~~~~~
Expand Down
13 changes: 13 additions & 0 deletions src/gtimelog/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1215,9 +1215,22 @@ def set_up_completion(self):
self.completion_choices_as_set = set()
completion.set_model(self.completion_choices)
completion.set_text_column(0)
completion.set_match_func(
self.completion_match_func, self.completion_choices)
if self.gtk_completion_enabled:
self.set_completion(completion)

def completion_match_func(self, completion, search_text, tree_iter, data):
entry = data.get_value(tree_iter, 0).lower()
pos = 0
for char in search_text:
new_pos = entry.find(char, pos)
if new_pos == -1:
return False
else:
pos = new_pos
return True

def gtk_completion_enabled_changed(self, *args):
if self.gtk_completion_enabled:
self.set_completion(self.gtk_completion)
Expand Down

0 comments on commit 2fb0ac1

Please sign in to comment.