@@ -50,6 +50,7 @@ define(function (require, exports, module) {
5050 PerfUtils = require ( "utils/PerfUtils" ) ,
5151 Editor = require ( "editor/Editor" ) . Editor ,
5252 InlineTextEditor = require ( "editor/InlineTextEditor" ) . InlineTextEditor ,
53+ KeyEvent = require ( "utils/KeyEvent" ) ,
5354 EditorUtils = require ( "editor/EditorUtils" ) ,
5455 ViewUtils = require ( "utils/ViewUtils" ) ,
5556 StatusBar = require ( "widgets/StatusBar" ) ,
@@ -78,9 +79,8 @@ define(function (require, exports, module) {
7879 $cursorInfo ,
7980 $fileInfo ,
8081 $indentType ,
81- $indentWidth ,
82- $indentDecrement ,
83- $indentIncrement ;
82+ $indentWidthLabel ,
83+ $indentWidthInput ;
8484
8585 /**
8686 * Adds keyboard command handlers to an Editor instance.
@@ -587,10 +587,17 @@ define(function (require, exports, module) {
587587 var indentWithTabs = Editor . getUseTabChar ( ) ;
588588 $indentType . text ( indentWithTabs ? Strings . STATUSBAR_TAB_SIZE : Strings . STATUSBAR_SPACES ) ;
589589 $indentType . attr ( "title" , indentWithTabs ? Strings . STATUSBAR_INDENT_TOOLTIP_SPACES : Strings . STATUSBAR_INDENT_TOOLTIP_TABS ) ;
590+ $indentWidthLabel . attr ( "title" , indentWithTabs ? Strings . STATUSBAR_INDENT_SIZE_TOOLTIP_TABS : Strings . STATUSBAR_INDENT_SIZE_TOOLTIP_SPACES ) ;
591+ }
592+
593+ function _getIndentSize ( ) {
594+ return Editor . getUseTabChar ( ) ? Editor . getTabSize ( ) : Editor . getIndentUnit ( ) ;
590595 }
591596
592597 function _updateIndentSize ( ) {
593- $indentWidth . text ( Editor . getUseTabChar ( ) ? Editor . getTabSize ( ) : Editor . getIndentUnit ( ) ) ;
598+ var size = _getIndentSize ( ) ;
599+ $indentWidthLabel . text ( size ) ;
600+ $indentWidthInput . val ( size ) ;
594601 }
595602
596603 function _toggleIndentType ( ) {
@@ -620,18 +627,31 @@ define(function (require, exports, module) {
620627 $cursorInfo . text ( StringUtils . format ( Strings . STATUSBAR_CURSOR_POSITION , ( cursor . line + 1 ) , column + 1 ) ) ;
621628 }
622629
623- function _changeIndentSize ( inc ) {
630+ function _changeIndentWidth ( value ) {
631+ $indentWidthLabel . removeClass ( "hidden" ) ;
632+ $indentWidthInput . addClass ( "hidden" ) ;
633+
634+ // remove all event handlers from the input field
635+ $indentWidthInput . off ( "blur keyup" ) ;
636+
637+ // restore focus to the editor
638+ focusEditor ( ) ;
639+
640+ if ( ! value || isNaN ( value ) ) {
641+ return ;
642+ }
643+
624644 if ( Editor . getUseTabChar ( ) ) {
625- Editor . setTabSize ( Math . max ( Editor . getTabSize ( ) + inc , 1 ) ) ;
645+ Editor . setTabSize ( Math . max ( Math . min ( value , 10 ) , 1 ) ) ;
626646 } else {
627- Editor . setIndentUnit ( Math . max ( Editor . getIndentUnit ( ) + inc , 1 ) ) ;
647+ Editor . setIndentUnit ( Math . max ( Math . min ( value , 10 ) , 1 ) ) ;
628648 }
629649
630650 // update indicator
631651 _updateIndentSize ( ) ;
632652
633653 // column position may change when tab size changes
634- _updateCursorInfo ( null ) ;
654+ _updateCursorInfo ( ) ;
635655 }
636656
637657 function _onFocusedEditorChange ( event , current , previous ) {
@@ -669,14 +689,34 @@ define(function (require, exports, module) {
669689 $cursorInfo = $ ( "#status-cursor" ) ;
670690 $fileInfo = $ ( "#status-file" ) ;
671691 $indentType = $ ( "#indent-type" ) ;
672- $indentWidth = $ ( "#indent-width" ) ;
673- $indentDecrement = $ ( "#indent-decrement" ) ;
674- $indentIncrement = $ ( "#indent-increment" ) ;
692+ $indentWidthLabel = $ ( "#indent-width-label" ) ;
693+ $indentWidthInput = $ ( "#indent-width-input" ) ;
675694
676695 // indentation event handlers
677696 $indentType . on ( "click" , _toggleIndentType ) ;
678- $indentDecrement . on ( "click" , function ( ) { _changeIndentSize ( - 1 ) ; } ) ;
679- $indentIncrement . on ( "click" , function ( ) { _changeIndentSize ( 1 ) ; } ) ;
697+ $indentWidthLabel
698+ . on ( "click" , function ( ) {
699+ // update the input value before displaying
700+ $indentWidthInput . val ( _getIndentSize ( ) ) ;
701+
702+ $indentWidthLabel . addClass ( "hidden" ) ;
703+ $indentWidthInput . removeClass ( "hidden" ) ;
704+ $indentWidthInput . focus ( ) ;
705+
706+ $indentWidthInput
707+ . on ( "blur" , function ( ) {
708+ _changeIndentWidth ( $indentWidthInput . val ( ) ) ;
709+ } )
710+ . on ( "keyup" , function ( event ) {
711+ if ( event . keyCode === KeyEvent . DOM_VK_RETURN ) {
712+ $indentWidthInput . blur ( ) ;
713+ } else if ( event . keyCode === KeyEvent . DOM_VK_ESCAPE ) {
714+ _changeIndentWidth ( false ) ;
715+ }
716+ } ) ;
717+ } ) ;
718+
719+ $indentWidthInput . focus ( function ( ) { $indentWidthInput . select ( ) ; } ) ;
680720
681721 _onFocusedEditorChange ( null , getFocusedEditor ( ) , null ) ;
682722 }
0 commit comments