Add test around viewport scrolling behavior

This commit is contained in:
Daniel Imms
2026-05-25 21:00:49 -07:00
parent 9bd72abc59
commit dc01e4e97b
2 changed files with 62 additions and 1 deletions
+15 -1
View File
@@ -99,7 +99,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon, ISearchAp
const nextIndex = this._resolveResultIndex(matches, term, searchOptions, direction, searchKey);
const activeMatch = matches[nextIndex];
terminal.select(activeMatch.startX, activeMatch.startY, activeMatch.cellLength);
terminal.scrollToLine(activeMatch.startY);
this._revealResult(activeMatch);
this._lastResolvedNavigation = {
searchKey,
matches,
@@ -539,6 +539,20 @@ export class SearchAddon extends Disposable implements ITerminalAddon, ISearchAp
return byRow.get(selection.start.y)?.get(selection.start.x) ?? -1;
}
private _revealResult(match: IMatch): void {
const terminal = this._terminal;
if (!terminal) {
return;
}
const viewportTop = terminal.buffer.active.viewportY;
const viewportBottom = viewportTop + terminal.rows - 1;
if (match.startY >= viewportTop && match.endY <= viewportBottom) {
return;
}
const middleY = Math.floor((match.startY + match.endY) / 2);
terminal.scrollToLine(Math.max(0, middleY - Math.floor(terminal.rows / 2)));
}
private _refreshDecorations(matches: IMatch[], decorationOptions: ISearchDecorationOptions, activeMatch: IMatch | undefined): void {
const terminal = this._terminal;
if (!terminal) {