3030 * Increase Font Size, Decrease Font Size, or Restore Font Size commands.
3131 * The 2nd arg to the listener is the amount of the change. The 3rd arg
3232 * is a string containing the new font size after applying the change.
33- * The 4th arg is a string containing the new line height after applying
34- * the change.
3533 */
3634
3735define ( function ( require , exports , module ) {
@@ -91,31 +89,27 @@ define(function (require, exports, module) {
9189 * @private
9290 * Add the styles used to update the font size
9391 * @param {string } fontSizeStyle A string with the font size and the size unit
94- * @param {string } lineHeightStyle A string with the line height and the size unit
9592 */
96- function _addDynamicFontSize ( fontSizeStyle , lineHeightStyle ) {
93+ function _addDynamicFontSize ( fontSizeStyle ) {
9794 var style = $ ( "<style type='text/css'></style>" ) . attr ( "id" , DYNAMIC_FONT_STYLE_ID ) ;
98- style . html ( ".CodeMirror {" +
99- "font-size: " + fontSizeStyle + " !important;" +
100- "line-height: " + lineHeightStyle + " !important;}" ) ;
95+ style . html ( ".CodeMirror { font-size: " + fontSizeStyle + " !important; }" ) ;
10196 $ ( "head" ) . append ( style ) ;
10297 }
10398
10499 /**
105100 * @private
106101 * Sets the font size and restores the scroll position as best as possible.
107102 * @param {string= } fontSizeStyle A string with the font size and the size unit
108- * @param {string= } lineHeightStyle A string with the line height and the size unit
109103 */
110- function _setSizeAndRestoreScroll ( fontSizeStyle , lineHeightStyle ) {
104+ function _setSizeAndRestoreScroll ( fontSizeStyle ) {
111105 var editor = EditorManager . getCurrentFullEditor ( ) ,
112106 oldWidth = editor . _codeMirror . defaultCharWidth ( ) ,
113107 scrollPos = editor . getScrollPos ( ) ,
114108 line = editor . _codeMirror . lineAtHeight ( scrollPos . y , "local" ) ;
115109
116110 _removeDynamicFontSize ( ) ;
117- if ( fontSizeStyle && lineHeightStyle ) {
118- _addDynamicFontSize ( fontSizeStyle , lineHeightStyle ) ;
111+ if ( fontSizeStyle ) {
112+ _addDynamicFontSize ( fontSizeStyle ) ;
119113 }
120114 editor . refreshAll ( ) ;
121115
@@ -135,51 +129,31 @@ define(function (require, exports, module) {
135129 * @return {boolean } true if adjustment occurred, false if it did not occur
136130 */
137131 function _adjustFontSize ( adjustment ) {
138- var fsStyle = $ ( ".CodeMirror" ) . css ( "font-size" ) ;
139- var lhStyle = $ ( ".CodeMirror" ) . css ( "line-height" ) ;
140-
141- var validFont = / ^ [ \d \. ] + ( p x | e m ) $ / ;
132+ var fsStyle = $ ( ".CodeMirror" ) . css ( "font-size" ) ,
133+ validFont = / ^ [ \d \. ] + ( p x | e m ) $ / ;
142134
143- // Make sure the font size and line height are expressed in terms
144- // we can handle (px or em). If not, simply bail.
145- if ( fsStyle . search ( validFont ) === - 1 || lhStyle . search ( validFont ) === - 1 ) {
135+ // Make sure that the font size is expressed in terms we can handle (px or em). If not, simply bail.
136+ if ( fsStyle . search ( validFont ) === - 1 ) {
146137 return false ;
147138 }
148139
149140 // Guaranteed to work by the validation above.
150- var fsUnits = fsStyle . substring ( fsStyle . length - 2 , fsStyle . length ) ;
151- var lhUnits = lhStyle . substring ( lhStyle . length - 2 , lhStyle . length ) ;
152- var delta = ( fsUnits === "px" ) ? 1 : 0.1 ;
153-
154- var fsOld = parseFloat ( fsStyle . substring ( 0 , fsStyle . length - 2 ) ) ;
155- var lhOld = parseFloat ( lhStyle . substring ( 0 , lhStyle . length - 2 ) ) ;
156-
157- var fsNew = fsOld + ( delta * adjustment ) ;
158- var lhNew = lhOld ;
159-
160- if ( fsUnits === lhUnits ) {
161- lhNew = fsNew * LINE_HEIGHT ;
162- if ( lhUnits === "px" ) {
163- // Use integer px value to avoid rounding differences
164- lhNew = Math . ceil ( lhNew ) ;
165- }
166- }
167-
168- var fsStr = fsNew + fsUnits ;
169- var lhStr = lhNew + lhUnits ;
141+ var fsUnits = fsStyle . substring ( fsStyle . length - 2 , fsStyle . length ) ,
142+ delta = fsUnits === "px" ? 1 : 0.1 ,
143+ fsOld = parseFloat ( fsStyle . substring ( 0 , fsStyle . length - 2 ) ) ,
144+ fsNew = fsOld + ( delta * adjustment ) ,
145+ fsStr = fsNew + fsUnits ;
170146
171147 // Don't let the font size get too small or too large. The minimum font size is 1px or 0.1em
172148 // and the maximum font size is 72px or 7.2em depending on the unit used
173149 if ( fsNew < MIN_FONT_SIZE * delta || fsNew > MAX_FONT_SIZE * delta ) {
174150 return false ;
175151 }
176152
177- _setSizeAndRestoreScroll ( fsStr , lhStr ) ;
178-
179- PreferencesManager . setViewState ( "fontSizeStyle" , fsStr ) ;
180- PreferencesManager . setViewState ( "lineHeightStyle" , lhStr ) ;
153+ _setSizeAndRestoreScroll ( fsStr ) ;
154+ PreferencesManager . setViewState ( "fontSizeStyle" , fsStr ) ;
181155
182- $ ( exports ) . triggerHandler ( "fontSizeChange" , [ adjustment , fsStr , lhStr ] ) ;
156+ $ ( exports ) . triggerHandler ( "fontSizeChange" , [ adjustment , fsStr ] ) ;
183157 return true ;
184158 }
185159
@@ -197,7 +171,6 @@ define(function (require, exports, module) {
197171 function _handleRestoreFontSize ( ) {
198172 _setSizeAndRestoreScroll ( ) ;
199173 PreferencesManager . setViewState ( "fontSizeStyle" ) ;
200- PreferencesManager . setViewState ( "lineHeightStyle" ) ;
201174 }
202175
203176
@@ -226,12 +199,23 @@ define(function (require, exports, module) {
226199 * Restores the Font Size and Line Height using the saved strings
227200 */
228201 function restoreFontSize ( ) {
229- var fsStr = PreferencesManager . getViewState ( "fontSizeStyle" ) ,
230- lhStr = PreferencesManager . getViewState ( "lineHeightStyle" ) ;
231-
232- if ( fsStr && lhStr ) {
202+ var fsStyle = PreferencesManager . getViewState ( "fontSizeStyle" ) ,
203+ fsAdjustment = PreferencesManager . getViewState ( "fontSizeAdjustment" ) ;
204+
205+ if ( fsAdjustment ) {
206+ // Always remove the old view state even if we also have the new view state.
207+ PreferencesManager . setViewState ( "fontSizeAdjustment" ) ;
208+
209+ if ( ! fsStyle ) {
210+ // Migrate the old view state to the new one.
211+ fsStyle = ( 12 + fsAdjustment ) + "px" ;
212+ PreferencesManager . setViewState ( "fontSizeStyle" , fsStyle ) ;
213+ }
214+ }
215+
216+ if ( fsStyle ) {
233217 _removeDynamicFontSize ( ) ;
234- _addDynamicFontSize ( fsStr , lhStr ) ;
218+ _addDynamicFontSize ( fsStyle ) ;
235219 }
236220 }
237221
@@ -334,11 +318,7 @@ define(function (require, exports, module) {
334318 * the old "fontSizeAdjustment" preference.
335319 */
336320 function _convertToNewViewStates ( key , value ) {
337- var fontSize = 12 + value ,
338- newRule = { "fontSizeStyle" : fontSize + "px" ,
339- "lineHeightStyle" : Math . ceil ( fontSize * LINE_HEIGHT ) + "px" } ;
340-
341- return newRule ;
321+ return { "fontSizeStyle" : ( 12 + value ) + "px" } ;
342322 }
343323
344324 // Register command handlers
0 commit comments