Skip to content

Commit 38263d8

Browse files
committed
Highlight queries and scroll to them
1 parent 51655db commit 38263d8

File tree

5 files changed

+19
-16
lines changed

5 files changed

+19
-16
lines changed

rednotebook/data.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,7 @@ def search(self, queries, tags):
207207
# We don't want to show search results from the text matching
208208
# this date.
209209
queries.remove(word)
210-
results.append(
211-
get_text_with_dots(self.text, 0, TEXT_RESULT_LENGTH)
212-
)
210+
results.append(get_text_with_dots(self.text, 0, TEXT_RESULT_LENGTH))
213211
text_result = self.search_in_text(queries)
214212
if text_result:
215213
results.append(text_result)

rednotebook/gui/browser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def load_html(self, html):
5252
class HtmlView(Browser):
5353
def __init__(self):
5454
Browser.__init__(self)
55-
self.search_text = ""
55+
self.search_queries = []
5656
self.connect("load-changed", self.on_load_changed)
5757
self.show_all()
5858

rednotebook/gui/editor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(self, day_text_view):
4444

4545
self._connect_undo_signals()
4646

47-
self.search_text = ""
47+
self.search_queries = []
4848

4949
# spell checker
5050
self._spell_checker = None

rednotebook/gui/main_window.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -814,17 +814,29 @@ def _get_buffer(self, key, text):
814814
def _get_buffer_for_day(self, day):
815815
return self._get_buffer(day.date, day.text)
816816

817+
def scroll_to_text(self, queries):
818+
"""
819+
Finds the first non-date word in queries, and passes it on to
820+
`Editor.scroll_to_text`.
821+
"""
822+
for word in queries:
823+
# If word matches date, it probably is not present in the text.
824+
if word in str(self.day):
825+
pass
826+
else:
827+
super().scroll_to_text(word)
828+
817829
def show_day(self, new_day):
818830
# Show new day
819831
self.day = new_day
820832
buf = self._get_buffer_for_day(new_day)
821833
self.replace_buffer(buf)
822834
self.day_text_view.grab_focus()
823835

824-
if self.search_text:
836+
if self.search_queries:
825837
# If a search is currently made, scroll to the text and return.
826-
GObject.idle_add(self.scroll_to_text, self.search_text)
827-
GObject.idle_add(self.highlight, self.search_text)
838+
GObject.idle_add(self.scroll_to_text, self.search_queries)
839+
GObject.idle_add(self.highlight, self.search_queries)
828840
return
829841

830842
def show_template(self, title, text):

rednotebook/gui/search.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,7 @@ def search(self, search_text):
6565

6666
# Scroll to query.
6767
if queries:
68-
# TODO: Decide where to scroll to?
69-
# To scroll to the first match, we'd need to search for the first
70-
# occurrence of each query, and scroll to the first one. But I am
71-
# not sure if that is ideal performance-wise.
72-
# Would it make sense to inspect the data returned by
73-
# `self.journal.search` -- which will have information on what
74-
# query matched fist, and it's index?
75-
pass
68+
self.main_window.day_text_field.scroll_to_text(tags + queries)
7669

7770
self.main_window.search_tree_view.update_data(queries, tags)
7871

0 commit comments

Comments
 (0)