@@ -530,6 +530,7 @@ var ui = {
530530 edit : $ ( ".ui-edit-area" ) ,
531531 view : $ ( ".ui-view-area" ) ,
532532 codemirror : $ ( ".ui-edit-area .CodeMirror" ) ,
533+ codemirrorScroll : $ ( ".ui-edit-area .CodeMirror .CodeMirror-scroll" ) ,
533534 markdown : $ ( ".ui-view-area .markdown-body" )
534535 }
535536} ;
@@ -703,26 +704,37 @@ function locationHashChanged(e) {
703704var windowResizeDebounce = 200 ;
704705var windowResize = _ . debounce ( windowResizeInner , windowResizeDebounce ) ;
705706
706- function windowResizeInner ( ) {
707+ function windowResizeInner ( callback ) {
707708 checkLayout ( ) ;
708709 checkResponsive ( ) ;
709710 checkEditorStyle ( ) ;
710711 checkTocStyle ( ) ;
711712 checkCursorMenu ( ) ;
712713 //refresh editor
713714 if ( loaded ) {
714- editor . setOption ( 'viewportMargin' , Infinity ) ;
715- setTimeout ( function ( ) {
715+ if ( editor . getOption ( 'scrollbarStyle' ) === 'native' ) {
716716 clearMap ( ) ;
717717 syncScrollToView ( ) ;
718- editor . setOption ( 'viewportMargin' , viewportMargin ) ;
719- //add or update user cursors
720- for ( var i = 0 ; i < onlineUsers . length ; i ++ ) {
721- if ( onlineUsers [ i ] . id != personalInfo . id )
722- buildCursor ( onlineUsers [ i ] ) ;
723- }
724718 updateScrollspy ( ) ;
725- } , 100 ) ;
719+ if ( callback && typeof callback === 'function' )
720+ callback ( ) ;
721+ } else {
722+ // force it load all docs at once to prevent scroll knob blink
723+ editor . setOption ( 'viewportMargin' , Infinity ) ;
724+ setTimeout ( function ( ) {
725+ clearMap ( ) ;
726+ syncScrollToView ( ) ;
727+ editor . setOption ( 'viewportMargin' , viewportMargin ) ;
728+ //add or update user cursors
729+ for ( var i = 0 ; i < onlineUsers . length ; i ++ ) {
730+ if ( onlineUsers [ i ] . id != personalInfo . id )
731+ buildCursor ( onlineUsers [ i ] ) ;
732+ }
733+ updateScrollspy ( ) ;
734+ if ( callback && typeof callback === 'function' )
735+ callback ( ) ;
736+ } , 1 ) ;
737+ }
726738 }
727739}
728740
@@ -754,25 +766,16 @@ function checkResponsive() {
754766var lastEditorWidth = 0 ;
755767
756768function checkEditorStyle ( ) {
769+ var desireHeight = statusBar ? ( ui . area . edit . height ( ) - statusBar . outerHeight ( ) ) : ui . area . edit . height ( ) ;
770+ // set editor height and min height based on scrollbar style and mode
757771 var scrollbarStyle = editor . getOption ( 'scrollbarStyle' ) ;
758772 if ( scrollbarStyle == 'overlay' || currentMode == modeType . both ) {
759- //save last editor scroll top
760- var lastTop = editor . getScrollInfo ( ) . top ;
761- ui . area . codemirror . css ( 'height' , '' ) ;
762- //set editor size to keep status bar on the bottom
763- editor . setSize ( null , ui . area . edit . height ( ) ) ;
764- //restore last editor scroll top
765- editor . scrollTo ( null , lastTop ) ;
773+ ui . area . codemirrorScroll . css ( 'height' , desireHeight + 'px' ) ;
774+ ui . area . codemirrorScroll . css ( 'min-height' , '' ) ;
766775 } else if ( scrollbarStyle == 'native' ) {
767- ui . area . codemirror . css ( 'height' , 'auto ' ) ;
768- $ ( '.CodeMirror-gutters' ) . css ( 'height' , $ ( '.CodeMirror-sizer' ) . height ( ) ) ;
776+ ui . area . codemirrorScroll . css ( 'height' , '' ) ;
777+ ui . area . codemirrorScroll . css ( 'min- height' , desireHeight + 'px' ) ;
769778 }
770- //set editor parent height to fill status bar
771- if ( statusBar )
772- statusBar . parent ( ) . css ( 'height' , ui . area . edit . height ( ) - statusBar . outerHeight ( ) + 'px' ) ;
773- //set sizer height to make it at least height as editor
774- var editorSizerHeight = ui . area . edit . height ( ) - ( statusBar ? statusBar . outerHeight ( ) : 0 ) ;
775- $ ( '.CodeMirror-sizer' ) . css ( 'height' , editorSizerHeight + 'px' ) ;
776779 //make editor resizable
777780 ui . area . edit . resizable ( {
778781 handles : 'e' ,
@@ -879,6 +882,7 @@ function toggleMode() {
879882var lastMode = null ;
880883
881884function changeMode ( type ) {
885+ // lock navbar to prevent it hide after changeMode
882886 lockNavbar ( ) ;
883887 saveInfo ( ) ;
884888 if ( type ) {
@@ -949,16 +953,15 @@ function changeMode(type) {
949953 }
950954
951955 windowResizeInner ( ) ;
952-
956+
953957 restoreInfo ( ) ;
954-
958+
955959 if ( lastMode == modeType . view && currentMode == modeType . both ) {
956- if ( ! scrollMap || ! lineHeightMap )
957- buildMapInner ( ) ;
958- var scrollMapNearest = closestIndex ( scrollMap , lastInfo . view . scroll . top ) ;
959- var lineHeightMapNearest = closestIndex ( lineHeightMap , scrollMapNearest ) ;
960- var height = lineHeightMapNearest * defaultTextHeight ;
961- editor . scrollTo ( null , height ) ;
960+ syncScrollToEdit ( ) ;
961+ }
962+
963+ if ( lastMode != modeType . edit && currentMode == modeType . edit ) {
964+ editor . refresh ( ) ;
962965 }
963966
964967 ui . toolbar . both . removeClass ( "active" ) ;
@@ -987,6 +990,15 @@ var unlockNavbar = _.debounce(function () {
987990 $ ( '.navbar' ) . removeClass ( 'locked' ) ;
988991} , 200 ) ;
989992
993+ function syncScrollToEdit ( ) {
994+ if ( ! scrollMap || ! lineHeightMap )
995+ buildMapInner ( ) ;
996+ var scrollMapNearest = closestIndex ( scrollMap , lastInfo . view . scroll . top ) ;
997+ var lineHeightMapNearest = closestIndex ( lineHeightMap , scrollMapNearest ) ;
998+ var height = lineHeightMapNearest * defaultTextHeight ;
999+ editor . scrollTo ( null , height ) ;
1000+ }
1001+
9901002function closestIndex ( arr , closestTo ) {
9911003 var closest = Math . max . apply ( null , arr ) ; //Get the highest number in arr in case it match nothing.
9921004 var index = 0 ;
0 commit comments