@@ -197,6 +197,22 @@ export default class SettingsPanel extends CollapsibleSectionPanel {
197197 }
198198 }
199199
200+ setText ( editor , name , type , value ) {
201+ let stringValue
202+ if ( this . isDefault ( name ) ) {
203+ stringValue = ''
204+ } else {
205+ stringValue = this . valueToString ( value ) || ''
206+ }
207+
208+ if ( stringValue === editor . getText ( ) || _ . isEqual ( value , this . parseValue ( type , editor . getText ( ) ) ) ) {
209+ return
210+ }
211+
212+ editor . setText ( stringValue )
213+ editor . moveToEndOfLine ( )
214+ }
215+
200216 bindSelectFields ( ) {
201217 const disposables = Array . from ( this . element . querySelectorAll ( 'select[id]' ) ) . map ( ( select ) => {
202218 const name = select . id
@@ -213,7 +229,6 @@ export default class SettingsPanel extends CollapsibleSectionPanel {
213229
214230 bindEditors ( ) {
215231 const disposables = Array . from ( this . element . querySelectorAll ( 'atom-text-editor' ) ) . map ( ( editorElement ) => {
216- let left
217232 let editor = editorElement . getModel ( )
218233 let name = editorElement . id
219234 let type = editorElement . getAttribute ( 'type' )
@@ -242,22 +257,21 @@ export default class SettingsPanel extends CollapsibleSectionPanel {
242257 subscriptions . add ( new Disposable ( ( ) => editorElement . removeEventListener ( 'blur' , blurHandler ) ) )
243258
244259 this . observe ( name , ( value ) => {
245- let stringValue
246- if ( this . isDefault ( name ) ) {
247- stringValue = ''
248- } else {
249- stringValue = ( left = this . valueToString ( value ) ) != null ? left : ''
250- }
251-
252- if ( stringValue === editor . getText ( ) || _ . isEqual ( value , this . parseValue ( type , editor . getText ( ) ) ) ) {
253- return
254- }
255-
256- editor . setText ( stringValue )
260+ this . setText ( editor , name , type , value )
257261 } )
258262
259263 subscriptions . add ( editor . onDidStopChanging ( ( ) => {
260- this . set ( name , this . parseValue ( type , editor . getText ( ) ) )
264+ const { minimum, maximum} = atom . config . getSchema ( name )
265+ const value = this . parseValue ( type , editor . getText ( ) )
266+ if ( minimum != null && value < minimum ) {
267+ this . set ( name , minimum )
268+ this . setText ( editor , name , type , minimum )
269+ } else if ( maximum != null && value > maximum ) {
270+ this . set ( name , maximum )
271+ this . setText ( editor , name , type , maximum )
272+ } else if ( ! this . set ( name , value ) ) {
273+ this . setText ( editor , name , type , atom . config . get ( name ) )
274+ }
261275 } ) )
262276
263277 return subscriptions
0 commit comments