From 24fb49875719dbf72d86e346464c127fea193cb0 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Thu, 24 Mar 2022 07:05:16 -0700 Subject: [PATCH] Don't override decoration positions This also fixes an exception that was throwing where we only allowed links within the terminal's 'rows', which should have been buffer length Fixes #3705 Part of microsoft/vscode#145808 --- addons/xterm-addon-search/src/SearchAddon.ts | 23 ++++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/addons/xterm-addon-search/src/SearchAddon.ts b/addons/xterm-addon-search/src/SearchAddon.ts index 0f677072..a46fb712 100644 --- a/addons/xterm-addon-search/src/SearchAddon.ts +++ b/addons/xterm-addon-search/src/SearchAddon.ts @@ -168,8 +168,8 @@ export class SearchAddon implements ITerminalAddon { this.clearDecorations(); return undefined; } - if (startRow > this._terminal.rows || startCol > this._terminal.cols) { - throw new Error(`Invalid row: ${startRow} or col: ${startCol} to search in terminal with ${this._terminal.rows} rows and ${this._terminal.cols} cols`); + if (startRow > this._terminal.buffer.active.baseY + this._terminal.rows || startCol > this._terminal.cols) { + throw new Error(`Invalid row: ${startRow} or col: ${startCol} to search in terminal with ${this._terminal.buffer.active.baseY + this._terminal.rows} rows and ${this._terminal.cols} cols`); } let result: ISearchResult | undefined = undefined; @@ -604,7 +604,12 @@ export class SearchAddon implements ITerminalAddon { if (decorations?.selectedColor) { const marker = terminal.registerMarker(-terminal.buffer.active.baseY - terminal.buffer.active.cursorY + result.row); if (marker) { - this._selectedDecoration = terminal.registerDecoration({ marker, overviewRulerOptions: { color: decorations.selectedColor } }); + this._selectedDecoration = terminal.registerDecoration({ + marker, + x: result.col, + width: result.size, + overviewRulerOptions: { color: decorations.selectedColor } + }); this._selectedDecoration?.onRender((e) => this._applyStyles(e, decorations.selectedColor, result)); this._selectedDecoration?.onDispose(() => marker.dispose()); } @@ -632,8 +637,6 @@ export class SearchAddon implements ITerminalAddon { } if (!element.classList.contains('xterm-find-result-decoration')) { element.classList.add('xterm-find-result-decoration'); - element.style.left = `${element.clientWidth * result.col}px`; - element.style.width = `${element.clientWidth * result.term.length}px`; element.style.backgroundColor = color; element.style.opacity = '0.6'; } @@ -651,10 +654,12 @@ export class SearchAddon implements ITerminalAddon { if (!marker || !decorations?.matchColor) { return undefined; } - const findResultDecoration = terminal.registerDecoration( - { marker, - overviewRulerOptions: this._resultDecorations.get(marker.line) && !this._dataChanged ? undefined : { color: decorations.matchColor, position: 'center' } - }); + const findResultDecoration = terminal.registerDecoration({ + marker, + x: result.col, + width: result.size, + overviewRulerOptions: this._resultDecorations.get(marker.line) && !this._dataChanged ? undefined : { color: decorations.matchColor, position: 'center' } + }); findResultDecoration?.onRender((e) => this._applyStyles(e, decorations.matchColor, result)); findResultDecoration?.onDispose(() => marker.dispose()); return findResultDecoration;