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.
ans = None
if in_paged_mode():
c = current_column_location()
for x in c, c - col_and_gap, c + col_and_gap:
# Try the current column, the previous column and the next
# column. Each column is tried from top to bottom.
left, right = x, x + col_and_gap
if left < 0 or right > scroll_viewport.paged_content_width():
continue
deltax = col_and_gap // 25
deltay = scroll_viewport.height() // 25
cury = 0
while cury < scroll_viewport.height():
curx = left
while curx < right - gap:
cfi = cfi_at_point(curx-Math.ceil(current_scroll_offset()), cury-Math.ceil(window.pageYOffset))
if cfi:
# print('Viewport cfi:', cfi)
return cfi
curx += deltax
cury += deltay
for cnum in range(cols_per_screen):
left = cnum * (col_and_gap + gap)
right = left + col_width
top, bottom = 0, scroll_viewport.height()
midx = (right - left) // 2
deltax = (right - left) // 24
deltay = (bottom - top) // 24
midy = (bottom - top) // 2
yidx = 0
while True:
yb, ya = midy - yidx * deltay, midy + yidx * deltay
if yb <= top or ya >= bottom:
break
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:
# print('Viewport cfi:', cfi)
return cfi
else:
try:
ans = cfi_at_current() or None