Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit db59b6f

Browse files
committed
Merge pull request #7142 from adobe/tom/scroll-past-end
New preference to be able to scroll past the end of the file
2 parents ed78415 + b72ae54 commit db59b6f

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

src/brackets.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ define(function (require, exports, module) {
5151
require("thirdparty/CodeMirror2/addon/edit/matchbrackets");
5252
require("thirdparty/CodeMirror2/addon/edit/closebrackets");
5353
require("thirdparty/CodeMirror2/addon/edit/closetag");
54+
require("thirdparty/CodeMirror2/addon/scroll/scrollpastend");
5455
require("thirdparty/CodeMirror2/addon/selection/active-line");
5556
require("thirdparty/CodeMirror2/addon/mode/multiplex");
5657
require("thirdparty/CodeMirror2/addon/mode/overlay");

src/editor/Editor.js

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ define(function (require, exports, module) {
8686
STYLE_ACTIVE_LINE = "styleActiveLine",
8787
WORD_WRAP = "wordWrap",
8888
CLOSE_TAGS = "closeTags",
89+
SCROLL_PAST_END = "scrollPastEnd",
8990
cmOptions = {};
9091

9192
// Mappings from Brackets preferences to CodeMirror options
@@ -98,6 +99,7 @@ define(function (require, exports, module) {
9899
cmOptions[STYLE_ACTIVE_LINE] = "styleActiveLine";
99100
cmOptions[WORD_WRAP] = "lineWrapping";
100101
cmOptions[CLOSE_TAGS] = "autoCloseTags";
102+
cmOptions[SCROLL_PAST_END] = "scrollPastEnd";
101103

102104
PreferencesManager.definePreference(SMART_INDENT, "boolean", true);
103105
PreferencesManager.definePreference(USE_TAB_CHAR, "boolean", false);
@@ -108,9 +110,9 @@ define(function (require, exports, module) {
108110
PreferencesManager.definePreference(STYLE_ACTIVE_LINE, "boolean", false);
109111
PreferencesManager.definePreference(WORD_WRAP, "boolean", true);
110112
PreferencesManager.definePreference(CLOSE_TAGS, "Object", { whenOpening: true, whenClosing: true, indentTags: [] });
113+
PreferencesManager.definePreference(SCROLL_PAST_END, "boolean", false);
111114

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];
115+
var editorOptions = Object.keys(cmOptions);
114116

115117
/** Editor preferences */
116118

@@ -231,22 +233,23 @@ define(function (require, exports, module) {
231233
// Create the CodeMirror instance
232234
// (note: CodeMirror doesn't actually require using 'new', but jslint complains without it)
233235
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
236+
autoCloseBrackets : currentOptions[CLOSE_BRACKETS],
237+
autoCloseTags : currentOptions[CLOSE_TAGS],
238+
coverGutterNextToScrollbar : true,
239+
cursorScrollMargin : 3,
240+
dragDrop : false,
241+
electricChars : false, // we use our own impl of this to avoid CodeMirror bugs; see _checkElectricChars()
242+
extraKeys : codeMirrorKeyMap,
243+
indentUnit : currentOptions[USE_TAB_CHAR] ? currentOptions[TAB_SIZE] : currentOptions[SPACE_UNITS],
244+
indentWithTabs : currentOptions[USE_TAB_CHAR],
245+
lineNumbers : currentOptions[SHOW_LINE_NUMBERS],
246+
lineWrapping : currentOptions[WORD_WRAP],
247+
matchBrackets : true,
248+
matchTags : { bothTags: true },
249+
scrollPastEnd : !range && currentOptions[SCROLL_PAST_END],
250+
smartIndent : currentOptions[SMART_INDENT],
251+
styleActiveLine : currentOptions[STYLE_ACTIVE_LINE],
252+
tabSize : currentOptions[TAB_SIZE]
250253
});
251254

252255
// Can't get CodeMirror's focused state without searching for
@@ -1830,6 +1833,7 @@ define(function (require, exports, module) {
18301833

18311834
if (oldValue !== newValue) {
18321835
this._currentOptions[prefName] = newValue;
1836+
var useTabChar = this._currentOptions[USE_TAB_CHAR];
18331837

18341838
if (prefName === USE_TAB_CHAR) {
18351839
this._codeMirror.setOption(cmOptions[prefName], newValue);
@@ -1839,15 +1843,13 @@ define(function (require, exports, module) {
18391843
);
18401844
} else if (prefName === STYLE_ACTIVE_LINE) {
18411845
this._updateStyleActiveLine();
1846+
} else if (prefName === SCROLL_PAST_END && this._visibleRange) {
1847+
// Do not apply this option to inline editors
1848+
return;
1849+
} else if ((useTabChar && prefName === SPACE_UNITS) || (!useTabChar && prefName === TAB_SIZE)) {
1850+
// This change conflicts with the useTabChar setting, so do not change the CodeMirror option
1851+
return;
18421852
} else {
1843-
// Set the CodeMirror option as long as it's not a change
1844-
// that is in conflict with the useTabChar setting.
1845-
var useTabChar = this._currentOptions[USE_TAB_CHAR];
1846-
if ((useTabChar && prefName === SPACE_UNITS) ||
1847-
(!useTabChar && prefName === TAB_SIZE)) {
1848-
return;
1849-
}
1850-
18511853
this._codeMirror.setOption(cmOptions[prefName], newValue);
18521854
}
18531855

0 commit comments

Comments
 (0)