When calculating CFI in paged mode go column-by-column from left to right and in each column start form midpoint and expand outwards

This commit is contained in:
Kovid Goyal 2019-10-09 12:45:19 +05:30
parent 1ca6398471
commit 6f09624280
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -401,25 +401,33 @@ def current_cfi():
# null if it could not be calculated. # null if it could not be calculated.
ans = None ans = None
if in_paged_mode(): if in_paged_mode():
c = current_column_location() for cnum in range(cols_per_screen):
for x in c, c - col_and_gap, c + col_and_gap: left = cnum * (col_and_gap + gap)
# Try the current column, the previous column and the next right = left + col_width
# column. Each column is tried from top to bottom. top, bottom = 0, scroll_viewport.height()
left, right = x, x + col_and_gap midx = (right - left) // 2
if left < 0 or right > scroll_viewport.paged_content_width(): deltax = (right - left) // 24
continue deltay = (bottom - top) // 24
deltax = col_and_gap // 25 midy = (bottom - top) // 2
deltay = scroll_viewport.height() // 25 yidx = 0
cury = 0 while True:
while cury < scroll_viewport.height(): yb, ya = midy - yidx * deltay, midy + yidx * deltay
curx = left if yb <= top or ya >= bottom:
while curx < right - gap: break
cfi = cfi_at_point(curx-Math.ceil(current_scroll_offset()), cury-Math.ceil(window.pageYOffset)) yidx += 1
xidx = 0
ys = v'[ya]' if ya is yb else v'[yb, ya]'
for cury in ys:
xb, xa = midx - xidx * deltax, midx + xidx * deltax
if xa <= left or xb >= right:
break
xidx += 1
xs = v'[xa]' if xa is xb else v'[xb, xa]'
for curx in xs:
cfi = cfi_at_point(curx, cury)
if cfi: if cfi:
# print('Viewport cfi:', cfi) # print('Viewport cfi:', cfi)
return cfi return cfi
curx += deltax
cury += deltay
else: else:
try: try:
ans = cfi_at_current() or None ans = cfi_at_current() or None