mirror of https://github.com/status-im/codimd.git
Updated syncscroll to lerp on last line
This commit is contained in:
parent
8db142554f
commit
6967dac0ff
|
@ -161,13 +161,15 @@ ui.area.view.on('scroll', function () {
|
||||||
//editor.on('scroll', _.debounce(syncScrollToView, syncScrollDelay));
|
//editor.on('scroll', _.debounce(syncScrollToView, syncScrollDelay));
|
||||||
//ui.area.view.on('scroll', _.debounce(syncScrollToEdit, 50));
|
//ui.area.view.on('scroll', _.debounce(syncScrollToEdit, 50));
|
||||||
|
|
||||||
var scrollMap, lineHeightMap;
|
var scrollMap, lineHeightMap, viewTop, viewBottom;
|
||||||
|
|
||||||
viewAjaxCallback = clearMap;
|
viewAjaxCallback = clearMap;
|
||||||
|
|
||||||
function clearMap() {
|
function clearMap() {
|
||||||
scrollMap = null;
|
scrollMap = null;
|
||||||
lineHeightMap = null;
|
lineHeightMap = null;
|
||||||
|
viewTop = null;
|
||||||
|
viewBottom = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var buildMap = _.throttle(buildMapInner, buildMapThrottle);
|
var buildMap = _.throttle(buildMapInner, buildMapThrottle);
|
||||||
|
@ -183,6 +185,8 @@ function buildMapInner(syncBack) {
|
||||||
_scrollMap = [];
|
_scrollMap = [];
|
||||||
nonEmptyList = [];
|
nonEmptyList = [];
|
||||||
_lineHeightMap = [];
|
_lineHeightMap = [];
|
||||||
|
viewTop = 0;
|
||||||
|
viewBottom = ui.area.view[0].scrollHeight - ui.area.view.height();
|
||||||
|
|
||||||
acc = 0;
|
acc = 0;
|
||||||
var lines = editor.getValue().split('\n');
|
var lines = editor.getValue().split('\n');
|
||||||
|
@ -208,7 +212,8 @@ function buildMapInner(syncBack) {
|
||||||
}
|
}
|
||||||
|
|
||||||
nonEmptyList.push(0);
|
nonEmptyList.push(0);
|
||||||
_scrollMap[0] = 0;
|
// make the first line go top
|
||||||
|
_scrollMap[0] = viewTop;
|
||||||
|
|
||||||
var parts = ui.area.markdown.find('.part').toArray();
|
var parts = ui.area.markdown.find('.part').toArray();
|
||||||
for (i = 0; i < parts.length; i++) {
|
for (i = 0; i < parts.length; i++) {
|
||||||
|
@ -296,9 +301,13 @@ function syncScrollToView(event, _lineNo) {
|
||||||
var topDiffPercent, posToNextDiff;
|
var topDiffPercent, posToNextDiff;
|
||||||
var textHeight = editor.defaultTextHeight();
|
var textHeight = editor.defaultTextHeight();
|
||||||
lineNo = Math.floor(scrollInfo.top / textHeight);
|
lineNo = Math.floor(scrollInfo.top / textHeight);
|
||||||
//if reach bottom, then scroll to end
|
// if reach the last line, will start lerp to the bottom
|
||||||
if (scrollInfo.height > scrollInfo.clientHeight && scrollInfo.top + scrollInfo.clientHeight >= scrollInfo.height - textHeight) {
|
var diffToBottom = (scrollInfo.top + scrollInfo.clientHeight) - (scrollInfo.height - textHeight);
|
||||||
posTo = ui.area.view[0].scrollHeight - ui.area.view.height();
|
if (scrollInfo.height > scrollInfo.clientHeight && diffToBottom > 0) {
|
||||||
|
topDiffPercent = diffToBottom / textHeight;
|
||||||
|
posTo = scrollMap[lineNo + 1];
|
||||||
|
posToNextDiff = (viewBottom - posTo) * topDiffPercent;
|
||||||
|
posTo += Math.floor(posToNextDiff);
|
||||||
} else {
|
} else {
|
||||||
topDiffPercent = (scrollInfo.top % textHeight) / textHeight;
|
topDiffPercent = (scrollInfo.top % textHeight) / textHeight;
|
||||||
posTo = scrollMap[lineNo];
|
posTo = scrollMap[lineNo];
|
||||||
|
|
Loading…
Reference in New Issue