From 420b2f65b40c84106c39549823141385b16730f3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 14 Oct 2019 17:26:51 +0530 Subject: [PATCH] Edit book: Fix a crash when editing CSS files caused by a behavior change in Qt 5.13. Fixes #1846760 [ebook editor crashes out when scrolling](https://bugs.launchpad.net/calibre/+bug/1846760) Apparently, if a QTextFormat.FormatRange object is garbage collected by python it is no longer safe to use a previously stored reference to it QTextFormat object --- src/calibre/gui2/tweak_book/editor/text.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/calibre/gui2/tweak_book/editor/text.py b/src/calibre/gui2/tweak_book/editor/text.py index 86c8739399..aceaf6d154 100644 --- a/src/calibre/gui2/tweak_book/editor/text.py +++ b/src/calibre/gui2/tweak_book/editor/text.py @@ -741,12 +741,10 @@ class TextEdit(PlainTextEdit): if r.start <= pos <= r.start + r.length and r.format.property(SYNTAX_PROPERTY): return r - def syntax_format_for_cursor(self, cursor): - return getattr(self.syntax_range_for_cursor(cursor), 'format', None) - def show_tooltip(self, ev): c = self.cursorForPosition(ev.pos()) - fmt = self.syntax_format_for_cursor(c) + fmt_range = self.syntax_range_for_cursor(c) + fmt = getattr(fmt_range, 'format', None) if fmt is not None: tt = unicode_type(fmt.toolTip()) if tt: