From 72b4e3bf4d2181a4ac19f63471790da499f6c723 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Mon, 17 Mar 2014 22:56:50 +0000 Subject: [PATCH] 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 --- ghost/admin/assets/lib/editor/markdownEditor.js | 3 +++ ghost/admin/assets/lib/editor/scrollHandler.js | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/ghost/admin/assets/lib/editor/markdownEditor.js b/ghost/admin/assets/lib/editor/markdownEditor.js index a35f7ab8fd..65a864e948 100644 --- a/ghost/admin/assets/lib/editor/markdownEditor.js +++ b/ghost/admin/assets/lib/editor/markdownEditor.js @@ -81,6 +81,9 @@ $(document).trigger('markdownEditorChange'); }); }, + isCursorAtEnd: function () { + return codemirror.getCursor('end').line > codemirror.lineCount() - 5; + }, value: function () { return codemirror.getValue(); } diff --git a/ghost/admin/assets/lib/editor/scrollHandler.js b/ghost/admin/assets/lib/editor/scrollHandler.js index b996879240..05d6638cd6 100644 --- a/ghost/admin/assets/lib/editor/scrollHandler.js +++ b/ghost/admin/assets/lib/editor/scrollHandler.js @@ -21,6 +21,10 @@ ratio = previewHeight / markdownHeight, previewPosition = $markdownViewPort.scrollTop() * ratio; + if (markdown.isCursorAtEnd()) { + previewPosition = previewHeight + 30; + } + // apply new scroll $previewViewPort.scrollTop(previewPosition); }, 10);