@@ -91,7 +91,7 @@ define(function (require, exports, module) {
9191 * @private
9292 * Add the styles used to update the font size
9393 * @param {string } fontSizeStyle A string with the font size and the size unit
94- * @param {string } lineHeightStyle A string with the line height and a the size unit
94+ * @param {string } lineHeightStyle A string with the line height and the size unit
9595 */
9696 function _addDynamicFontSize ( fontSizeStyle , lineHeightStyle ) {
9797 // It's necessary to inject a new rule to address all editors.
@@ -106,26 +106,28 @@ define(function (require, exports, module) {
106106 /**
107107 * @private
108108 * Sets the font size and restores the scroll position as best as possible.
109- * @param {string } fontSizeStyle A string with the font size and the size unit
110- * @param {string } lineHeightStyle A string with the line height and a the size unit
109+ * @param {string= } fontSizeStyle A string with the font size and the size unit
110+ * @param {string= } lineHeightStyle A string with the line height and the size unit
111111 */
112112 function _setSizeAndRestoreScroll ( fontSizeStyle , lineHeightStyle ) {
113113 var editor = EditorManager . getCurrentFullEditor ( ) ,
114114 oldWidth = editor . _codeMirror . defaultCharWidth ( ) ,
115- oldHeight = editor . getTextHeight ( ) ,
116- scrollPos = editor . getScrollPos ( ) ;
117-
118- _addDynamicFontSize ( fontSizeStyle , lineHeightStyle ) ;
115+ scrollPos = editor . getScrollPos ( ) ,
116+ line = editor . _codeMirror . lineAtHeight ( scrollPos . y , "local" ) ;
117+ console . log ( line ) ;
118+ if ( fontSizeStyle && lineHeightStyle ) {
119+ _addDynamicFontSize ( fontSizeStyle , lineHeightStyle ) ;
120+ } else {
121+ _removeDynamicFontSize ( ) ;
122+ }
119123 editor . refreshAll ( ) ;
120124
121125 // Calculate the new scroll based on the old font sizes and scroll position
122126 var newWidth = editor . _codeMirror . defaultCharWidth ( ) ,
123- newHeight = editor . getTextHeight ( ) ,
124127 deltaX = scrollPos . x / oldWidth ,
125- deltaY = scrollPos . y / oldHeight ,
126128 scrollPosX = scrollPos . x + Math . round ( deltaX * ( newWidth - oldWidth ) ) ,
127- scrollPosY = scrollPos . y + Math . round ( deltaY * ( newHeight - oldHeight ) ) ;
128-
129+ scrollPosY = editor . _codeMirror . heightAtLine ( line , "local" ) ;
130+ console . log ( scrollPosY ) ;
129131 editor . setScrollPos ( scrollPosX , scrollPosY ) ;
130132 }
131133
@@ -177,31 +179,28 @@ define(function (require, exports, module) {
177179
178180 _setSizeAndRestoreScroll ( fsStr , lhStr ) ;
179181
180- PreferencesManager . setViewState ( "fontSizeString " , fsStr ) ;
181- PreferencesManager . setViewState ( "lineHeightString " , lhStr ) ;
182+ PreferencesManager . setViewState ( "fontSizeStyle " , fsStr ) ;
183+ PreferencesManager . setViewState ( "lineHeightStyle " , lhStr ) ;
182184
183185 $ ( exports ) . triggerHandler ( "fontSizeChange" , [ adjustment , fsStr , lhStr ] ) ;
184186 return true ;
185187 }
186188
187189 /** Increases the font size by 1 */
188190 function _handleIncreaseFontSize ( ) {
189- if ( _adjustFontSize ( 1 ) ) {
190- PreferencesManager . setViewState ( "fontSizeAdjustment" , PreferencesManager . getViewState ( "fontSizeAdjustment" ) + 1 ) ;
191- }
191+ _adjustFontSize ( 1 ) ;
192192 }
193193
194194 /** Decreases the font size by 1 */
195195 function _handleDecreaseFontSize ( ) {
196- if ( _adjustFontSize ( - 1 ) ) {
197- PreferencesManager . setViewState ( "fontSizeAdjustment" , PreferencesManager . getViewState ( "fontSizeAdjustment" ) - 1 ) ;
198- }
196+ _adjustFontSize ( - 1 ) ;
199197 }
200198
201199 /** Restores the font size to the original size */
202200 function _handleRestoreFontSize ( ) {
203- _adjustFontSize ( - PreferencesManager . getViewState ( "fontSizeAdjustment" ) ) ;
204- PreferencesManager . setViewState ( "fontSizeAdjustment" , 0 ) ;
201+ _setSizeAndRestoreScroll ( ) ;
202+ PreferencesManager . setViewState ( "fontSizeStyle" , undefined ) ;
203+ PreferencesManager . setViewState ( "lineHeightStyle" , undefined ) ;
205204 }
206205
207206
@@ -230,8 +229,8 @@ define(function (require, exports, module) {
230229 * Restores the Font Size and Line Height using the saved strings
231230 */
232231 function restoreFontSize ( ) {
233- var fsStr = PreferencesManager . getViewState ( "fontSizeString " ) ,
234- lhStr = PreferencesManager . getViewState ( "lineHeightString " ) ;
232+ var fsStr = PreferencesManager . getViewState ( "fontSizeStyle " ) ,
233+ lhStr = PreferencesManager . getViewState ( "lineHeightStyle " ) ;
235234
236235 if ( fsStr && lhStr ) {
237236 _addDynamicFontSize ( fsStr , lhStr ) ;
0 commit comments