diff --git a/TODO b/TODO index 4cc09b3..4a532db 100644 --- a/TODO +++ b/TODO @@ -93,9 +93,7 @@ TODO Deselecting all directories in the settings dialog also filters out manually added books Clean up 'switch' page layout Colors aren't loaded properly for annotation previews - Cover page shouldn't be scolled midway Last line in QTextBrowser should never be cut off - Cursor position is a little finicky when toggling fullscreen Hide mousepointer more aggressively Secondary: diff --git a/lector/contentwidgets.py b/lector/contentwidgets.py index f6bcb34..047a7c7 100644 --- a/lector/contentwidgets.py +++ b/lector/contentwidgets.py @@ -276,7 +276,7 @@ class PliantQGraphicsView(QtWidgets.QGraphicsView): self.viewport().setCursor(QtCore.Qt.OpenHandCursor) else: self.viewport().setCursor(QtCore.Qt.ClosedHandCursor) - self.parent.mouse_hide_timer.start(3000) + self.parent.mouse_hide_timer.start(2000) QtWidgets.QGraphicsView.mouseMoveEvent(self, event) def generate_graphicsview_context_menu(self, position): @@ -669,7 +669,7 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser): self.viewport().setCursor(QtCore.Qt.IBeamCursor) else: self.viewport().setCursor(QtCore.Qt.ArrowCursor) - self.parent.mouse_hide_timer.start(3000) + self.parent.mouse_hide_timer.start(2000) QtWidgets.QTextBrowser.mouseMoveEvent(self, event) diff --git a/lector/threaded.py b/lector/threaded.py index 79669ac..0b26e4b 100644 --- a/lector/threaded.py +++ b/lector/threaded.py @@ -195,6 +195,18 @@ class BackGroundTextSearch(QtCore.QThread): if not self.search_text or len(self.search_text) < 3: return + def get_surrounding_text(textCursor, words_before): + textCursor.movePosition( + QtGui.QTextCursor.WordLeft, + QtGui.QTextCursor.MoveAnchor, + words_before) + textCursor.movePosition( + QtGui.QTextCursor.NextWord, + QtGui.QTextCursor.KeepAnchor, + words_before * 2) + cursor_selection = textCursor.selection().toPlainText() + return cursor_selection.replace('\n', '') + self.search_results = {} # Create a new QTextDocument of each chapter and iterate @@ -215,16 +227,16 @@ class BackGroundTextSearch(QtCore.QThread): while not findResultCursor.isNull(): result_position = findResultCursor.position() - surroundingTextCursor = QtGui.QTextCursor(chapterDocument) - surroundingTextCursor.setPosition( - result_position, QtGui.QTextCursor.MoveAnchor) - # Get words before and after - surroundingTextCursor.movePosition( - QtGui.QTextCursor.WordLeft, QtGui.QTextCursor.MoveAnchor, 3) - surroundingTextCursor.movePosition( - QtGui.QTextCursor.NextWord, QtGui.QTextCursor.KeepAnchor, 6) - surrounding_text = surroundingTextCursor.selection().toPlainText() - surrounding_text = surrounding_text.replace('\n', ' ') + words_before = 3 + while True: + surroundingTextCursor = QtGui.QTextCursor(chapterDocument) + surroundingTextCursor.setPosition( + result_position, QtGui.QTextCursor.MoveAnchor) + surrounding_text = get_surrounding_text( + surroundingTextCursor, words_before) + words_before += 1 + if surrounding_text[:2] not in ('. ', ', '): + break # Case insensitive replace for find results replace_pattern = re.compile(re.escape(self.search_text), re.IGNORECASE) diff --git a/lector/widgets.py b/lector/widgets.py index c3e0e0c..5dc0924 100644 --- a/lector/widgets.py +++ b/lector/widgets.py @@ -426,6 +426,7 @@ class Tab(QtWidgets.QWidget): if not self.are_we_doing_images_only: self.hiddenButton.animateClick(100) + self.mouse_hide_timer.start(2000) self.is_fullscreen = True def exit_fullscreen(self): @@ -458,6 +459,7 @@ class Tab(QtWidgets.QWidget): if not self.main_window.settings['show_bars']: self.main_window.toggle_distraction_free() + self.mouse_hide_timer.start(2000) self.contentView.setFocus() def change_chapter_tocBox(self):