From 449ede1d576a72ed36be2e8f19de99be10c36bad Mon Sep 17 00:00:00 2001 From: miguel Date: Mon, 21 Oct 2019 14:55:22 -0400 Subject: [PATCH] Prevent search result from being deselected if it is the only result remove leading whitespace prevent single search term deselection in findPrevious --- addons/xterm-addon-search/src/SearchAddon.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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); }