From a9d2b8a55c40b4d0b477edba5ef3c7d2f1d9fd4e Mon Sep 17 00:00:00 2001 From: Ken Aoki Date: Sat, 10 Oct 2020 04:04:52 +0000 Subject: [PATCH 1/4] Fix search not expanding selection to left when appropriate --- addons/xterm-addon-search/src/SearchAddon.ts | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/addons/xterm-addon-search/src/SearchAddon.ts b/addons/xterm-addon-search/src/SearchAddon.ts index f5505689..561794e1 100644 --- a/addons/xterm-addon-search/src/SearchAddon.ts +++ b/addons/xterm-addon-search/src/SearchAddon.ts @@ -141,14 +141,14 @@ export class SearchAddon implements ITerminalAddon { const isReverseSearch = true; let startRow = this._terminal.buffer.active.baseY + this._terminal.rows; let startCol = this._terminal.cols; - let result: ISearchResult | undefined; - const incremental = searchOptions ? searchOptions.incremental : false; let currentSelection: ISelectionPosition | undefined; if (this._terminal.hasSelection()) { - currentSelection = this._terminal.getSelectionPosition()!; + const incremental = searchOptions ? searchOptions.incremental : false; // Start from selection start if there is a selection - startRow = currentSelection.startRow; - startCol = currentSelection.startColumn; + // For incremental search, use selection end + currentSelection = this._terminal.getSelectionPosition()!; + startRow = incremental ? currentSelection.endRow : currentSelection.startRow; + startCol = incremental ? currentSelection.endColumn : currentSelection.startColumn; } this._initLinesCache(); @@ -157,14 +157,8 @@ export class SearchAddon implements ITerminalAddon { startCol }; - if (incremental) { - result = this._findInLine(term, searchPosition, searchOptions, false); - if (!(result && result.row === startRow && result.col === startCol)) { - result = this._findInLine(term, searchPosition, searchOptions, true); - } - } else { - result = this._findInLine(term, searchPosition, searchOptions, isReverseSearch); - } + // Search startRow + let result = this._findInLine(term, searchPosition, searchOptions, isReverseSearch); // Search from startRow - 1 to top if (!result) { From b6074df4bf76e996fea449dc718a2122ceeab30a Mon Sep 17 00:00:00 2001 From: Ken Aoki Date: Tue, 13 Oct 2020 06:44:01 +0000 Subject: [PATCH 2/4] Revert "Fix search not expanding selection to left when appropriate" This reverts commit a9d2b8a55c40b4d0b477edba5ef3c7d2f1d9fd4e. --- addons/xterm-addon-search/src/SearchAddon.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/addons/xterm-addon-search/src/SearchAddon.ts b/addons/xterm-addon-search/src/SearchAddon.ts index 561794e1..f5505689 100644 --- a/addons/xterm-addon-search/src/SearchAddon.ts +++ b/addons/xterm-addon-search/src/SearchAddon.ts @@ -141,14 +141,14 @@ export class SearchAddon implements ITerminalAddon { const isReverseSearch = true; let startRow = this._terminal.buffer.active.baseY + this._terminal.rows; let startCol = this._terminal.cols; + let result: ISearchResult | undefined; + const incremental = searchOptions ? searchOptions.incremental : false; let currentSelection: ISelectionPosition | undefined; if (this._terminal.hasSelection()) { - const incremental = searchOptions ? searchOptions.incremental : false; - // Start from selection start if there is a selection - // For incremental search, use selection end currentSelection = this._terminal.getSelectionPosition()!; - startRow = incremental ? currentSelection.endRow : currentSelection.startRow; - startCol = incremental ? currentSelection.endColumn : currentSelection.startColumn; + // Start from selection start if there is a selection + startRow = currentSelection.startRow; + startCol = currentSelection.startColumn; } this._initLinesCache(); @@ -157,8 +157,14 @@ export class SearchAddon implements ITerminalAddon { startCol }; - // Search startRow - let result = this._findInLine(term, searchPosition, searchOptions, isReverseSearch); + if (incremental) { + result = this._findInLine(term, searchPosition, searchOptions, false); + if (!(result && result.row === startRow && result.col === startCol)) { + result = this._findInLine(term, searchPosition, searchOptions, true); + } + } else { + result = this._findInLine(term, searchPosition, searchOptions, isReverseSearch); + } // Search from startRow - 1 to top if (!result) { From d3d8ec3b2018c51f6cbd3ee8b5225d8449d044db Mon Sep 17 00:00:00 2001 From: Ken Aoki Date: Tue, 13 Oct 2020 09:55:10 +0000 Subject: [PATCH 3/4] Fix search not expanding selection to left when appropriate (revenge) --- addons/xterm-addon-search/src/SearchAddon.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/xterm-addon-search/src/SearchAddon.ts b/addons/xterm-addon-search/src/SearchAddon.ts index f5505689..54a4a198 100644 --- a/addons/xterm-addon-search/src/SearchAddon.ts +++ b/addons/xterm-addon-search/src/SearchAddon.ts @@ -158,8 +158,13 @@ export class SearchAddon implements ITerminalAddon { }; if (incremental) { - result = this._findInLine(term, searchPosition, searchOptions, false); + result = this._findInLine(term, searchPosition, searchOptions, false); // Try to expand selection to right first. if (!(result && result.row === startRow && result.col === startCol)) { + // If selection was not able to be expanded to right, then reverse search begin. + if (currentSelection) { + searchPosition.startRow = currentSelection.endRow; + searchPosition.startCol = currentSelection.endColumn; + } result = this._findInLine(term, searchPosition, searchOptions, true); } } else { From 519e44d30e45c86b8c9f27a2e2e49a1bc2ae31b0 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Mon, 11 Jan 2021 09:19:53 -0800 Subject: [PATCH 4/4] Clean up, improve comments Co-authored-by: Megan Rogge --- 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 54a4a198..efc12662 100644 --- a/addons/xterm-addon-search/src/SearchAddon.ts +++ b/addons/xterm-addon-search/src/SearchAddon.ts @@ -158,9 +158,11 @@ export class SearchAddon implements ITerminalAddon { }; if (incremental) { - result = this._findInLine(term, searchPosition, searchOptions, false); // Try to expand selection to right first. - if (!(result && result.row === startRow && result.col === startCol)) { - // If selection was not able to be expanded to right, then reverse search begin. + // Try to expand selection to right first. + result = this._findInLine(term, searchPosition, searchOptions, false); + const isOldResultHighlighted = result && result.row === startRow && result.col === startCol; + if (!isOldResultHighlighted) { + // If selection was not able to be expanded to the right, then try reverse search if (currentSelection) { searchPosition.startRow = currentSelection.endRow; searchPosition.startCol = currentSelection.endColumn; @@ -250,6 +252,7 @@ export class SearchAddon implements ITerminalAddon { * @param term The search term. * @param position The position to start the search. * @param searchOptions Search options. + * @param isReverseSearch Whether the search should start from the right side of the terminal and search to the left. * @return The search result if it was found. */ protected _findInLine(term: string, searchPosition: ISearchPosition, searchOptions: ISearchOptions = {}, isReverseSearch: boolean = false): ISearchResult | undefined {