Skip to content

Commit

Permalink
fix: more optimal way to accessing an element's list of classes; mark…
Browse files Browse the repository at this point in the history
… `highlightIndentGuide` as internal property
  • Loading branch information
mkslanc committed Aug 16, 2022
1 parent d4c1ab8 commit 855a874
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
20 changes: 9 additions & 11 deletions src/layer/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,11 @@ var Text = function(parentEl) {
return true;
};

this.highlightIndentGuides = true;
this.$highlightIndentGuides = true;
this.setHighlightIndentGuides = function (highlight) {
if (this.displayIndentGuides === false) return false;
if (this.highlightIndentGuides === highlight) return false;
if (this.$highlightIndentGuides === highlight) return false;

this.highlightIndentGuides = highlight;
this.$highlightIndentGuides = highlight;
return highlight;
};

Expand Down Expand Up @@ -428,7 +427,7 @@ var Text = function(parentEl) {
};

this.$highlightIndentGuide = function () {
if (!this.highlightIndentGuides) return;
if (!this.$highlightIndentGuides || !this.displayIndentGuides) return;

this.$highlightIndentGuideMarker = {
indentLevel: undefined,
Expand Down Expand Up @@ -486,9 +485,9 @@ var Text = function(parentEl) {
var childNodes = cell.element.childNodes;
if (childNodes.length > 0) {
for (var j = 0; j < childNodes.length; j++) {
if (childNodes[j].className && childNodes[j].className.search("ace_indent-guide-active") !== -1) {
childNodes[j].className = childNodes[j].className.replace(
"ace_indent-guide-active", "ace_indent-guide");
if (childNodes[j].classList && childNodes[j].classList.contains("ace_indent-guide-active")) {
childNodes[j].classList.remove("ace_indent-guide-active");
break;
}
}
}
Expand All @@ -499,9 +498,8 @@ var Text = function(parentEl) {
var line = this.session.doc.getLine(cell.row);
if (line !== "") {
var childNodes = cell.element.childNodes;
if (childNodes && childNodes[indentLevel - 1] && childNodes[indentLevel - 1].className) {
childNodes[indentLevel - 1].className = childNodes[indentLevel - 1].className.replace(
"ace_indent-guide", "ace_indent-guide-active");
if (childNodes && childNodes[indentLevel - 1] && childNodes[indentLevel - 1].classList) {
childNodes[indentLevel - 1].classList.add("ace_indent-guide-active");
}
}
};
Expand Down
10 changes: 4 additions & 6 deletions src/virtual_renderer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,22 +200,20 @@ module.exports = {
editor.session.selection.$setSelection(1, 22, 1, 22);
editor.resize(true);

function assertIndentGuides(indentGuidesCount, activeIndentGuidesCount) {
var indentGuides = editor.container.querySelectorAll(".ace_indent-guide");
function assertIndentGuides(activeIndentGuidesCount) {
var activeIndentGuides = editor.container.querySelectorAll(".ace_indent-guide-active");
assert.equal(indentGuides.length, indentGuidesCount);
assert.equal(activeIndentGuides.length, activeIndentGuidesCount);
}

assertIndentGuides(2, 0);
assertIndentGuides( 0);

editor.setOption("highlightIndentGuides", true);
assertIndentGuides(0, 2);
assertIndentGuides( 2);

editor.session.selection.clearSelection();
editor.session.selection.$setSelection(1, 15, 1, 15);
editor.resize(true);
assertIndentGuides(2, 0);
assertIndentGuides( 0);
}

// change tab size after setDocument (for text layer)
Expand Down

0 comments on commit 855a874

Please sign in to comment.