Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: highlight indent guides with wrapped lines #5621

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions src/layer/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ class Text {
var ranges = this.session.$bracketHighlight.ranges;
for (var i = 0; i < ranges.length; i++) {
if (cursor.row !== ranges[i].start.row) {
this.$highlightIndentGuideMarker.end = ranges[i].start.row;
this.$highlightIndentGuideMarker.end = ranges[i].start.row + 1;
if (cursor.row > ranges[i].start.row) {
this.$highlightIndentGuideMarker.dir = -1;
}
Expand Down Expand Up @@ -511,25 +511,25 @@ class Text {
}

$clearActiveIndentGuide() {
var cells = this.$lines.cells;
for (var i = 0; i < cells.length; i++) {
var cell = cells[i];
var childNodes = cell.element.childNodes;
if (childNodes.length > 0) {
for (var j = 0; j < childNodes.length; j++) {
if (childNodes[j].classList && childNodes[j].classList.contains("ace_indent-guide-active")) {
childNodes[j].classList.remove("ace_indent-guide-active");
break;
}
}
}
}
var activeIndentGuides = this.element.querySelectorAll(".ace_indent-guide-active");
activeIndentGuides.forEach(el => {
el.classList.remove("ace_indent-guide-active");
});
}

$setIndentGuideActive(cell, indentLevel) {
var line = this.session.doc.getLine(cell.row);
if (line !== "") {
var childNodes = cell.element.childNodes;
let element = cell.element;
if (cell.element.classList && cell.element.classList.contains("ace_line_group")) {
if (cell.element.childNodes.length > 0) {
element = cell.element.childNodes[0];
}
else {
return;
}
}
var childNodes = element.childNodes;
if (childNodes) {
let node = childNodes[indentLevel - 1];
if (node && node.classList && node.classList.contains("ace_indent-guide")) node.classList.add(
Expand Down Expand Up @@ -558,7 +558,7 @@ class Text {
for (var i = cells.length - 1; i >= 0; i--) {
var cell = cells[i];
if (this.$highlightIndentGuideMarker.end && cell.row < this.$highlightIndentGuideMarker.start) {
if (cell.row <= this.$highlightIndentGuideMarker.end) break;
if (cell.row < this.$highlightIndentGuideMarker.end) break;
this.$setIndentGuideActive(cell, indentLevel);
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/virtual_renderer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,11 @@ module.exports = {
editor._signal("input", {});
assert.equal(editor.renderer.content.textContent, "only visible for empty value");
},
"test: highlight indent guide": function () {
"test: highlight indent guide": function (done) {
editor.session.setValue(
"function Test() {\n" + " function Inner() {\n" + " \n" + " \n" + " }\n" + "}");
editor.setOption("highlightIndentGuides", false);
editor.setOption("wrap", 10); // to make sure higlight works with wrapped lines
editor.session.selection.$setSelection(1, 22, 1, 22);
editor.resize(true);

Expand All @@ -260,6 +261,14 @@ module.exports = {
editor.session.selection.$setSelection(1, 15, 1, 15);
editor.resize(true);
assertIndentGuides( 0);

editor.session.selection.clearSelection();
editor.session.selection.$setSelection(4, 5, 4, 5);

setTimeout(() => {
assertIndentGuides( 2);
done();
}, 100);
},
"test annotation marks": function() {
function findPointFillStyle(imageData, x, y) {
Expand Down