mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
TTS should start reading from the current page
This commit is contained in:
parent
c80acf0aed
commit
f4b6806202
@ -64,7 +64,7 @@ from read_book.touch import (
|
||||
)
|
||||
from read_book.viewport import scroll_viewport
|
||||
from select import (
|
||||
move_end_of_selection, selection_extents, word_at_point
|
||||
move_end_of_selection, selection_extents, word_at_point, first_visible_word
|
||||
)
|
||||
from utils import debounce, is_ios
|
||||
|
||||
@ -903,9 +903,10 @@ class IframeBoss:
|
||||
text_node, offset = None, 0
|
||||
if data.pos:
|
||||
r = word_at_point(data.pos.x, data.pos.y)
|
||||
if r:
|
||||
if r.startContainer?.nodeType is Node.TEXT_NODE:
|
||||
text_node, offset = r.startContainer, r.startOffset
|
||||
else:
|
||||
r = first_visible_word()
|
||||
if r and r.startContainer?.nodeType is Node.TEXT_NODE:
|
||||
text_node, offset = r.startContainer, r.startOffset
|
||||
marked_text = tts_data(text_node, offset)
|
||||
sel = window.getSelection()
|
||||
sel.removeAllRanges()
|
||||
|
@ -42,6 +42,18 @@ def word_at_point(x, y):
|
||||
return r
|
||||
|
||||
|
||||
def first_visible_word():
|
||||
width = window.innerWidth
|
||||
height = window.innerHeight
|
||||
xdelta = width // 10
|
||||
ydelta = height // 10
|
||||
for y in range(0, height, ydelta):
|
||||
for x in range(0, width, xdelta):
|
||||
r = word_at_point(x, y)
|
||||
if r?:
|
||||
return r
|
||||
|
||||
|
||||
def empty_range_extents():
|
||||
return {
|
||||
'start': {'x': 0, 'y': 0, 'height': 0, 'width': 0, 'onscreen': False, 'selected_prev': False},
|
||||
|
Loading…
x
Reference in New Issue
Block a user