1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-16 00:14:34 +02:00

Desktop: Fixes #6074: Scroll jumps when typing if heavy scripts or many large elements are used (#6383)

This commit is contained in:
Kenichi Kobayashi
2022-04-10 19:31:17 +09:00
committed by GitHub
parent e02422070e
commit f6e21e0180
7 changed files with 35 additions and 11 deletions

View File

@ -45,7 +45,8 @@ scrollmap.get_ = () => {
// Each map entry is total-ordered.
let last = 0;
for (let i = 0; i < elems.length; i++) {
const top = elems[i].getBoundingClientRect().top - offset;
const rect = elems[i].getBoundingClientRect();
const top = rect.top - offset;
const line = Number(elems[i].getAttribute('source-line'));
const percent = Math.max(0, Math.min(1, top / height));
if (map.line[last] < line && map.percent[last] < percent) {
@ -53,12 +54,20 @@ scrollmap.get_ = () => {
map.percent.push(percent);
last += 1;
}
const bottom = rect.bottom - offset;
const lineEnd = Number(elems[i].getAttribute('source-line-end'));
const percentEnd = Math.max(0, Math.min(1, bottom / height));
if (map.line[last] < lineEnd && map.percent[last] < percentEnd) {
map.line.push(lineEnd);
map.percent.push(percentEnd);
last += 1;
}
}
const lineCount = scrollmap.lineCount_;
if (lineCount) {
map.lineCount = lineCount;
} else {
if (map.lineCount <= map.line[last]) map.lineCount = map.line[last] + 1;
if (map.lineCount < map.line[last]) map.lineCount = map.line[last];
}
if (map.percent[last] < 1) {
map.line.push(lineCount || 1e10);