Merge pull request #2281 from lramos15/lramos15/centered-scroll

Centers search scroll in viewport
This commit is contained in:
Daniel Imms
2019-07-02 16:03:21 -07:00
committed by GitHub
+5 -3
View File
@@ -38,7 +38,7 @@ export class SearchAddon implements ITerminalAddon {
this._terminal = terminal; this._terminal = terminal;
} }
public dispose(): void {} public dispose(): void { }
/** /**
* Find the next instance of the term, then scroll to and select it. If it * Find the next instance of the term, then scroll to and select it. If it
@@ -234,7 +234,7 @@ export class SearchAddon implements ITerminalAddon {
*/ */
private _isWholeWord(searchIndex: number, line: string, term: string): boolean { private _isWholeWord(searchIndex: number, line: string, term: string): boolean {
return (((searchIndex === 0) || (NON_WORD_CHARACTERS.indexOf(line[searchIndex - 1]) !== -1)) && 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 +373,9 @@ export class SearchAddon implements ITerminalAddon {
return false; return false;
} }
terminal.select(result.col, result.row, result.term.length); 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 - Math.floor(terminal.rows / 2);
terminal.scrollLines(scroll);
return true; return true;
} }
} }