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

Commit 5aea3d7

Browse files
committed
Merge pull request #7641 from lkcampbell/fix-7283
Fix Issue #7283: Padding with line numbers turned off is broken
2 parents 873cb84 + 129bbd6 commit 5aea3d7

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

src/editor/Editor.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,6 +2033,10 @@ define(function (require, exports, module) {
20332033
} else if (prefName === SCROLL_PAST_END && this._visibleRange) {
20342034
// Do not apply this option to inline editors
20352035
return;
2036+
} else if (prefName === SHOW_LINE_NUMBERS) {
2037+
Editor._toggleLinePadding(!newValue);
2038+
this._codeMirror.setOption(cmOptions[SHOW_LINE_NUMBERS], newValue);
2039+
this.refreshAll();
20362040
} else {
20372041
this._codeMirror.setOption(cmOptions[prefName], newValue);
20382042
}
@@ -2204,6 +2208,16 @@ define(function (require, exports, module) {
22042208
return PreferencesManager.get(WORD_WRAP, fullPath);
22052209
};
22062210

2211+
/**
2212+
* @private
2213+
* Toggles the left padding of all code editors. Used to provide more
2214+
* space between the code text and the left edge of the editor when
2215+
* line numbers are hidden.
2216+
* @param {boolean} showLinePadding
2217+
*/
2218+
Editor._toggleLinePadding = function (showLinePadding) {
2219+
$("#editor-holder").toggleClass("show-line-padding", showLinePadding);
2220+
};
22072221

22082222
// Set up listeners for preference changes
22092223
editorOptions.forEach(function (prefName) {

src/editor/EditorOptionHandlers.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ define(function (require, exports, module) {
9191
_.each(_optionMapping, function (commandName, prefName) {
9292
CommandManager.get(commandName).setChecked(PreferencesManager.get(prefName));
9393
});
94+
95+
if (!Editor.getShowLineNumbers()) {
96+
Editor._toggleLinePadding(true);
97+
}
9498
}
9599

96100
CommandManager.register(Strings.CMD_TOGGLE_LINE_NUMBERS, Commands.TOGGLE_LINE_NUMBERS, _getToggler(SHOW_LINE_NUMBERS));

src/styles/brackets_codemirror_override.less

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
padding: 0 @code-padding 0 0;
2525
}
2626

27+
.show-line-padding .CodeMirror pre {
28+
padding-left: @code-padding;
29+
}
30+
2731
.CodeMirror-scroll {
2832
background-color: @background-color-3;
2933
}
@@ -45,9 +49,15 @@
4549
.CodeMirror-activeline-background {
4650
background: transparent;
4751
}
52+
4853
.CodeMirror-focused .CodeMirror-activeline-background {
4954
background: @activeline-bgcolor;
5055
}
56+
57+
.show-line-padding .CodeMirror-focused .CodeMirror-activeline-background {
58+
box-shadow: inset @code-padding 0 0 0 @activeline-number-bgcolor;
59+
}
60+
5161
.CodeMirror-focused .CodeMirror-activeline {
5262
& > div, .CodeMirror-gutter-elt {
5363
height: 100%;
@@ -228,15 +238,24 @@
228238
.CodeMirror .CodeMirror-activeline-background {
229239
background: transparent;
230240
}
241+
242+
.show-line-padding & .CodeMirror .CodeMirror-activeline-background {
243+
box-shadow: none;
244+
}
245+
231246
.CodeMirror .CodeMirror-activeline .CodeMirror-gutter-elt {
232247
background: transparent;
233248
color: @accent-comment;
234249
}
235-
250+
236251
.CodeMirror-focused .CodeMirror-activeline-background {
237252
background: @activeline-bgcolor;
238253
}
239254

255+
.show-line-padding & .CodeMirror-focused .CodeMirror-activeline-background {
256+
box-shadow: inset @code-padding 0 0 0 @tc-gray-panel-top-bar;
257+
}
258+
240259
.CodeMirror-focused .CodeMirror-activeline {
241260
.CodeMirror-gutter-elt {
242261
background: @tc-gray-panel-top-bar;

0 commit comments

Comments
 (0)