diff --git a/addons/xterm-addon-search/src/SearchAddon.ts b/addons/xterm-addon-search/src/SearchAddon.ts index 5893f79f..3c12e4f1 100644 --- a/addons/xterm-addon-search/src/SearchAddon.ts +++ b/addons/xterm-addon-search/src/SearchAddon.ts @@ -59,12 +59,12 @@ export class SearchAddon implements ITerminalAddon { let startCol = 0; let startRow = 0; - + let currentSelection = null; if (this._terminal.hasSelection()) { const incremental = searchOptions ? searchOptions.incremental : false; // Start from the selection end if there is a selection // For incremental search, use existing row - const currentSelection = this._terminal.getSelectionPosition()!; + currentSelection = this._terminal.getSelectionPosition()!; startRow = incremental ? currentSelection.startRow : currentSelection.endRow; startCol = incremental ? currentSelection.startColumn : currentSelection.endColumn; } @@ -97,6 +97,9 @@ export class SearchAddon implements ITerminalAddon { } } + // If there is only one result, return false. + if (!result && currentSelection) return false; + // Set selection and scroll if a result was found return this._selectResult(result); } @@ -123,8 +126,9 @@ export class SearchAddon implements ITerminalAddon { let startCol = this._terminal.cols; let result: ISearchResult | undefined = undefined; const incremental = searchOptions ? searchOptions.incremental : false; + let currentSelection = null; if (this._terminal.hasSelection()) { - const currentSelection = this._terminal.getSelectionPosition()!; + currentSelection = this._terminal.getSelectionPosition()!; // Start from selection start if there is a selection startRow = currentSelection.startRow; startCol = currentSelection.startColumn; @@ -161,6 +165,9 @@ export class SearchAddon implements ITerminalAddon { } } + // If there is only one result, return false. + if (!result && currentSelection) return false; + // Set selection and scroll if a result was found return this._selectResult(result); }