From 14ee0d0ad567584d1a6dbfbfa9da4f37b95088eb Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Fri, 9 Dec 2011 13:15:15 +1100 Subject: [PATCH] Scroll cursor into view on enter. --- source/Editor.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/source/Editor.js b/source/Editor.js index dfb9b87..339a0e5 100644 --- a/source/Editor.js +++ b/source/Editor.js @@ -295,7 +295,7 @@ undoStack, // = [], undoStackLength, // = 0, isInUndoState, // = false, - docWasChanged = function docWasChanged () { + docWasChanged = function () { if ( isInUndoState ) { isInUndoState = false; fireEvent( 'undoStateChange', { @@ -1253,6 +1253,16 @@ setSelection( createRange( nodeAfterSplit, 0 ) ); updatePath( 0, true ); + // Scroll into view + if ( nodeAfterSplit.nodeType === TEXT_NODE ) { + nodeAfterSplit = nodeAfterSplit.parentNode; + } + if ( nodeAfterSplit.offsetTop + nodeAfterSplit.offsetHeight > + ( doc.documentElement.scrollTop || body.scrollTop ) + + body.offsetHeight ) { + nodeAfterSplit.scrollIntoView( false ); + } + // We're not still in an undo state docWasChanged(); },