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
This commit is contained in:
Kovid Goyal 2019-10-14 17:26:51 +05:30
parent 12485fef82
commit 420b2f65b4
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -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: