From dcb967bdf6c614c783fbe829ea3e3b1e5cfc82d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Sun, 9 Mar 2014 18:32:48 -0300 Subject: [PATCH 1/5] New preference to be albe to scroll past the end of the file --- src/editor/Editor.js | 43 +++++++++++++++++++++++++------------------ src/index.html | 1 + test/SpecRunner.html | 1 + 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/editor/Editor.js b/src/editor/Editor.js index bd8f8ba6d0d..f6ba7c046f8 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -85,6 +85,7 @@ define(function (require, exports, module) { STYLE_ACTIVE_LINE = "styleActiveLine", WORD_WRAP = "wordWrap", CLOSE_TAGS = "closeTags", + SCROLL_PAST_END = "scrollPastEnd", cmOptions = {}; // Mappings from Brackets preferences to CodeMirror options @@ -97,6 +98,7 @@ define(function (require, exports, module) { cmOptions[STYLE_ACTIVE_LINE] = "styleActiveLine"; cmOptions[WORD_WRAP] = "lineWrapping"; cmOptions[CLOSE_TAGS] = "autoCloseTags"; + cmOptions[SCROLL_PAST_END] = "scrollPastEnd"; PreferencesManager.definePreference(SMART_INDENT, "boolean", true); PreferencesManager.definePreference(USE_TAB_CHAR, "boolean", false); @@ -107,9 +109,9 @@ define(function (require, exports, module) { PreferencesManager.definePreference(STYLE_ACTIVE_LINE, "boolean", false); PreferencesManager.definePreference(WORD_WRAP, "boolean", true); PreferencesManager.definePreference(CLOSE_TAGS, "Object", { whenOpening: true, whenClosing: true, indentTags: [] }); + PreferencesManager.definePreference(SCROLL_PAST_END, "boolean", false); - var editorOptions = [SMART_INDENT, USE_TAB_CHAR, TAB_SIZE, SPACE_UNITS, CLOSE_BRACKETS, - SHOW_LINE_NUMBERS, STYLE_ACTIVE_LINE, WORD_WRAP, CLOSE_TAGS]; + var editorOptions = Object.keys(cmOptions); /** Editor preferences */ @@ -386,22 +388,23 @@ define(function (require, exports, module) { // Create the CodeMirror instance // (note: CodeMirror doesn't actually require using 'new', but jslint complains without it) this._codeMirror = new CodeMirror(container, { - electricChars: false, // we use our own impl of this to avoid CodeMirror bugs; see _checkElectricChars() - smartIndent: currentOptions[SMART_INDENT], - indentWithTabs: currentOptions[USE_TAB_CHAR], - tabSize: currentOptions[TAB_SIZE], - indentUnit: currentOptions[USE_TAB_CHAR] ? currentOptions[TAB_SIZE] : currentOptions[SPACE_UNITS], - lineNumbers: currentOptions[SHOW_LINE_NUMBERS], - lineWrapping: currentOptions[WORD_WRAP], - styleActiveLine: currentOptions[STYLE_ACTIVE_LINE], - coverGutterNextToScrollbar: true, - matchBrackets: true, - matchTags: {bothTags: true}, - dragDrop: false, - extraKeys: codeMirrorKeyMap, - autoCloseBrackets: currentOptions[CLOSE_BRACKETS], - autoCloseTags: currentOptions[CLOSE_TAGS], - cursorScrollMargin: 3 + electricChars : false, // we use our own impl of this to avoid CodeMirror bugs; see _checkElectricChars() + smartIndent : currentOptions[SMART_INDENT], + indentWithTabs : currentOptions[USE_TAB_CHAR], + tabSize : currentOptions[TAB_SIZE], + indentUnit : currentOptions[USE_TAB_CHAR] ? currentOptions[TAB_SIZE] : currentOptions[SPACE_UNITS], + lineNumbers : currentOptions[SHOW_LINE_NUMBERS], + lineWrapping : currentOptions[WORD_WRAP], + styleActiveLine : currentOptions[STYLE_ACTIVE_LINE], + coverGutterNextToScrollbar : true, + matchBrackets : true, + matchTags : { bothTags: true }, + dragDrop : false, + extraKeys : codeMirrorKeyMap, + autoCloseBrackets : currentOptions[CLOSE_BRACKETS], + autoCloseTags : currentOptions[CLOSE_TAGS], + scrollPastEnd : !range ? currentOptions[SCROLL_PAST_END] : false, + cursorScrollMargin : 3 }); // Can't get CodeMirror's focused state without searching for @@ -1572,6 +1575,10 @@ define(function (require, exports, module) { (!useTabChar && prefName === TAB_SIZE)) { return; } + // Do not apply this option to inline editors + if (prefName === SCROLL_PAST_END && this._visibleRange) { + return; + } this._codeMirror.setOption(cmOptions[prefName], newValue); } diff --git a/src/index.html b/src/index.html index 24701b7595d..07e20039f9d 100644 --- a/src/index.html +++ b/src/index.html @@ -55,6 +55,7 @@ + diff --git a/test/SpecRunner.html b/test/SpecRunner.html index 568eae7d9ba..8bb58dbb3a3 100644 --- a/test/SpecRunner.html +++ b/test/SpecRunner.html @@ -40,6 +40,7 @@ + From efdfd901bd7d3672161054799b1bc40ee8d123b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Sun, 9 Mar 2014 18:48:43 -0300 Subject: [PATCH 2/5] Remove unnecesary script --- test/SpecRunner.html | 1 - 1 file changed, 1 deletion(-) diff --git a/test/SpecRunner.html b/test/SpecRunner.html index 8bb58dbb3a3..568eae7d9ba 100644 --- a/test/SpecRunner.html +++ b/test/SpecRunner.html @@ -40,7 +40,6 @@ - From eca77f066265d5f3c20ec4871e69a125f0045ae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Mon, 10 Mar 2014 17:10:18 -0300 Subject: [PATCH 3/5] Changes after initial review --- src/editor/Editor.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/editor/Editor.js b/src/editor/Editor.js index f6ba7c046f8..504298d82f5 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -388,23 +388,23 @@ define(function (require, exports, module) { // Create the CodeMirror instance // (note: CodeMirror doesn't actually require using 'new', but jslint complains without it) this._codeMirror = new CodeMirror(container, { + autoCloseBrackets : currentOptions[CLOSE_BRACKETS], + autoCloseTags : currentOptions[CLOSE_TAGS], + coverGutterNextToScrollbar : true, + cursorScrollMargin : 3, + dragDrop : false, electricChars : false, // we use our own impl of this to avoid CodeMirror bugs; see _checkElectricChars() - smartIndent : currentOptions[SMART_INDENT], - indentWithTabs : currentOptions[USE_TAB_CHAR], - tabSize : currentOptions[TAB_SIZE], + extraKeys : codeMirrorKeyMap, indentUnit : currentOptions[USE_TAB_CHAR] ? currentOptions[TAB_SIZE] : currentOptions[SPACE_UNITS], + indentWithTabs : currentOptions[USE_TAB_CHAR], lineNumbers : currentOptions[SHOW_LINE_NUMBERS], lineWrapping : currentOptions[WORD_WRAP], - styleActiveLine : currentOptions[STYLE_ACTIVE_LINE], - coverGutterNextToScrollbar : true, matchBrackets : true, matchTags : { bothTags: true }, - dragDrop : false, - extraKeys : codeMirrorKeyMap, - autoCloseBrackets : currentOptions[CLOSE_BRACKETS], - autoCloseTags : currentOptions[CLOSE_TAGS], - scrollPastEnd : !range ? currentOptions[SCROLL_PAST_END] : false, - cursorScrollMargin : 3 + scrollPastEnd : !range && currentOptions[SCROLL_PAST_END], + smartIndent : currentOptions[SMART_INDENT], + styleActiveLine : currentOptions[STYLE_ACTIVE_LINE], + tabSize : currentOptions[TAB_SIZE] }); // Can't get CodeMirror's focused state without searching for From c4190aadfbf071c909a21a18900bfea05beafacf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Thu, 13 Mar 2014 20:12:58 -0300 Subject: [PATCH 4/5] Changes after Review --- src/editor/Editor.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/editor/Editor.js b/src/editor/Editor.js index fad179323bc..3fb48ade059 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -1833,6 +1833,7 @@ define(function (require, exports, module) { if (oldValue !== newValue) { this._currentOptions[prefName] = newValue; + var useTabChar = this._currentOptions[USE_TAB_CHAR]; if (prefName === USE_TAB_CHAR) { this._codeMirror.setOption(cmOptions[prefName], newValue); @@ -1842,19 +1843,14 @@ define(function (require, exports, module) { ); } else if (prefName === STYLE_ACTIVE_LINE) { this._updateStyleActiveLine(); - } else { + } else if (prefName === SCROLL_PAST_END && this._visibleRange) { + // Do not apply this option to inline editors + return; + } else if ((useTabChar && prefName === SPACE_UNITS) || (!useTabChar && prefName === TAB_SIZE)) { // Set the CodeMirror option as long as it's not a change // that is in conflict with the useTabChar setting. - var useTabChar = this._currentOptions[USE_TAB_CHAR]; - if ((useTabChar && prefName === SPACE_UNITS) || - (!useTabChar && prefName === TAB_SIZE)) { - return; - } - // Do not apply this option to inline editors - if (prefName === SCROLL_PAST_END && this._visibleRange) { - return; - } - + return; + } else { this._codeMirror.setOption(cmOptions[prefName], newValue); } From b72ae54a6dd1c9ffc69136724d277b5e7b8225c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Thu, 13 Mar 2014 20:39:39 -0300 Subject: [PATCH 5/5] Reverse comment --- src/editor/Editor.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/editor/Editor.js b/src/editor/Editor.js index 3fb48ade059..bf3049365bb 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -1847,8 +1847,7 @@ define(function (require, exports, module) { // Do not apply this option to inline editors return; } else if ((useTabChar && prefName === SPACE_UNITS) || (!useTabChar && prefName === TAB_SIZE)) { - // Set the CodeMirror option as long as it's not a change - // that is in conflict with the useTabChar setting. + // This change conflicts with the useTabChar setting, so do not change the CodeMirror option return; } else { this._codeMirror.setOption(cmOptions[prefName], newValue);