-
Notifications
You must be signed in to change notification settings - Fork 120
New search #558
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
base: master
Are you sure you want to change the base?
New search #558
Changes from all commits
eb39000
24fe9c7
dfe87d9
fc51d80
b8eee88
a4287cd
a7a829f
6229ab1
ff5aeda
42009c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -724,9 +724,20 @@ def set_date(self, new_month, new_date, day): | |
| def get_day_text(self): | ||
| return self.day_text_field.get_text() | ||
|
|
||
| def highlight_text(self, search_text): | ||
| self.html_editor.highlight(search_text) | ||
| self.day_text_field.highlight(search_text) | ||
| def highlight_text(self, search_words): | ||
| self.day_text_field.highlight(search_words) | ||
|
|
||
| # The HTML view can only highlight one match, so we search for a match ourselves | ||
| # and highlight the last match, since it's what the user is currently typing. | ||
| day_text = self.day_text_field.get_text() | ||
|
|
||
| def get_last_match(): | ||
| for word in reversed(search_words): | ||
| if word.lower() in day_text.lower(): | ||
| return word | ||
| return "" | ||
|
|
||
| self.html_editor.highlight(get_last_match()) | ||
|
|
||
| def show_message(self, title, msg, msg_type): | ||
| if msg_type == Gtk.MessageType.ERROR: | ||
|
|
@@ -814,17 +825,29 @@ def _get_buffer(self, key, text): | |
| def _get_buffer_for_day(self, day): | ||
| return self._get_buffer(day.date, day.text) | ||
|
|
||
| def scroll_to_non_date_text(self, words): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the new method name. |
||
| """ | ||
| Find the first non-date word in words, and pass it on to | ||
| `Editor.scroll_to_text`. | ||
RJ722 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """ | ||
| for word in words: | ||
| # If word matches date, it probably is not present in the text. | ||
| if word in str(self.day): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's remove the |
||
| pass | ||
| else: | ||
| super().scroll_to_text(word) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we still need the |
||
|
|
||
| def show_day(self, new_day): | ||
| # Show new day | ||
| self.day = new_day | ||
| buf = self._get_buffer_for_day(new_day) | ||
| self.replace_buffer(buf) | ||
| self.day_text_view.grab_focus() | ||
|
|
||
| if self.search_text: | ||
| if self.search_words: | ||
| # If a search is currently made, scroll to the text and return. | ||
| GObject.idle_add(self.scroll_to_text, self.search_text) | ||
| GObject.idle_add(self.highlight, self.search_text) | ||
| GObject.idle_add(self.scroll_to_non_date_text, self.search_words) | ||
| GObject.idle_add(self.highlight, self.search_words) | ||
| return | ||
|
|
||
| def show_template(self, title, text): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"matched agains" -> "match"