6464define ( function ( require , exports , module ) {
6565 "use strict" ;
6666
67- var CodeMirror = require ( "thirdparty/CodeMirror2/lib/codemirror" ) ,
67+ var AnimationUtils = require ( "utils/AnimationUtils" ) ,
68+ Async = require ( "utils/Async" ) ,
69+ CodeMirror = require ( "thirdparty/CodeMirror2/lib/codemirror" ) ,
6870 Menus = require ( "command/Menus" ) ,
6971 PerfUtils = require ( "utils/PerfUtils" ) ,
7072 PreferencesManager = require ( "preferences/PreferencesManager" ) ,
7173 Strings = require ( "strings" ) ,
7274 TextRange = require ( "document/TextRange" ) . TextRange ,
7375 TokenUtils = require ( "utils/TokenUtils" ) ,
7476 ViewUtils = require ( "utils/ViewUtils" ) ,
75- Async = require ( "utils/Async" ) ,
76- AnimationUtils = require ( "utils/AnimationUtils" ) ,
7777 _ = require ( "thirdparty/lodash" ) ;
7878
7979 /** Editor preferences */
80- var SMART_INDENT = "smartIndent" ,
81- USE_TAB_CHAR = "useTabChar" ,
82- TAB_SIZE = "tabSize" ,
83- SPACE_UNITS = "spaceUnits" ,
84- CLOSE_BRACKETS = "closeBrackets" ,
80+ var CLOSE_BRACKETS = "closeBrackets" ,
81+ CLOSE_TAGS = "closeTags" ,
82+ SCROLL_PAST_END = "scrollPastEnd" ,
8583 SHOW_LINE_NUMBERS = "showLineNumbers" ,
84+ SMART_INDENT = "smartIndent" ,
85+ SOFT_TABS = "softTabs" ,
86+ SPACE_UNITS = "spaceUnits" ,
8687 STYLE_ACTIVE_LINE = "styleActiveLine" ,
88+ TAB_SIZE = "tabSize" ,
8789 WORD_WRAP = "wordWrap" ,
88- CLOSE_TAGS = "closeTags" ,
89- cmOptions = { } ;
90+ USE_TAB_CHAR = "useTabChar" ;
91+
92+ var cmOptions = { } ;
9093
9194 // Mappings from Brackets preferences to CodeMirror options
92- cmOptions [ SMART_INDENT ] = "smartIndent" ;
93- cmOptions [ USE_TAB_CHAR ] = "indentWithTabs" ;
94- cmOptions [ TAB_SIZE ] = "indentUnit" ;
95- cmOptions [ SPACE_UNITS ] = "indentUnit" ;
9695 cmOptions [ CLOSE_BRACKETS ] = "autoCloseBrackets" ;
96+ cmOptions [ CLOSE_TAGS ] = "autoCloseTags" ;
97+ cmOptions [ SCROLL_PAST_END ] = "scrollPastEnd" ;
9798 cmOptions [ SHOW_LINE_NUMBERS ] = "lineNumbers" ;
99+ cmOptions [ SMART_INDENT ] = "smartIndent" ;
100+ cmOptions [ SPACE_UNITS ] = "indentUnit" ;
98101 cmOptions [ STYLE_ACTIVE_LINE ] = "styleActiveLine" ;
102+ cmOptions [ TAB_SIZE ] = "indentUnit" ;
103+ cmOptions [ USE_TAB_CHAR ] = "indentWithTabs" ;
99104 cmOptions [ WORD_WRAP ] = "lineWrapping" ;
100- cmOptions [ CLOSE_TAGS ] = "autoCloseTags" ;
101105
102- PreferencesManager . definePreference ( SMART_INDENT , "boolean" , true ) ;
103- PreferencesManager . definePreference ( USE_TAB_CHAR , "boolean" , false ) ;
104- PreferencesManager . definePreference ( TAB_SIZE , "number" , 4 ) ;
105- PreferencesManager . definePreference ( SPACE_UNITS , "number" , 4 ) ;
106- PreferencesManager . definePreference ( CLOSE_BRACKETS , "boolean" , false ) ;
106+ PreferencesManager . definePreference ( CLOSE_BRACKETS , "boolean" , false ) ;
107+ PreferencesManager . definePreference ( CLOSE_TAGS , "Object" , { whenOpening : true , whenClosing : true , indentTags : [ ] } ) ;
108+ PreferencesManager . definePreference ( SCROLL_PAST_END , "boolean" , false ) ;
107109 PreferencesManager . definePreference ( SHOW_LINE_NUMBERS , "boolean" , true ) ;
110+ PreferencesManager . definePreference ( SMART_INDENT , "boolean" , true ) ;
111+ PreferencesManager . definePreference ( SOFT_TABS , "boolean" , true ) ;
112+ PreferencesManager . definePreference ( SPACE_UNITS , "number" , 4 ) ;
108113 PreferencesManager . definePreference ( STYLE_ACTIVE_LINE , "boolean" , false ) ;
109- PreferencesManager . definePreference ( WORD_WRAP , "boolean" , true ) ;
110- PreferencesManager . definePreference ( CLOSE_TAGS , "Object" , { whenOpening : true , whenClosing : true , indentTags : [ ] } ) ;
114+ PreferencesManager . definePreference ( TAB_SIZE , "number" , 4 ) ;
115+ PreferencesManager . definePreference ( USE_TAB_CHAR , "boolean" , false ) ;
116+ PreferencesManager . definePreference ( WORD_WRAP , "boolean" , true ) ;
111117
112- var editorOptions = [ SMART_INDENT , USE_TAB_CHAR , TAB_SIZE , SPACE_UNITS , CLOSE_BRACKETS ,
113- SHOW_LINE_NUMBERS , STYLE_ACTIVE_LINE , WORD_WRAP , CLOSE_TAGS ] ;
118+ var editorOptions = Object . keys ( cmOptions ) ;
114119
115120 /** Editor preferences */
116121
@@ -231,22 +236,23 @@ define(function (require, exports, module) {
231236 // Create the CodeMirror instance
232237 // (note: CodeMirror doesn't actually require using 'new', but jslint complains without it)
233238 this . _codeMirror = new CodeMirror ( container , {
234- electricChars : false , // we use our own impl of this to avoid CodeMirror bugs; see _checkElectricChars()
235- smartIndent : currentOptions [ SMART_INDENT ] ,
236- indentWithTabs : currentOptions [ USE_TAB_CHAR ] ,
237- tabSize : currentOptions [ TAB_SIZE ] ,
238- indentUnit : currentOptions [ USE_TAB_CHAR ] ? currentOptions [ TAB_SIZE ] : currentOptions [ SPACE_UNITS ] ,
239- lineNumbers : currentOptions [ SHOW_LINE_NUMBERS ] ,
240- lineWrapping : currentOptions [ WORD_WRAP ] ,
241- styleActiveLine : currentOptions [ STYLE_ACTIVE_LINE ] ,
242- coverGutterNextToScrollbar : true ,
243- matchBrackets : true ,
244- matchTags : { bothTags : true } ,
245- dragDrop : false ,
246- extraKeys : codeMirrorKeyMap ,
247- autoCloseBrackets : currentOptions [ CLOSE_BRACKETS ] ,
248- autoCloseTags : currentOptions [ CLOSE_TAGS ] ,
249- cursorScrollMargin : 3
239+ autoCloseBrackets : currentOptions [ CLOSE_BRACKETS ] ,
240+ autoCloseTags : currentOptions [ CLOSE_TAGS ] ,
241+ coverGutterNextToScrollbar : true ,
242+ cursorScrollMargin : 3 ,
243+ dragDrop : false ,
244+ electricChars : false , // we use our own impl of this to avoid CodeMirror bugs; see _checkElectricChars()
245+ extraKeys : codeMirrorKeyMap ,
246+ indentUnit : currentOptions [ USE_TAB_CHAR ] ? currentOptions [ TAB_SIZE ] : currentOptions [ SPACE_UNITS ] ,
247+ indentWithTabs : currentOptions [ USE_TAB_CHAR ] ,
248+ lineNumbers : currentOptions [ SHOW_LINE_NUMBERS ] ,
249+ lineWrapping : currentOptions [ WORD_WRAP ] ,
250+ matchBrackets : true ,
251+ matchTags : { bothTags : true } ,
252+ scrollPastEnd : ! range && currentOptions [ SCROLL_PAST_END ] ,
253+ smartIndent : currentOptions [ SMART_INDENT ] ,
254+ styleActiveLine : currentOptions [ STYLE_ACTIVE_LINE ] ,
255+ tabSize : currentOptions [ TAB_SIZE ]
250256 } ) ;
251257
252258 // Can't get CodeMirror's focused state without searching for
@@ -513,7 +519,7 @@ define(function (require, exports, module) {
513519 var instance = this . _codeMirror ,
514520 overallJump = null ;
515521
516- if ( ! instance . getOption ( "indentWithTabs" ) ) {
522+ if ( ! instance . getOption ( "indentWithTabs" ) && PreferencesManager . get ( SOFT_TABS ) ) {
517523 var indentUnit = instance . getOption ( "indentUnit" ) ;
518524
519525 _ . each ( this . getSelections ( ) , function ( sel ) {
@@ -1154,7 +1160,7 @@ define(function (require, exports, module) {
11541160 * @param {number } centerOptions Option value, or 0 for no options; one of the BOUNDARY_* constants above.
11551161 */
11561162 Editor . prototype . setSelections = function ( selections , center , centerOptions ) {
1157- var primIndex ;
1163+ var primIndex = selections . length - 1 ;
11581164 this . _codeMirror . setSelections ( _ . map ( selections , function ( sel , index ) {
11591165 if ( sel . primary ) {
11601166 primIndex = index ;
@@ -1835,6 +1841,7 @@ define(function (require, exports, module) {
18351841
18361842 if ( oldValue !== newValue ) {
18371843 this . _currentOptions [ prefName ] = newValue ;
1844+ var useTabChar = this . _currentOptions [ USE_TAB_CHAR ] ;
18381845
18391846 if ( prefName === USE_TAB_CHAR ) {
18401847 this . _codeMirror . setOption ( cmOptions [ prefName ] , newValue ) ;
@@ -1844,15 +1851,13 @@ define(function (require, exports, module) {
18441851 ) ;
18451852 } else if ( prefName === STYLE_ACTIVE_LINE ) {
18461853 this . _updateStyleActiveLine ( ) ;
1854+ } else if ( prefName === SCROLL_PAST_END && this . _visibleRange ) {
1855+ // Do not apply this option to inline editors
1856+ return ;
1857+ } else if ( ( useTabChar && prefName === SPACE_UNITS ) || ( ! useTabChar && prefName === TAB_SIZE ) ) {
1858+ // This change conflicts with the useTabChar setting, so do not change the CodeMirror option
1859+ return ;
18471860 } else {
1848- // Set the CodeMirror option as long as it's not a change
1849- // that is in conflict with the useTabChar setting.
1850- var useTabChar = this . _currentOptions [ USE_TAB_CHAR ] ;
1851- if ( ( useTabChar && prefName === SPACE_UNITS ) ||
1852- ( ! useTabChar && prefName === TAB_SIZE ) ) {
1853- return ;
1854- }
1855-
18561861 this . _codeMirror . setOption ( cmOptions [ prefName ] , newValue ) ;
18571862 }
18581863
0 commit comments