Skip to content

Commit 77b9fe1

Browse files
authored
Fix: highlight indent guides with wrapped lines (#5621)
* fix: highlight indent guides with wrapped lines * fix: rare cases when indent guide final line was not included to bracketed block * imrove test for highlight indent guide
1 parent 6f05b92 commit 77b9fe1

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

src/layer/text.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ class Text {
481481
var ranges = this.session.$bracketHighlight.ranges;
482482
for (var i = 0; i < ranges.length; i++) {
483483
if (cursor.row !== ranges[i].start.row) {
484-
this.$highlightIndentGuideMarker.end = ranges[i].start.row;
484+
this.$highlightIndentGuideMarker.end = ranges[i].start.row + 1;
485485
if (cursor.row > ranges[i].start.row) {
486486
this.$highlightIndentGuideMarker.dir = -1;
487487
}
@@ -511,25 +511,25 @@ class Text {
511511
}
512512

513513
$clearActiveIndentGuide() {
514-
var cells = this.$lines.cells;
515-
for (var i = 0; i < cells.length; i++) {
516-
var cell = cells[i];
517-
var childNodes = cell.element.childNodes;
518-
if (childNodes.length > 0) {
519-
for (var j = 0; j < childNodes.length; j++) {
520-
if (childNodes[j].classList && childNodes[j].classList.contains("ace_indent-guide-active")) {
521-
childNodes[j].classList.remove("ace_indent-guide-active");
522-
break;
523-
}
524-
}
525-
}
526-
}
514+
var activeIndentGuides = this.element.querySelectorAll(".ace_indent-guide-active");
515+
activeIndentGuides.forEach(el => {
516+
el.classList.remove("ace_indent-guide-active");
517+
});
527518
}
528519

529520
$setIndentGuideActive(cell, indentLevel) {
530521
var line = this.session.doc.getLine(cell.row);
531522
if (line !== "") {
532-
var childNodes = cell.element.childNodes;
523+
let element = cell.element;
524+
if (cell.element.classList && cell.element.classList.contains("ace_line_group")) {
525+
if (cell.element.childNodes.length > 0) {
526+
element = cell.element.childNodes[0];
527+
}
528+
else {
529+
return;
530+
}
531+
}
532+
var childNodes = element.childNodes;
533533
if (childNodes) {
534534
let node = childNodes[indentLevel - 1];
535535
if (node && node.classList && node.classList.contains("ace_indent-guide")) node.classList.add(
@@ -558,7 +558,7 @@ class Text {
558558
for (var i = cells.length - 1; i >= 0; i--) {
559559
var cell = cells[i];
560560
if (this.$highlightIndentGuideMarker.end && cell.row < this.$highlightIndentGuideMarker.start) {
561-
if (cell.row <= this.$highlightIndentGuideMarker.end) break;
561+
if (cell.row < this.$highlightIndentGuideMarker.end) break;
562562
this.$setIndentGuideActive(cell, indentLevel);
563563
}
564564
}

src/virtual_renderer_test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,11 @@ module.exports = {
289289
editor._signal("input", {});
290290
assert.equal(editor.renderer.content.textContent, "only visible for empty value");
291291
},
292-
"test: highlight indent guide": function () {
292+
"test: highlight indent guide": function (done) {
293293
editor.session.setValue(
294294
"function Test() {\n" + " function Inner() {\n" + " \n" + " \n" + " }\n" + "}");
295295
editor.setOption("highlightIndentGuides", false);
296+
editor.setOption("wrap", 10); // to make sure higlight works with wrapped lines
296297
editor.session.selection.$setSelection(1, 22, 1, 22);
297298
editor.resize(true);
298299

@@ -310,6 +311,14 @@ module.exports = {
310311
editor.session.selection.$setSelection(1, 15, 1, 15);
311312
editor.resize(true);
312313
assertIndentGuides( 0);
314+
315+
editor.session.selection.clearSelection();
316+
editor.session.selection.$setSelection(4, 5, 4, 5);
317+
318+
setTimeout(() => {
319+
assertIndentGuides( 2);
320+
done();
321+
}, 100);
313322
},
314323
"test annotation marks": function() {
315324
function findPointFillStyle(imageData, x, y) {

0 commit comments

Comments
 (0)