Skip to content

Commit 855a874

Browse files
committed
fix: more optimal way to accessing an element's list of classes; mark highlightIndentGuide as internal property
1 parent d4c1ab8 commit 855a874

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

Diff for: src/layer/text.js

+9-11
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,11 @@ var Text = function(parentEl) {
101101
return true;
102102
};
103103

104-
this.highlightIndentGuides = true;
104+
this.$highlightIndentGuides = true;
105105
this.setHighlightIndentGuides = function (highlight) {
106-
if (this.displayIndentGuides === false) return false;
107-
if (this.highlightIndentGuides === highlight) return false;
106+
if (this.$highlightIndentGuides === highlight) return false;
108107

109-
this.highlightIndentGuides = highlight;
108+
this.$highlightIndentGuides = highlight;
110109
return highlight;
111110
};
112111

@@ -428,7 +427,7 @@ var Text = function(parentEl) {
428427
};
429428

430429
this.$highlightIndentGuide = function () {
431-
if (!this.highlightIndentGuides) return;
430+
if (!this.$highlightIndentGuides || !this.displayIndentGuides) return;
432431

433432
this.$highlightIndentGuideMarker = {
434433
indentLevel: undefined,
@@ -486,9 +485,9 @@ var Text = function(parentEl) {
486485
var childNodes = cell.element.childNodes;
487486
if (childNodes.length > 0) {
488487
for (var j = 0; j < childNodes.length; j++) {
489-
if (childNodes[j].className && childNodes[j].className.search("ace_indent-guide-active") !== -1) {
490-
childNodes[j].className = childNodes[j].className.replace(
491-
"ace_indent-guide-active", "ace_indent-guide");
488+
if (childNodes[j].classList && childNodes[j].classList.contains("ace_indent-guide-active")) {
489+
childNodes[j].classList.remove("ace_indent-guide-active");
490+
break;
492491
}
493492
}
494493
}
@@ -499,9 +498,8 @@ var Text = function(parentEl) {
499498
var line = this.session.doc.getLine(cell.row);
500499
if (line !== "") {
501500
var childNodes = cell.element.childNodes;
502-
if (childNodes && childNodes[indentLevel - 1] && childNodes[indentLevel - 1].className) {
503-
childNodes[indentLevel - 1].className = childNodes[indentLevel - 1].className.replace(
504-
"ace_indent-guide", "ace_indent-guide-active");
501+
if (childNodes && childNodes[indentLevel - 1] && childNodes[indentLevel - 1].classList) {
502+
childNodes[indentLevel - 1].classList.add("ace_indent-guide-active");
505503
}
506504
}
507505
};

Diff for: src/virtual_renderer_test.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -200,22 +200,20 @@ module.exports = {
200200
editor.session.selection.$setSelection(1, 22, 1, 22);
201201
editor.resize(true);
202202

203-
function assertIndentGuides(indentGuidesCount, activeIndentGuidesCount) {
204-
var indentGuides = editor.container.querySelectorAll(".ace_indent-guide");
203+
function assertIndentGuides(activeIndentGuidesCount) {
205204
var activeIndentGuides = editor.container.querySelectorAll(".ace_indent-guide-active");
206-
assert.equal(indentGuides.length, indentGuidesCount);
207205
assert.equal(activeIndentGuides.length, activeIndentGuidesCount);
208206
}
209207

210-
assertIndentGuides(2, 0);
208+
assertIndentGuides( 0);
211209

212210
editor.setOption("highlightIndentGuides", true);
213-
assertIndentGuides(0, 2);
211+
assertIndentGuides( 2);
214212

215213
editor.session.selection.clearSelection();
216214
editor.session.selection.$setSelection(1, 15, 1, 15);
217215
editor.resize(true);
218-
assertIndentGuides(2, 0);
216+
assertIndentGuides( 0);
219217
}
220218

221219
// change tab size after setDocument (for text layer)

0 commit comments

Comments
 (0)