TTS should start reading from the current page

This commit is contained in:
Kovid Goyal 2020-12-11 07:34:17 +05:30
parent c80acf0aed
commit f4b6806202
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 17 additions and 4 deletions

View File

@ -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,8 +903,9 @@ 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:
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()

View File

@ -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},