@@ -78,12 +78,6 @@ define(function (require, exports, module) {
7878 */
7979 var LINE_HEIGHT = 1.25 ;
8080
81- /**
82- * @private
83- * @type {boolean }
84- */
85- var _fontSizePrefsLoaded = false ;
86-
8781
8882 /**
8983 * @private
@@ -95,39 +89,44 @@ define(function (require, exports, module) {
9589
9690 /**
9791 * @private
98- * Sets the font size and restores the scroll position as best as possible.
99- * @param {string } fontSizeStyle A string with the font size and the size unit
100- * @param {string } lineHeightStyle A string with the line height and a the size unit
92+ * Add the styles used to update the font size
93+ * @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
10195 */
102- function _setSizeAndRestoreScroll ( fontSizeStyle , lineHeightStyle ) {
103- var editor = EditorManager . getCurrentFullEditor ( ) ,
104- oldWidth = editor . _codeMirror . defaultCharWidth ( ) ,
105- oldHeight = editor . getTextHeight ( ) ,
106- scrollPos = editor . getScrollPos ( ) ;
107-
96+ function _addDynamicFontSize ( fontSizeStyle , lineHeightStyle ) {
10897 // It's necessary to inject a new rule to address all editors.
10998 _removeDynamicFontSize ( ) ;
11099 var style = $ ( "<style type='text/css'></style>" ) . attr ( "id" , DYNAMIC_FONT_STYLE_ID ) ;
111100 style . html ( ".CodeMirror {" +
112101 "font-size: " + fontSizeStyle + " !important;" +
113102 "line-height: " + lineHeightStyle + " !important;}" ) ;
114103 $ ( "head" ) . append ( style ) ;
104+ }
105+
106+ /**
107+ * @private
108+ * 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
111+ */
112+ function _setSizeAndRestoreScroll ( fontSizeStyle , lineHeightStyle ) {
113+ var editor = EditorManager . getCurrentFullEditor ( ) ,
114+ oldWidth = editor . _codeMirror . defaultCharWidth ( ) ,
115+ oldHeight = editor . getTextHeight ( ) ,
116+ scrollPos = editor . getScrollPos ( ) ;
115117
118+ _addDynamicFontSize ( fontSizeStyle , lineHeightStyle ) ;
116119 editor . refreshAll ( ) ;
117120
118- // Scroll the document back to its original position, but not on the first load since the position
119- // was saved with the new height and already been restored.
120- if ( _fontSizePrefsLoaded ) {
121- // Calculate the new scroll based on the old font sizes and scroll position
122- var newWidth = editor . _codeMirror . defaultCharWidth ( ) ,
123- newHeight = editor . getTextHeight ( ) ,
124- deltaX = scrollPos . x / oldWidth ,
125- deltaY = scrollPos . y / oldHeight ,
126- scrollPosX = scrollPos . x + Math . round ( deltaX * ( newWidth - oldWidth ) ) ,
127- scrollPosY = scrollPos . y + Math . round ( deltaY * ( newHeight - oldHeight ) ) ;
121+ // Calculate the new scroll based on the old font sizes and scroll position
122+ var newWidth = editor . _codeMirror . defaultCharWidth ( ) ,
123+ newHeight = editor . getTextHeight ( ) ,
124+ deltaX = scrollPos . x / oldWidth ,
125+ deltaY = scrollPos . y / oldHeight ,
126+ scrollPosX = scrollPos . x + Math . round ( deltaX * ( newWidth - oldWidth ) ) ,
127+ scrollPosY = scrollPos . y + Math . round ( deltaY * ( newHeight - oldHeight ) ) ;
128128
129- editor . setScrollPos ( scrollPosX , scrollPosY ) ;
130- }
129+ editor . setScrollPos ( scrollPosX , scrollPosY ) ;
131130 }
132131
133132 /**
@@ -158,6 +157,7 @@ define(function (require, exports, module) {
158157
159158 var fsNew = fsOld + ( delta * adjustment ) ;
160159 var lhNew = lhOld ;
160+
161161 if ( fsUnits === lhUnits ) {
162162 lhNew = fsNew * LINE_HEIGHT ;
163163 if ( lhUnits === "px" ) {
@@ -177,6 +177,9 @@ define(function (require, exports, module) {
177177
178178 _setSizeAndRestoreScroll ( fsStr , lhStr ) ;
179179
180+ PreferencesManager . setViewState ( "fontSizeString" , fsStr ) ;
181+ PreferencesManager . setViewState ( "lineHeightString" , lhStr ) ;
182+
180183 $ ( exports ) . triggerHandler ( "fontSizeChange" , [ adjustment , fsStr , lhStr ] ) ;
181184 return true ;
182185 }
@@ -215,14 +218,6 @@ define(function (require, exports, module) {
215218 CommandManager . get ( Commands . VIEW_DECREASE_FONT_SIZE ) . setEnabled ( true ) ;
216219 CommandManager . get ( Commands . VIEW_RESTORE_FONT_SIZE ) . setEnabled ( true ) ;
217220 }
218-
219- // Font Size preferences only need to be loaded one time
220- if ( ! _fontSizePrefsLoaded ) {
221- _removeDynamicFontSize ( ) ;
222- _adjustFontSize ( PreferencesManager . getViewState ( "fontSizeAdjustment" ) ) ;
223- _fontSizePrefsLoaded = true ;
224- }
225-
226221 } else {
227222 // No current document so disable all of the Font Size commands
228223 CommandManager . get ( Commands . VIEW_INCREASE_FONT_SIZE ) . setEnabled ( false ) ;
@@ -231,6 +226,18 @@ define(function (require, exports, module) {
231226 }
232227 }
233228
229+ /**
230+ * Restores the Font Size and Line Height using the saved strings
231+ */
232+ function restoreFontSize ( ) {
233+ var fsStr = PreferencesManager . getViewState ( "fontSizeString" ) ,
234+ lhStr = PreferencesManager . getViewState ( "lineHeightString" ) ;
235+
236+ if ( fsStr && lhStr ) {
237+ _addDynamicFontSize ( fsStr , lhStr ) ;
238+ }
239+ }
240+
234241
235242
236243 /**
@@ -336,4 +343,6 @@ define(function (require, exports, module) {
336343
337344 // Update UI when Brackets finishes loading
338345 AppInit . appReady ( _updateUI ) ;
346+
347+ exports . restoreFontSize = restoreFontSize ;
339348} ) ;
0 commit comments