mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Another small speedup
This commit is contained in:
parent
8d1433ae78
commit
b2168dc176
@ -130,7 +130,8 @@ class SyntaxHighlighter(object):
|
|||||||
block = doc.findBlock(position)
|
block = doc.findBlock(position)
|
||||||
while block.isValid() and (block.position() < end_pos or force_next_highlight):
|
while block.isValid() and (block.position() < end_pos or force_next_highlight):
|
||||||
formats, force_next_highlight = self.parse_single_block(block)
|
formats, force_next_highlight = self.parse_single_block(block)
|
||||||
self.apply_format_changes(doc, block, formats)
|
self.apply_format_changes(block, formats)
|
||||||
|
doc.markContentsDirty(block.position(), block.length())
|
||||||
block = block.next()
|
block = block.next()
|
||||||
finally:
|
finally:
|
||||||
doc.contentsChange.connect(self.reformat_blocks)
|
doc.contentsChange.connect(self.reformat_blocks)
|
||||||
@ -151,7 +152,9 @@ class SyntaxHighlighter(object):
|
|||||||
formats = []
|
formats = []
|
||||||
for i, num, fmt in run_loop(ud, self.state_map, self.formats, unicode(block.text())):
|
for i, num, fmt in run_loop(ud, self.state_map, self.formats, unicode(block.text())):
|
||||||
if fmt is not None:
|
if fmt is not None:
|
||||||
formats.append((i, num, fmt))
|
r = QTextLayout.FormatRange()
|
||||||
|
r.start, r.length, r.format = i, num, fmt
|
||||||
|
formats.append(r)
|
||||||
force_next_highlight = is_new_ud or ud.state != orig_state
|
force_next_highlight = is_new_ud or ud.state != orig_state
|
||||||
return formats, force_next_highlight
|
return formats, force_next_highlight
|
||||||
|
|
||||||
@ -159,22 +162,16 @@ class SyntaxHighlighter(object):
|
|||||||
if block.isValid():
|
if block.isValid():
|
||||||
self.reformat_blocks(block.position(), 0, 1)
|
self.reformat_blocks(block.position(), 0, 1)
|
||||||
|
|
||||||
def apply_format_changes(self, doc, block, formats):
|
def apply_format_changes(self, block, formats):
|
||||||
layout = block.layout()
|
layout = block.layout()
|
||||||
preedit_start = layout.preeditAreaPosition()
|
preedit_start = layout.preeditAreaPosition()
|
||||||
preedit_length = layout.preeditAreaText().length()
|
preedit_length = layout.preeditAreaText().length()
|
||||||
ranges = []
|
for r in formats:
|
||||||
R = QTextLayout.FormatRange
|
|
||||||
for i, num, fmt in formats:
|
|
||||||
# Adjust range by pre-edit text, if any
|
# Adjust range by pre-edit text, if any
|
||||||
if preedit_start != 0:
|
if preedit_start != 0:
|
||||||
if i >= preedit_start:
|
if r.start >= preedit_start:
|
||||||
i += preedit_length
|
r.start += preedit_length
|
||||||
elif i + num >= preedit_start:
|
elif r.start + r.length >= preedit_start:
|
||||||
num += preedit_length
|
r.length += preedit_length
|
||||||
r = R()
|
layout.setAdditionalFormats(formats)
|
||||||
r.start, r.length, r.format = i, num, fmt
|
|
||||||
ranges.append(r)
|
|
||||||
layout.setAdditionalFormats(ranges)
|
|
||||||
doc.markContentsDirty(block.position(), block.length())
|
|
||||||
|
|
||||||
|
@ -578,9 +578,9 @@ class TextEdit(PlainTextEdit):
|
|||||||
with store_locale:
|
with store_locale:
|
||||||
formats = self.highlighter.parse_single_block(c.block())[0]
|
formats = self.highlighter.parse_single_block(c.block())[0]
|
||||||
pos = c.positionInBlock()
|
pos = c.positionInBlock()
|
||||||
for i, num, fmt in formats:
|
for r in formats:
|
||||||
if i <= pos < i + num and fmt.property(SPELL_PROPERTY).toBool():
|
if r.start <= pos < r.start + r.length and r.format.property(SPELL_PROPERTY).toBool():
|
||||||
return fmt.property(SPELL_LOCALE_PROPERTY).toPyObject()
|
return r.format.property(SPELL_LOCALE_PROPERTY).toPyObject()
|
||||||
|
|
||||||
def recheck_word(self, word, locale):
|
def recheck_word(self, word, locale):
|
||||||
c = self.textCursor()
|
c = self.textCursor()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user