From 60c2248cb4cdd80df5f2c3759c641a024e6e7987 Mon Sep 17 00:00:00 2001 From: Logan Ramos Date: Tue, 2 Jul 2019 15:09:30 -0700 Subject: [PATCH] Centers scroll in viewport --- addons/xterm-addon-search/src/SearchAddon.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/addons/xterm-addon-search/src/SearchAddon.ts b/addons/xterm-addon-search/src/SearchAddon.ts index 57f115f8..5c4e28d8 100644 --- a/addons/xterm-addon-search/src/SearchAddon.ts +++ b/addons/xterm-addon-search/src/SearchAddon.ts @@ -4,6 +4,7 @@ */ import { Terminal, IDisposable, ITerminalAddon } from 'xterm'; +import { floor } from 'mathjs'; export interface ISearchOptions { regex?: boolean; @@ -38,7 +39,7 @@ export class SearchAddon implements ITerminalAddon { this._terminal = terminal; } - public dispose(): void {} + public dispose(): void { } /** * Find the next instance of the term, then scroll to and select it. If it @@ -234,7 +235,7 @@ export class SearchAddon implements ITerminalAddon { */ private _isWholeWord(searchIndex: number, line: string, term: string): boolean { return (((searchIndex === 0) || (NON_WORD_CHARACTERS.indexOf(line[searchIndex - 1]) !== -1)) && - (((searchIndex + term.length) === line.length) || (NON_WORD_CHARACTERS.indexOf(line[searchIndex + term.length]) !== -1))); + (((searchIndex + term.length) === line.length) || (NON_WORD_CHARACTERS.indexOf(line[searchIndex + term.length]) !== -1))); } /** @@ -373,7 +374,9 @@ export class SearchAddon implements ITerminalAddon { return false; } terminal.select(result.col, result.row, result.term.length); - terminal.scrollLines(result.row - terminal.buffer.viewportY); + let scroll = result.row - terminal.buffer.viewportY; + scroll = scroll - floor(terminal.rows / 2); + terminal.scrollLines(scroll); return true; } }