0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00

Force preview to scroll to the end

fixes #958, fixes #535

- If the cursor is within the last 5 lines, then scroll to the end of the preview window, rather than using a ratio
This commit is contained in:
Hannah Wolfe 2014-03-17 22:56:50 +00:00
parent 545fc6e911
commit 72b4e3bf4d
2 changed files with 7 additions and 0 deletions

View file

@ -81,6 +81,9 @@
$(document).trigger('markdownEditorChange'); $(document).trigger('markdownEditorChange');
}); });
}, },
isCursorAtEnd: function () {
return codemirror.getCursor('end').line > codemirror.lineCount() - 5;
},
value: function () { value: function () {
return codemirror.getValue(); return codemirror.getValue();
} }

View file

@ -21,6 +21,10 @@
ratio = previewHeight / markdownHeight, ratio = previewHeight / markdownHeight,
previewPosition = $markdownViewPort.scrollTop() * ratio; previewPosition = $markdownViewPort.scrollTop() * ratio;
if (markdown.isCursorAtEnd()) {
previewPosition = previewHeight + 30;
}
// apply new scroll // apply new scroll
$previewViewPort.scrollTop(previewPosition); $previewViewPort.scrollTop(previewPosition);
}, 10); }, 10);