mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit book: Fix highlighting for special characters not visible when the cursor is on the line with the special character
This commit is contained in:
parent
3badcba7b1
commit
9741a12e02
@ -4,14 +4,16 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
from collections import defaultdict, deque
|
from collections import defaultdict, deque
|
||||||
|
from qt.core import (
|
||||||
|
QTextBlock, QTextBlockUserData, QTextCursor, QTextFormat, QTextLayout, QTimer,
|
||||||
|
)
|
||||||
|
|
||||||
from qt.core import QTextCursor, QTextBlockUserData, QTextLayout, QTimer
|
|
||||||
|
|
||||||
from ..themes import highlight_to_char_format
|
|
||||||
from calibre.gui2.widgets import BusyCursor
|
from calibre.gui2.widgets import BusyCursor
|
||||||
from calibre.utils.icu import utf16_length
|
from calibre.utils.icu import utf16_length
|
||||||
from polyglot.builtins import iteritems
|
from polyglot.builtins import iteritems
|
||||||
|
|
||||||
|
from ..themes import highlight_to_char_format
|
||||||
|
|
||||||
|
|
||||||
def run_loop(user_data, state_map, formats, text):
|
def run_loop(user_data, state_map, formats, text):
|
||||||
state = user_data.state
|
state = user_data.state
|
||||||
@ -240,3 +242,11 @@ class SyntaxHighlighter:
|
|||||||
elif r.start + r.length >= preedit_start:
|
elif r.start + r.length >= preedit_start:
|
||||||
r.length += preedit_length
|
r.length += preedit_length
|
||||||
layout.setFormats(formats)
|
layout.setFormats(formats)
|
||||||
|
|
||||||
|
def formats_for_line(self, block: QTextBlock, start, length):
|
||||||
|
layout = block.layout()
|
||||||
|
start_in_block = start - block.position()
|
||||||
|
limit = start_in_block + length
|
||||||
|
for f in layout.formats():
|
||||||
|
if f.start >= start_in_block and f.start < limit and f.format.hasProperty(QTextFormat.Property.BackgroundBrush):
|
||||||
|
yield f
|
||||||
|
@ -331,7 +331,7 @@ class TextEdit(PlainTextEdit):
|
|||||||
def update_extra_selections(self, instant=True):
|
def update_extra_selections(self, instant=True):
|
||||||
sel = []
|
sel = []
|
||||||
if self.current_cursor_line is not None:
|
if self.current_cursor_line is not None:
|
||||||
sel.append(self.current_cursor_line)
|
sel.extend(self.current_cursor_line)
|
||||||
if self.current_search_mark is not None:
|
if self.current_search_mark is not None:
|
||||||
sel.append(self.current_search_mark)
|
sel.append(self.current_search_mark)
|
||||||
if instant and not self.highlighter.has_requests and self.smarts is not None:
|
if instant and not self.highlighter.has_requests and self.smarts is not None:
|
||||||
@ -627,7 +627,24 @@ class TextEdit(PlainTextEdit):
|
|||||||
sel.format.setProperty(QTextFormat.Property.FullWidthSelection, True)
|
sel.format.setProperty(QTextFormat.Property.FullWidthSelection, True)
|
||||||
sel.cursor = self.textCursor()
|
sel.cursor = self.textCursor()
|
||||||
sel.cursor.clearSelection()
|
sel.cursor.clearSelection()
|
||||||
self.current_cursor_line = sel
|
self.current_cursor_line = [sel]
|
||||||
|
|
||||||
|
# apply any formats that have a backgroud over the cursor line format
|
||||||
|
# to ensure they are visible
|
||||||
|
c = self.textCursor()
|
||||||
|
block = c.block()
|
||||||
|
c.clearSelection()
|
||||||
|
c.select(QTextCursor.SelectionType.LineUnderCursor)
|
||||||
|
start = min(c.anchor(), c.position())
|
||||||
|
length = max(c.anchor(), c.position()) - start
|
||||||
|
for f in self.highlighter.formats_for_line(block, start, length):
|
||||||
|
sel = QTextEdit.ExtraSelection()
|
||||||
|
c = self.textCursor()
|
||||||
|
c.setPosition(f.start + block.position())
|
||||||
|
c.setPosition(c.position() + f.length, QTextCursor.MoveMode.KeepAnchor)
|
||||||
|
sel.cursor, sel.format = c, f.format
|
||||||
|
self.current_cursor_line.append(sel)
|
||||||
|
|
||||||
self.update_extra_selections(instant=False)
|
self.update_extra_selections(instant=False)
|
||||||
# Update the cursor line's line number in the line number area
|
# Update the cursor line's line number in the line number area
|
||||||
try:
|
try:
|
||||||
|
@ -66,7 +66,7 @@ SOLARIZED = \
|
|||||||
Statement fg={green} bold
|
Statement fg={green} bold
|
||||||
Keyword fg={green}
|
Keyword fg={green}
|
||||||
Special fg={red}
|
Special fg={red}
|
||||||
SpecialCharacter bg={base02}
|
SpecialCharacter bg={base03}
|
||||||
|
|
||||||
Error us=wave uc={red}
|
Error us=wave uc={red}
|
||||||
SpellError us=wave uc={orange}
|
SpellError us=wave uc={orange}
|
||||||
@ -113,7 +113,7 @@ THEMES = {
|
|||||||
Special fg={special}
|
Special fg={special}
|
||||||
Error us=wave uc=red
|
Error us=wave uc=red
|
||||||
SpellError us=wave uc=orange
|
SpellError us=wave uc=orange
|
||||||
SpecialCharacter bg={cursor_loc}
|
SpecialCharacter bg=666666
|
||||||
Link fg=cyan
|
Link fg=cyan
|
||||||
BadLink fg={string} us=wave uc=red
|
BadLink fg={string} us=wave uc=red
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ THEMES = {
|
|||||||
Statement fg={keyword}
|
Statement fg={keyword}
|
||||||
Keyword fg={keyword}
|
Keyword fg={keyword}
|
||||||
Special fg={special} italic
|
Special fg={special} italic
|
||||||
SpecialCharacter bg={cursor_loc}
|
SpecialCharacter bg=afafaf
|
||||||
Error us=wave uc=red
|
Error us=wave uc=red
|
||||||
SpellError us=wave uc=magenta
|
SpellError us=wave uc=magenta
|
||||||
Link fg=blue
|
Link fg=blue
|
||||||
|
Loading…
x
Reference in New Issue
Block a user