@@ -588,6 +588,7 @@ function checkEditorStyle () {
588588 }
589589 // workaround editor will have wrong doc height when editor height changed
590590 editor . setSize ( null , ui . area . edit . height ( ) )
591+ checkEditorScrollOverLines ( )
591592 // make editor resizable
592593 if ( ! ui . area . resize . handle . length ) {
593594 ui . area . edit . resizable ( {
@@ -674,6 +675,15 @@ function checkEditorScrollbarInner () {
674675 editor . scrollTo ( null , scrollInfo . top )
675676}
676677
678+ function checkEditorScrollOverLines ( ) {
679+ const desireHeight = parseInt ( ui . area . codemirrorScroll [ 0 ] . style . height ) || parseInt ( ui . area . codemirrorScroll [ 0 ] . style . minHeight )
680+ // make editor have extra padding in the bottom (except small screen)
681+ const paddingBottom = editor . doc && editor . doc . height > defaultTextHeight ? ( desireHeight - defaultTextHeight ) : 0
682+ if ( parseInt ( ui . area . codemirrorLines . css ( 'padding-bottom' ) ) !== paddingBottom ) {
683+ ui . area . codemirrorLines . css ( 'padding-bottom' , paddingBottom + 'px' )
684+ }
685+ }
686+
677687function checkTocStyle ( ) {
678688 // toc right
679689 var paddingRight = parseFloat ( ui . area . markdown . css ( 'padding-right' ) )
@@ -2554,9 +2564,11 @@ function enforceMaxLength (cm, change) {
25542564 }
25552565 return false
25562566}
2567+ let lastDocHeight
25572568var ignoreEmitEvents = [ 'setValue' , 'ignoreHistory' ]
25582569editorInstance . on ( 'beforeChange' , function ( cm , change ) {
25592570 if ( debug ) { console . debug ( change ) }
2571+ lastDocHeight = editor . doc . height
25602572 removeNullByte ( cm , change )
25612573 if ( enforceMaxLength ( cm , change ) ) {
25622574 $ ( '.limit-modal' ) . modal ( 'show' )
@@ -2590,6 +2602,7 @@ editorInstance.on('paste', function () {
25902602 // na
25912603} )
25922604editorInstance . on ( 'changes' , function ( editor , changes ) {
2605+ const docHeightChanged = editor . doc . height !== lastDocHeight
25932606 updateHistory ( )
25942607 var docLength = editor . getValue ( ) . length
25952608 // workaround for big documents
@@ -2605,13 +2618,18 @@ editorInstance.on('changes', function (editor, changes) {
26052618 viewportMargin = newViewportMargin
26062619 windowResize ( )
26072620 }
2608- checkEditorScrollbar ( )
2609- if ( ui . area . codemirrorScroll [ 0 ] . scrollHeight > ui . area . view [ 0 ] . scrollHeight && editorHasFocus ( ) ) {
2610- postUpdateEvent = function ( ) {
2611- syncScrollToView ( )
2612- postUpdateEvent = null
2621+ if ( docHeightChanged ) {
2622+ checkEditorScrollbar ( )
2623+ checkEditorScrollOverLines ( )
2624+ // always sync edit scrolling to view if user is editing
2625+ if ( ui . area . codemirrorScroll [ 0 ] . scrollHeight > ui . area . view [ 0 ] . scrollHeight && editorHasFocus ( ) ) {
2626+ postUpdateEvent = function ( ) {
2627+ syncScrollToView ( )
2628+ postUpdateEvent = null
2629+ }
26132630 }
26142631 }
2632+ lastDocHeight = editor . doc . height
26152633} )
26162634editorInstance . on ( 'focus' , function ( editor ) {
26172635 for ( var i = 0 ; i < onlineUsers . length ; i ++ ) {
0 commit comments