Skip to content

Commit 2165c76

Browse files
committed
Reinstate the fixedGutter option
1 parent 8416706 commit 2165c76

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

doc/manual.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ <h2 id="config">Configuration</h2>
222222
names are the keys passed
223223
to <a href="#setGutterMarker"><code>setGutterMarker</code></a>.</dd>
224224

225+
<dt id="option_fixedGutter"><code>fixedGutter (boolean)</code></dt>
226+
<dd>Determines whether the gutter scrolls along with the content
227+
horizontally (false) or whether it stays fixed during horizontal
228+
scrolling (true, the default).</dd>
229+
225230
<dt id="option_readOnly"><code>readOnly (boolean)</code></dt>
226231
<dd>This disables editing of the editor content by the user. If
227232
the special value <code>"nocursor"</code> is given (instead of

lib/codemirror.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,13 +358,14 @@ window.CodeMirror = (function() {
358358

359359
function alignHorizontally(cm) {
360360
var display = cm.display;
361-
if (!display.alignWidgets && !display.gutters.firstChild) return;
361+
if (!display.alignWidgets && (!display.gutters.firstChild || !cm.options.fixedGutter)) return;
362362
var comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.view.scrollLeft;
363363
var gutterW = display.gutters.offsetWidth, l = comp + "px";
364364
for (var n = display.lineDiv.firstChild; n; n = n.nextSibling) if (n.alignable) {
365365
for (var i = 0, a = n.alignable; i < a.length; ++i) a[i].style.left = l;
366366
}
367-
display.gutters.style.left = (comp + gutterW) + "px";
367+
if (cm.options.fixedGutter)
368+
display.gutters.style.left = (comp + gutterW) + "px";
368369
}
369370

370371
function maybeUpdateLineNumberWidth(cm) {
@@ -428,7 +429,8 @@ window.CodeMirror = (function() {
428429

429430
if (changes && maybeUpdateLineNumberWidth(cm))
430431
changes = true;
431-
display.sizer.style.marginLeft = display.scrollbarH.style.left = display.gutters.offsetWidth + "px";
432+
var gutterW = display.sizer.style.marginLeft = display.gutters.offsetWidth + "px";
433+
display.scrollbarH.style.left = cm.options.fixedGutter ? gutterW : "0";
432434

433435
// When merged lines are present, the line that needs to be
434436
// redrawn might not be the one that was changed.
@@ -616,8 +618,8 @@ window.CodeMirror = (function() {
616618
var wrap = elt("div", null, line.wrapClass, "position: relative");
617619
if (cm.options.lineNumbers || markers) {
618620
var gutterWrap = wrap.appendChild(elt("div", null, null, "position: absolute; left: " +
619-
dims.fixedPos + "px"));
620-
wrap.alignable = [gutterWrap];
621+
(cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px"));
622+
if (cm.options.fixedGutter) wrap.alignable = [gutterWrap];
621623
if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"]))
622624
wrap.lineNumber = gutterWrap.appendChild(
623625
elt("div", lineNumberFor(cm.options, lineNo),
@@ -2883,6 +2885,10 @@ window.CodeMirror = (function() {
28832885
setGuttersForLineNumbers(cm.options);
28842886
guttersChanged(cm);
28852887
}, true);
2888+
option("fixedGutter", true, function(cm, val) {
2889+
cm.display.gutters.style.left = val ? compensateForHScroll(cm.display) + "px" : "0";
2890+
cm.refresh();
2891+
}, true);
28862892
option("lineNumbers", false, function(cm) {
28872893
setGuttersForLineNumbers(cm.options);
28882894
guttersChanged(cm);

0 commit comments

Comments
 (0)