Skip to content

Commit

Permalink
cleanup matchesContainer method
Browse files Browse the repository at this point in the history
  • Loading branch information
dotcypress committed Dec 12, 2016
1 parent 41ded83 commit 8939040
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions lib/hterm.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ hterm.Terminal.IO.prototype.writeUTF8 = function (string) {
}

runes(string).forEach(rune => {
this.terminal_.getTextAttributes().hasUnicode = containsNonLatinCodepoints(rune);
this.terminal_.getTextAttributes().unicodeNode = containsNonLatinCodepoints(rune);
this.terminal_.interpret(rune);
this.terminal_.getTextAttributes().hasUnicode = false;
this.terminal_.getTextAttributes().unicodeNode = false;
});
};

const oldIsDefault = hterm.TextAttributes.prototype.isDefault;
hterm.TextAttributes.prototype.isDefault = function () {
return !this.hasUnicode && oldIsDefault.call(this);
return !this.unicodeNode && oldIsDefault.call(this);
};

const oldSetFontSize = hterm.Terminal.prototype.setFontSize;
Expand All @@ -146,15 +146,15 @@ hterm.Terminal.prototype.setFontSize = function (px) {
unicodeNodeStyle.innerHTML = `
.unicode-node {
display: inline-block;
max-width: ${this.scrollPort_.characterSize.width}px;
width: ${this.scrollPort_.characterSize.width}px;
}
`;
};

const oldCreateContainer = hterm.TextAttributes.prototype.createContainer;
hterm.TextAttributes.prototype.createContainer = function (text) {
const container = oldCreateContainer.call(this, text);
if (container.style && text.length === 1 && containsNonLatinCodepoints(text)) {
if (container.style && text.length < 2 && containsNonLatinCodepoints(text)) {
container.className += ' unicode-node';
}
return container;
Expand All @@ -163,11 +163,9 @@ hterm.TextAttributes.prototype.createContainer = function (text) {
// Do not match containers when one of them has unicode text (unicode chars need to be alone in their containers)
const oldMatchesContainer = hterm.TextAttributes.prototype.matchesContainer;
hterm.TextAttributes.prototype.matchesContainer = function (obj) {
const content = typeof obj === 'string' ? obj : obj.textContent;
if (this.hasUnicode || containsNonLatinCodepoints(content)) {
return false;
}
return oldMatchesContainer.call(this, obj);
return oldMatchesContainer.call(this, obj) &&
!this.unicodeNode &&
!containsNonLatinCodepoints(obj.textContent);
};

// there's no option to turn off the size overlay
Expand Down

0 comments on commit 8939040

Please sign in to comment.