diff --git a/addons/xterm-addon-search/src/SearchAddon.ts b/addons/xterm-addon-search/src/SearchAddon.ts index bd962ee5..b3b430a5 100644 --- a/addons/xterm-addon-search/src/SearchAddon.ts +++ b/addons/xterm-addon-search/src/SearchAddon.ts @@ -126,10 +126,11 @@ export class SearchAddon implements ITerminalAddon { const isReverseSearch = true; let startRow = this._terminal.buffer.baseY + this._terminal.rows; let startCol = this._terminal.cols; - + let result: ISearchResult | undefined = undefined; + const incremental = searchOptions ? searchOptions.incremental : false; if (this._terminal.hasSelection()) { - // Start from the selection start if there is a selection const currentSelection = this._terminal.getSelectionPosition()!; + // Start from selection start if there is a selection startRow = currentSelection.startRow; startCol = currentSelection.startColumn; } @@ -137,7 +138,7 @@ export class SearchAddon implements ITerminalAddon { this._initLinesCache(); // Search startRow - let result = this._findInLine(term, startRow, startCol, searchOptions, isReverseSearch); + result = incremental ? this._findInLine(term, startRow, startCol, searchOptions, false) : this._findInLine(term, startRow, startCol, searchOptions, isReverseSearch); // Search from startRow - 1 to top if (!result) { diff --git a/demo/client.ts b/demo/client.ts index a28a720c..104fa49a 100644 --- a/demo/client.ts +++ b/demo/client.ts @@ -140,9 +140,9 @@ function createTerminal(): void { }); addDomListener(actionElements.findPrevious, 'keyup', (e) => { - if (e.key === `Enter`) { - searchAddon.findPrevious(actionElements.findPrevious.value, getSearchOptions()); - } + const searchOptions = getSearchOptions(); + searchOptions.incremental = e.key !== `Enter`; + searchAddon.findPrevious(actionElements.findPrevious.value, searchOptions); }); // fit is called within a setTimeout, cols and rows need this.