mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Edit book: A new option to show a configurable number lines above the current line when syncing the position of the preview panel to the current position in the code editor (under Preview settings in the Editor preferences). Fixes #1908929 [Enhancement request for seeing code changes in file previewer.](https://bugs.launchpad.net/calibre/+bug/1908929)
This commit is contained in:
parent
a4907b5012
commit
2a66dfead0
@ -38,6 +38,7 @@ d['preview_standard_font_family'] = 'serif'
|
|||||||
d['preview_base_font_size'] = 18
|
d['preview_base_font_size'] = 18
|
||||||
d['preview_mono_font_size'] = 14
|
d['preview_mono_font_size'] = 14
|
||||||
d['preview_minimum_font_size'] = 8
|
d['preview_minimum_font_size'] = 8
|
||||||
|
d['preview_sync_context'] = 0
|
||||||
d['preview_background'] = 'auto'
|
d['preview_background'] = 'auto'
|
||||||
d['preview_foreground'] = 'auto'
|
d['preview_foreground'] = 'auto'
|
||||||
d['preview_link_color'] = 'auto'
|
d['preview_link_color'] = 'auto'
|
||||||
|
@ -381,6 +381,11 @@ class PreviewSettings(BasicSettings): # {{{
|
|||||||
w = self('preview_minimum_font_size')
|
w = self('preview_minimum_font_size')
|
||||||
w.setMinimum(4), w.setMaximum(100), w.setSuffix(' px')
|
w.setMinimum(4), w.setMaximum(100), w.setSuffix(' px')
|
||||||
l.addRow(_('Mi&nimum font size:'), w)
|
l.addRow(_('Mi&nimum font size:'), w)
|
||||||
|
w = self('preview_sync_context')
|
||||||
|
w.setMinimum(0), w.setMaximum(10), w.setSuffix(' ' + _('lines'))
|
||||||
|
w.setToolTip('<p>' + _(
|
||||||
|
'Number of lines that are shown above the current line when syncing the text shown in the preview panel to the cursor position in the code view'))
|
||||||
|
l.addRow(_('Visible lines above s&ync point:'), w)
|
||||||
l.addRow(_('Background color:'), self.color_override('preview_background'))
|
l.addRow(_('Background color:'), self.color_override('preview_background'))
|
||||||
l.addRow(_('Foreground color:'), self.color_override('preview_foreground'))
|
l.addRow(_('Foreground color:'), self.color_override('preview_foreground'))
|
||||||
l.addRow(_('Link color:'), self.color_override('preview_link_color'))
|
l.addRow(_('Link color:'), self.color_override('preview_link_color'))
|
||||||
|
@ -341,7 +341,7 @@ class WebPage(QWebEnginePage):
|
|||||||
if lnum is None:
|
if lnum is None:
|
||||||
return
|
return
|
||||||
tags = [x.lower() for x in tags]
|
tags = [x.lower() for x in tags]
|
||||||
self.bridge.go_to_sourceline_address.emit(lnum, tags)
|
self.bridge.go_to_sourceline_address.emit(lnum, tags, tprefs['preview_sync_context'])
|
||||||
|
|
||||||
def split_mode(self, enabled):
|
def split_mode(self, enabled):
|
||||||
if self.bridge.ready:
|
if self.bridge.ready:
|
||||||
|
@ -40,34 +40,53 @@ def find_containing_block(elem):
|
|||||||
elem = elem.parentNode
|
elem = elem.parentNode
|
||||||
return elem
|
return elem
|
||||||
|
|
||||||
def scroll_to_node(node):
|
|
||||||
|
def line_height():
|
||||||
|
ans = line_height.ans
|
||||||
|
if not ans:
|
||||||
|
ds = window.getComputedStyle(document.body)
|
||||||
|
try:
|
||||||
|
# will fail if line-height = "normal"
|
||||||
|
lh = float(ds.lineHeight)
|
||||||
|
except:
|
||||||
|
try:
|
||||||
|
lh = 1.2 * float(ds.fontSize)
|
||||||
|
except:
|
||||||
|
lh = 15
|
||||||
|
ans = line_height.ans = max(5, lh)
|
||||||
|
return ans
|
||||||
|
|
||||||
|
|
||||||
|
def scroll_to_node(node, sync_context):
|
||||||
if node is document.body:
|
if node is document.body:
|
||||||
window.scrollTo(0, 0)
|
window.scrollTo(0, 0)
|
||||||
else:
|
else:
|
||||||
node.scrollIntoView()
|
node.scrollIntoView()
|
||||||
|
if sync_context:
|
||||||
|
window.scrollBy(0, -sync_context * line_height())
|
||||||
|
|
||||||
|
|
||||||
state = {'blocks_found': False, 'in_split_mode': False}
|
state = {'blocks_found': False, 'in_split_mode': False}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def go_to_line(lnum):
|
def go_to_line(lnum, sync_context):
|
||||||
for node in document.querySelectorAll(f'[data-lnum="{lnum}"]'):
|
for node in document.querySelectorAll(f'[data-lnum="{lnum}"]'):
|
||||||
if is_hidden(node):
|
if is_hidden(node):
|
||||||
continue
|
continue
|
||||||
scroll_to_node(node)
|
scroll_to_node(node, sync_context)
|
||||||
break
|
break
|
||||||
|
|
||||||
@from_python
|
@from_python
|
||||||
def go_to_sourceline_address(sourceline, tags):
|
def go_to_sourceline_address(sourceline, tags, sync_context):
|
||||||
nodes = document.querySelectorAll(f'[data-lnum="{sourceline}"]')
|
nodes = document.querySelectorAll(f'[data-lnum="{sourceline}"]')
|
||||||
for index in range(nodes.length):
|
for index in range(nodes.length):
|
||||||
node = nodes[index]
|
node = nodes[index]
|
||||||
if index >= tags.length or node.tagName.toLowerCase() is not tags[index]:
|
if index >= tags.length or node.tagName.toLowerCase() is not tags[index]:
|
||||||
break
|
break
|
||||||
if index == tags.length - 1 and not is_hidden(node):
|
if index == tags.length - 1 and not is_hidden(node):
|
||||||
return scroll_to_node(node)
|
return scroll_to_node(node, sync_context)
|
||||||
go_to_line(sourceline)
|
go_to_line(sourceline, sync_context)
|
||||||
|
|
||||||
def line_numbers():
|
def line_numbers():
|
||||||
found_body = False
|
found_body = False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user