@@ -588,6 +588,7 @@ function checkEditorStyle () {
588
588
}
589
589
// workaround editor will have wrong doc height when editor height changed
590
590
editor . setSize ( null , ui . area . edit . height ( ) )
591
+ checkEditorScrollOverLines ( )
591
592
// make editor resizable
592
593
if ( ! ui . area . resize . handle . length ) {
593
594
ui . area . edit . resizable ( {
@@ -674,6 +675,15 @@ function checkEditorScrollbarInner () {
674
675
editor . scrollTo ( null , scrollInfo . top )
675
676
}
676
677
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
+
677
687
function checkTocStyle ( ) {
678
688
// toc right
679
689
var paddingRight = parseFloat ( ui . area . markdown . css ( 'padding-right' ) )
@@ -2554,9 +2564,11 @@ function enforceMaxLength (cm, change) {
2554
2564
}
2555
2565
return false
2556
2566
}
2567
+ let lastDocHeight
2557
2568
var ignoreEmitEvents = [ 'setValue' , 'ignoreHistory' ]
2558
2569
editorInstance . on ( 'beforeChange' , function ( cm , change ) {
2559
2570
if ( debug ) { console . debug ( change ) }
2571
+ lastDocHeight = editor . doc . height
2560
2572
removeNullByte ( cm , change )
2561
2573
if ( enforceMaxLength ( cm , change ) ) {
2562
2574
$ ( '.limit-modal' ) . modal ( 'show' )
@@ -2590,6 +2602,7 @@ editorInstance.on('paste', function () {
2590
2602
// na
2591
2603
} )
2592
2604
editorInstance . on ( 'changes' , function ( editor , changes ) {
2605
+ const docHeightChanged = editor . doc . height !== lastDocHeight
2593
2606
updateHistory ( )
2594
2607
var docLength = editor . getValue ( ) . length
2595
2608
// workaround for big documents
@@ -2605,13 +2618,18 @@ editorInstance.on('changes', function (editor, changes) {
2605
2618
viewportMargin = newViewportMargin
2606
2619
windowResize ( )
2607
2620
}
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
+ }
2613
2630
}
2614
2631
}
2632
+ lastDocHeight = editor . doc . height
2615
2633
} )
2616
2634
editorInstance . on ( 'focus' , function ( editor ) {
2617
2635
for ( var i = 0 ; i < onlineUsers . length ; i ++ ) {
0 commit comments