diff --git a/src/calibre/gui2/tweak_book/editor/text.py b/src/calibre/gui2/tweak_book/editor/text.py index e69cc26ffb..24bea37bce 100644 --- a/src/calibre/gui2/tweak_book/editor/text.py +++ b/src/calibre/gui2/tweak_book/editor/text.py @@ -14,7 +14,7 @@ import regex from PyQt4.Qt import ( QPlainTextEdit, QFontDatabase, QToolTip, QPalette, QFont, QKeySequence, QTextEdit, QTextFormat, QWidget, QSize, QPainter, Qt, QRect, pyqtSlot, - QApplication, QMimeData, QColor, QColorDialog) + QApplication, QMimeData, QColor, QColorDialog, QTimer) from calibre import prepare_string_for_xml, xml_entity_to_unicode from calibre.gui2.tweak_book import tprefs, TOP @@ -135,6 +135,8 @@ class TextEdit(PlainTextEdit): self.smarts = NullSmarts(self) self.current_cursor_line = None self.current_search_mark = None + self.smarts_highlight_timer = t = QTimer() + t.setInterval(750), t.setSingleShot(True), t.timeout.connect(self.update_extra_selections) self.highlighter = SyntaxHighlighter() self.line_number_area = LineNumbers(self) self.apply_settings() @@ -252,13 +254,16 @@ class TextEdit(PlainTextEdit): self.setTextCursor(c) self.ensureCursorVisible() - def update_extra_selections(self): + def update_extra_selections(self, instant=True): sel = [] if self.current_cursor_line is not None: sel.append(self.current_cursor_line) if self.current_search_mark is not None: sel.append(self.current_search_mark) - sel.extend(self.smarts.get_extra_selections(self)) + if instant: + sel.extend(self.smarts.get_extra_selections(self)) + else: + self.smarts_highlight_timer.start() self.setExtraSelections(sel) # Search and replace {{{ @@ -456,7 +461,7 @@ class TextEdit(PlainTextEdit): sel.cursor = self.textCursor() sel.cursor.clearSelection() self.current_cursor_line = sel - self.update_extra_selections() + self.update_extra_selections(instant=False) # Update the cursor line's line number in the line number area try: self.line_number_area.update(0, self.last_current_lnum[0], self.line_number_area.width(), self.last_current_lnum[1])