Skip to content

Commit

Permalink
Merge pull request xtermjs#4651 from jerch/fix_4642
Browse files Browse the repository at this point in the history
fix decorations on DOM renderer
  • Loading branch information
Tyriar authored Aug 9, 2023
2 parents 0224317 + 0366aa2 commit 7276027
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
8 changes: 7 additions & 1 deletion src/browser/renderer/dom/DomRendererRowFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ export class DomRendererRowFactory {
const isCursorCell = isCursorRow && x === cursorX;
const isLinkHover = hasHover && x >= linkStart && x <= linkEnd;

let isDecorated = false;
this._decorationService.forEachDecorationAtCell(x, row, undefined, d => {
isDecorated = true;
});

// get chars to render for this cell
let chars = cell.getChars() || WHITESPACE_CELL_CHAR;
if (chars === ' ' && (cell.isUnderline() || cell.isOverline())) {
Expand Down Expand Up @@ -160,6 +165,7 @@ export class DomRendererRowFactory {
&& spacing === oldSpacing
&& !isCursorCell
&& !isJoined
&& !isDecorated
) {
// no span alterations, thus only account chars skipping all code below
text += chars;
Expand Down Expand Up @@ -386,7 +392,7 @@ export class DomRendererRowFactory {
}

// exclude conditions for cell merging - never merge these
if (!isCursorCell && !isInSelection && !isJoined) {
if (!isCursorCell && !isInSelection && !isJoined && !isDecorated) {
cellAmount++;
} else {
charElement.textContent = text;
Expand Down
45 changes: 24 additions & 21 deletions src/common/SortedList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class SortedList<T> {
this._array.push(value);
return;
}
i = this._search(this._getKey(value), 0, this._array.length - 1);
i = this._search(this._getKey(value));
this._array.splice(i, 0, value);
}

Expand All @@ -40,7 +40,7 @@ export class SortedList<T> {
if (key === undefined) {
return false;
}
i = this._search(key, 0, this._array.length - 1);
i = this._search(key);
if (i === -1) {
return false;
}
Expand All @@ -60,7 +60,7 @@ export class SortedList<T> {
if (this._array.length === 0) {
return;
}
i = this._search(key, 0, this._array.length - 1);
i = this._search(key);
if (i < 0 || i >= this._array.length) {
return;
}
Expand All @@ -76,7 +76,7 @@ export class SortedList<T> {
if (this._array.length === 0) {
return;
}
i = this._search(key, 0, this._array.length - 1);
i = this._search(key);
if (i < 0 || i >= this._array.length) {
return;
}
Expand All @@ -92,23 +92,26 @@ export class SortedList<T> {
return this._array.values();
}

private _search(key: number, min: number, max: number): number {
if (max < min) {
return min;
}
let mid = Math.floor((min + max) / 2);
const midKey = this._getKey(this._array[mid]);
if (midKey > key) {
return this._search(key, min, mid - 1);
}
if (midKey < key) {
return this._search(key, mid + 1, max);
}
// Value found! Since keys can be duplicates, move the result index back to the lowest index
// that matches the key.
while (mid > 0 && this._getKey(this._array[mid - 1]) === key) {
mid--;
private _search(key: number): number {
let min = 0;
let max = this._array.length - 1;
while (max >= min) {
let mid = (min + max) >> 1;
const midKey = this._getKey(this._array[mid]);
if (midKey > key) {
max = mid - 1;
} else if (midKey < key) {
min = mid + 1;
} else {
// key in list, walk to lowest duplicate
while (mid > 0 && this._getKey(this._array[mid - 1]) === key) {
mid--;
}
return mid;
}
}
return mid;
// key not in list
// still return closest min (also used as insert position)
return min;
}
}

0 comments on commit 7276027

Please sign in to comment.