Skip to content

Commit

Permalink
fix: add mock getHighlightIndentGuides and `setHighlightIndentGuide…
Browse files Browse the repository at this point in the history
…s` for old tests to work
  • Loading branch information
mkslanc committed Aug 12, 2022
1 parent f1f6517 commit 4067512
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 28 deletions.
57 changes: 29 additions & 28 deletions src/layer/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var Lines = require("./lines").Lines;
var EventEmitter = require("../lib/event_emitter").EventEmitter;

var Text = function(parentEl) {
this.dom = dom;
this.dom = dom;
this.element = this.dom.createElement("div");
this.element.className = "ace_layer ace_text-layer";
parentEl.appendChild(this.element);
Expand Down Expand Up @@ -50,7 +50,7 @@ var Text = function(parentEl) {
this.getCharacterWidth = function() {
return this.$fontMetrics.$characterSize.width || 0;
};

this.$setFontMetrics = function(measure) {
this.$fontMetrics = measure;
this.$fontMetrics.on("changeCharacterSize", function(e) {
Expand Down Expand Up @@ -135,15 +135,15 @@ var Text = function(parentEl) {
: lang.stringRepeat(" ", this.tabSize);

var tabClass = this.showTabs ? " ace_invisible ace_invisible_tab" : "";
var tabContent = this.showTabs
var tabContent = this.showTabs
? lang.stringRepeat(this.TAB_CHAR, this.tabSize)
: spaceContent;

var span = this.dom.createElement("span");
span.className = className + spaceClass;
span.textContent = spaceContent;
this.$tabStrings[" "] = span;

var span = this.dom.createElement("span");
span.className = className + tabClass;
span.textContent = tabContent;
Expand All @@ -158,7 +158,7 @@ var Text = function(parentEl) {
this.config.firstRow != config.firstRow) {
return this.update(config);
}

this.config = config;

var first = Math.max(firstRow, config.firstRow);
Expand Down Expand Up @@ -226,9 +226,9 @@ var Text = function(parentEl) {

if (this.$lines.pageChanged(oldConfig, config))
return this.update(config);

this.$lines.moveContainer(config);

var lastRow = config.lastRow;
var oldLastRow = oldConfig ? oldConfig.lastRow : -1;

Expand Down Expand Up @@ -278,7 +278,7 @@ var Text = function(parentEl) {
break;

var line = this.$lines.createCell(row, config, this.session);

var lineEl = line.element;
this.dom.removeChildren(lineEl);
dom.setStyle(lineEl.style, "height", this.$lines.computeLineHeight(row, config, this.session) + "px");
Expand All @@ -302,7 +302,7 @@ var Text = function(parentEl) {

this.update = function(config) {
this.$lines.moveContainer(config);

this.config = config;

var firstRow = config.firstRow;
Expand All @@ -311,7 +311,7 @@ var Text = function(parentEl) {
var lines = this.$lines;
while (lines.getLength())
lines.pop();

lines.push(this.$renderLinesFragment(config, firstRow, lastRow));
};

Expand All @@ -324,7 +324,7 @@ var Text = function(parentEl) {
this.$renderToken = function(parent, screenColumn, token, value) {
var self = this;
var re = /(\t)|( +)|([\x00-\x1f\x80-\xa0\xad\u1680\u180E\u2000-\u200f\u2028\u2029\u202F\u205F\uFEFF\uFFF9-\uFFFC\u2066\u2067\u2068\u202A\u202B\u202D\u202E\u202C\u2069]+)|(\u3000)|([\u1100-\u115F\u11A3-\u11A7\u11FA-\u11FF\u2329-\u232A\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u2FF0-\u2FFB\u3001-\u303E\u3041-\u3096\u3099-\u30FF\u3105-\u312D\u3131-\u318E\u3190-\u31BA\u31C0-\u31E3\u31F0-\u321E\u3220-\u3247\u3250-\u32FE\u3300-\u4DBF\u4E00-\uA48C\uA490-\uA4C6\uA960-\uA97C\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFAFF\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE66\uFE68-\uFE6B\uFF01-\uFF60\uFFE0-\uFFE6]|[\uD800-\uDBFF][\uDC00-\uDFFF])/g;

var valueFragment = this.dom.createFragment(this.element);

var m;
Expand All @@ -335,18 +335,18 @@ var Text = function(parentEl) {
var controlCharacter = m[3];
var cjkSpace = m[4];
var cjk = m[5];

if (!self.showSpaces && simpleSpace)
continue;

var before = i != m.index ? value.slice(i, m.index) : "";

i = m.index + m[0].length;

if (before) {
valueFragment.appendChild(this.dom.createTextNode(before, this.element));
}

if (tab) {
var tabSize = self.session.getScreenTabSize(screenColumn + m.index);
valueFragment.appendChild(self.$tabStrings[tabSize].cloneNode(true));
Expand All @@ -368,7 +368,7 @@ var Text = function(parentEl) {
} else if (cjkSpace) {
// U+3000 is both invisible AND full-width, so must be handled uniquely
screenColumn += 1;

var span = this.dom.createElement("span");
span.style.width = (self.config.characterWidth * 2) + "px";
span.className = self.showSpaces ? "ace_cjk ace_invisible ace_invisible_space" : "ace_cjk";
Expand All @@ -383,24 +383,24 @@ var Text = function(parentEl) {
valueFragment.appendChild(span);
}
}

valueFragment.appendChild(this.dom.createTextNode(i ? value.slice(i) : value, this.element));

if (!this.$textToken[token.type]) {
var classes = "ace_" + token.type.replace(/\./g, " ace_");
var span = this.dom.createElement("span");
if (token.type == "fold")
span.style.width = (token.value.length * this.config.characterWidth) + "px";

span.className = classes;
span.appendChild(valueFragment);

parent.appendChild(span);
}
else {
parent.appendChild(valueFragment);
}

return screenColumn + value.length;
};

Expand Down Expand Up @@ -504,9 +504,10 @@ var Text = function(parentEl) {
"ace_indent-guide", "ace_indent-guide-active");
}
}
}
};

this.$renderHighlightIndentGuide = function () {
if (!this.$lines) return;
var cells = this.$lines.cells;
this.$clearActiveIndentGuide();
var indentLevel = this.$highlightIndentGuideMarker.indentLevel;
Expand Down Expand Up @@ -537,7 +538,7 @@ var Text = function(parentEl) {
var lineEl = this.dom.createElement("div");
lineEl.className = "ace_line";
lineEl.style.height = this.config.lineHeight + "px";

return lineEl;
};

Expand All @@ -549,7 +550,7 @@ var Text = function(parentEl) {

var lineEl = this.$createLineElement();
parent.appendChild(lineEl);

for (var i = 0; i < tokens.length; i++) {
var token = tokens[i];
var value = token.value;
Expand Down Expand Up @@ -590,7 +591,7 @@ var Text = function(parentEl) {
}
}
}

if (splits[splits.length - 1] > this.MAX_LINE_LENGTH)
this.$renderOverflowMessage(lineEl, screenColumn, null, "", true);
};
Expand All @@ -611,16 +612,16 @@ var Text = function(parentEl) {
screenColumn = this.$renderToken(parent, screenColumn, token, value);
}
};

this.$renderOverflowMessage = function(parent, screenColumn, token, value, hide) {
token && this.$renderToken(parent, screenColumn, token,
value.slice(0, this.MAX_LINE_LENGTH - screenColumn));

var overflowEl = this.dom.createElement("span");
overflowEl.className = "ace_inline_button ace_keyword ace_toggle_wrap";
overflowEl.textContent = hide ? "<hide>" : "<click to see more...>";
parent.appendChild(overflowEl);

parent.appendChild(overflowEl);
};

// row is either first row of foldline or not in fold
Expand Down Expand Up @@ -659,7 +660,7 @@ var Text = function(parentEl) {
var invisibleEl = this.dom.createElement("span");
invisibleEl.className = "ace_invisible ace_invisible_eol";
invisibleEl.textContent = row == this.session.getLength() - 1 ? this.EOF_CHAR : this.EOL_CHAR;

lastLineEl.appendChild(invisibleEl);
}
};
Expand Down
6 changes: 6 additions & 0 deletions src/test/mockrenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,9 @@ MockRenderer.prototype.screenToTextCoordinates = function() {
MockRenderer.prototype.adjustWrapLimit = function () {

};

MockRenderer.prototype.getHighlightIndentGuides = function() {
};

MockRenderer.prototype.setHighlightIndentGuides = function() {
};

0 comments on commit 4067512

Please sign in to comment.