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 ) {
@@ -878,13 +884,18 @@ define(function (require, exports, module) {
878884 */
879885 Editor . prototype . getColOffset = function ( pos ) {
880886 var line = this . _codeMirror . getRange ( { line : pos . line , ch : 0 } , pos ) ,
881- tabSize = Editor . getTabSize ( ) ,
887+ tabSize = null ,
882888 column = 0 ,
883889 i ;
884890
885891 for ( i = 0 ; i < line . length ; i ++ ) {
886892 if ( line [ i ] === '\t' ) {
887- column += ( tabSize - ( column % tabSize ) ) ;
893+ if ( tabSize === null ) {
894+ tabSize = Editor . getTabSize ( ) ;
895+ }
896+ if ( tabSize > 0 ) {
897+ column += ( tabSize - ( column % tabSize ) ) ;
898+ }
888899 } else {
889900 column ++ ;
890901 }
@@ -1153,7 +1164,7 @@ define(function (require, exports, module) {
11531164 * should be merged with for the purposes of undo. See Document.replaceRange() for more details.
11541165 */
11551166 Editor . prototype . setSelections = function ( selections , center , centerOptions , origin ) {
1156- var primIndex , options ;
1167+ var primIndex = selections . length - 1 , options ;
11571168 if ( origin ) {
11581169 options = { origin : origin } ;
11591170 }
@@ -1837,6 +1848,7 @@ define(function (require, exports, module) {
18371848
18381849 if ( oldValue !== newValue ) {
18391850 this . _currentOptions [ prefName ] = newValue ;
1851+ var useTabChar = this . _currentOptions [ USE_TAB_CHAR ] ;
18401852
18411853 if ( prefName === USE_TAB_CHAR ) {
18421854 this . _codeMirror . setOption ( cmOptions [ prefName ] , newValue ) ;
@@ -1846,15 +1858,13 @@ define(function (require, exports, module) {
18461858 ) ;
18471859 } else if ( prefName === STYLE_ACTIVE_LINE ) {
18481860 this . _updateStyleActiveLine ( ) ;
1861+ } else if ( prefName === SCROLL_PAST_END && this . _visibleRange ) {
1862+ // Do not apply this option to inline editors
1863+ return ;
1864+ } else if ( ( useTabChar && prefName === SPACE_UNITS ) || ( ! useTabChar && prefName === TAB_SIZE ) ) {
1865+ // This change conflicts with the useTabChar setting, so do not change the CodeMirror option
1866+ return ;
18491867 } else {
1850- // Set the CodeMirror option as long as it's not a change
1851- // that is in conflict with the useTabChar setting.
1852- var useTabChar = this . _currentOptions [ USE_TAB_CHAR ] ;
1853- if ( ( useTabChar && prefName === SPACE_UNITS ) ||
1854- ( ! useTabChar && prefName === TAB_SIZE ) ) {
1855- return ;
1856- }
1857-
18581868 this . _codeMirror . setOption ( cmOptions [ prefName ] , newValue ) ;
18591869 }
18601870
0 commit comments