From cae3d59e2367ea74ac5fe88186b50e4d35b5e79b Mon Sep 17 00:00:00 2001 From: Logan Ramos Date: Wed, 24 Jul 2019 15:09:59 -0700 Subject: [PATCH 1/6] Change search addon behavior --- addons/xterm-addon-search/src/SearchAddon.ts | 65 +++----------------- 1 file changed, 7 insertions(+), 58 deletions(-) diff --git a/addons/xterm-addon-search/src/SearchAddon.ts b/addons/xterm-addon-search/src/SearchAddon.ts index 8fcfc690..054b97cd 100644 --- a/addons/xterm-addon-search/src/SearchAddon.ts +++ b/addons/xterm-addon-search/src/SearchAddon.ts @@ -58,7 +58,7 @@ export class SearchAddon implements ITerminalAddon { } let startCol: number = 0; - let startRow = this._terminal.buffer.viewportY; + let startRow = 0; if (this._terminal.hasSelection()) { const incremental = searchOptions ? searchOptions.incremental : false; @@ -72,16 +72,9 @@ export class SearchAddon implements ITerminalAddon { this._initLinesCache(); // A row that has isWrapped = false - let findingRow = startRow; + const findingRow = startRow; // index of beginning column that _findInLine need to scan. - let cumulativeCols = startCol; - // If startRow is wrapped row, scan for unwrapped row above. - // So we can start matching on wrapped line from long unwrapped line. - let currentLine = this._terminal.buffer.getLine(findingRow); - while (currentLine && currentLine.isWrapped) { - cumulativeCols += this._terminal.cols; - currentLine = this._terminal.buffer.getLine(--findingRow); - } + const cumulativeCols = startCol; // Search startRow let result = this._findInLine(term, findingRow, cumulativeCols, searchOptions); @@ -89,7 +82,7 @@ export class SearchAddon implements ITerminalAddon { // Search from startRow + 1 to end if (!result) { - for (let y = startRow + 1; y < this._terminal.buffer.baseY + this._terminal.rows; y++) { + for (let y = startRow; y < this._terminal.buffer.baseY + this._terminal.rows; y++) { // If the current line is wrapped line, increase index of column to ignore the previous scan // Otherwise, reset beginning column index to zero with set new unwrapped line index @@ -100,17 +93,6 @@ export class SearchAddon implements ITerminalAddon { } } - // Search from the top to the startRow (search the whole startRow again in - // case startCol > 0) - if (!result) { - for (let y = 0; y < findingRow; y++) { - result = this._findInLine(term, y, 0, searchOptions); - if (result) { - break; - } - } - } - // Set selection and scroll if a result was found return this._selectResult(result); } @@ -133,7 +115,7 @@ export class SearchAddon implements ITerminalAddon { } const isReverseSearch = true; - let startRow = this._terminal.buffer.viewportY + this._terminal.rows - 1; + let startRow = this._terminal.buffer.baseY + this._terminal.rows; let startCol = this._terminal.cols; if (this._terminal.hasSelection()) { @@ -150,44 +132,11 @@ export class SearchAddon implements ITerminalAddon { // Search from startRow - 1 to top if (!result) { - // If the line is wrapped line, increase number of columns that is needed to be scanned - // Se we can scan on wrapped line from unwrapped line - let cumulativeCols = this._terminal.cols; - if (this._terminal.buffer.getLine(startRow)!.isWrapped) { - cumulativeCols += startCol; - } - for (let y = startRow - 1; y >= 0; y--) { - result = this._findInLine(term, y, cumulativeCols, searchOptions, isReverseSearch); + for (let y = startRow; y >= 0; y--) { + result = this._findInLine(term, y, startCol, searchOptions, isReverseSearch); if (result) { break; } - // If the current line is wrapped line, increase scanning range, - // preparing for scanning on unwrapped line - const line = this._terminal.buffer.getLine(y); - if (line && line.isWrapped) { - cumulativeCols += this._terminal.cols; - } else { - cumulativeCols = this._terminal.cols; - } - } - } - - // Search from the bottom to startRow (search the whole startRow again in - // case startCol > 0) - if (!result) { - const searchFrom = this._terminal.buffer.baseY + this._terminal.rows - 1; - let cumulativeCols = this._terminal.cols; - for (let y = searchFrom; y >= startRow; y--) { - result = this._findInLine(term, y, cumulativeCols, searchOptions, isReverseSearch); - if (result) { - break; - } - const line = this._terminal.buffer.getLine(y); - if (line && line.isWrapped) { - cumulativeCols += this._terminal.cols; - } else { - cumulativeCols = this._terminal.cols; - } } } From f3f52e6920dba1fef5f27d5740ac0dcc3d8861d6 Mon Sep 17 00:00:00 2001 From: Logan Ramos Date: Wed, 24 Jul 2019 15:30:09 -0700 Subject: [PATCH 2/6] Changed default Search Addon behavior --- addons/xterm-addon-search/src/SearchAddon.ts | 23 ++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/addons/xterm-addon-search/src/SearchAddon.ts b/addons/xterm-addon-search/src/SearchAddon.ts index 054b97cd..bd962ee5 100644 --- a/addons/xterm-addon-search/src/SearchAddon.ts +++ b/addons/xterm-addon-search/src/SearchAddon.ts @@ -82,7 +82,7 @@ export class SearchAddon implements ITerminalAddon { // Search from startRow + 1 to end if (!result) { - for (let y = startRow; y < this._terminal.buffer.baseY + this._terminal.rows; y++) { + for (let y = startRow + 1; y < this._terminal.buffer.baseY + this._terminal.rows; y++) { // If the current line is wrapped line, increase index of column to ignore the previous scan // Otherwise, reset beginning column index to zero with set new unwrapped line index @@ -92,6 +92,15 @@ export class SearchAddon implements ITerminalAddon { } } } + // If we hit the bottom and didn't search from the very top wrap back up + if (!result && startRow !== 0) { + for (let y = 0; y < startRow; y++) { + result = this._findInLine(term, y, 0, searchOptions); + if (result) { + break; + } + } + } // Set selection and scroll if a result was found return this._selectResult(result); @@ -132,7 +141,17 @@ export class SearchAddon implements ITerminalAddon { // Search from startRow - 1 to top if (!result) { - for (let y = startRow; y >= 0; y--) { + startCol = this._terminal.cols; + for (let y = startRow - 1; y >= 0; y--) { + result = this._findInLine(term, y, startCol, searchOptions, isReverseSearch); + if (result) { + break; + } + } + } + // If we hit the top and didn't search from the very bottom wrap back down + if (!result && startRow !== (this._terminal.buffer.baseY + this._terminal.rows)) { + for (let y = (this._terminal.buffer.baseY + this._terminal.rows); y > startRow; y--) { result = this._findInLine(term, y, startCol, searchOptions, isReverseSearch); if (result) { break; From d104f39a9d886413f6d05d890222838ddf0cb8bb Mon Sep 17 00:00:00 2001 From: Logan Ramos Date: Wed, 24 Jul 2019 16:01:07 -0700 Subject: [PATCH 3/6] Incremental previous search --- addons/xterm-addon-search/src/SearchAddon.ts | 7 ++++--- demo/client.ts | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) 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. From db936701f48e30871a2b8af711664a311214b2cf Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Wed, 24 Jul 2019 16:09:57 -0700 Subject: [PATCH 4/6] Include incremental in getSearchOptions --- demo/client.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/demo/client.ts b/demo/client.ts index 104fa49a..040292e4 100644 --- a/demo/client.ts +++ b/demo/client.ts @@ -58,11 +58,12 @@ function setPadding(): void { term.fit(); } -function getSearchOptions(): ISearchOptions { +function getSearchOptions(e: KeyboardEvent): ISearchOptions { return { regex: (document.getElementById('regex') as HTMLInputElement).checked, wholeWord: (document.getElementById('whole-word') as HTMLInputElement).checked, - caseSensitive: (document.getElementById('case-sensitive') as HTMLInputElement).checked + caseSensitive: (document.getElementById('case-sensitive') as HTMLInputElement).checked, + incremental: e.key !== `Enter` }; } @@ -134,15 +135,11 @@ function createTerminal(): void { addDomListener(paddingElement, 'change', setPadding); addDomListener(actionElements.findNext, 'keyup', (e) => { - const searchOptions = getSearchOptions(); - searchOptions.incremental = e.key !== `Enter`; - searchAddon.findNext(actionElements.findNext.value, searchOptions); + searchAddon.findNext(actionElements.findNext.value, getSearchOptions(e)); }); addDomListener(actionElements.findPrevious, 'keyup', (e) => { - const searchOptions = getSearchOptions(); - searchOptions.incremental = e.key !== `Enter`; - searchAddon.findPrevious(actionElements.findPrevious.value, searchOptions); + searchAddon.findPrevious(actionElements.findPrevious.value, getSearchOptions(e)); }); // fit is called within a setTimeout, cols and rows need this. From ea72a3b594c2d67da0b3d4b1f1c485ab8cd57e39 Mon Sep 17 00:00:00 2001 From: Logan Ramos Date: Thu, 25 Jul 2019 08:50:37 -0700 Subject: [PATCH 5/6] Fix incremental search bug --- addons/xterm-addon-search/src/SearchAddon.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/addons/xterm-addon-search/src/SearchAddon.ts b/addons/xterm-addon-search/src/SearchAddon.ts index b3b430a5..2b8c4234 100644 --- a/addons/xterm-addon-search/src/SearchAddon.ts +++ b/addons/xterm-addon-search/src/SearchAddon.ts @@ -137,8 +137,14 @@ export class SearchAddon implements ITerminalAddon { this._initLinesCache(); - // Search startRow - result = incremental ? this._findInLine(term, startRow, startCol, searchOptions, false) : this._findInLine(term, startRow, startCol, searchOptions, isReverseSearch); + if (incremental) { + result = this._findInLine(term, startRow, startCol, searchOptions, false); + if (!(result && result.row === startRow && result.col === startCol)) { + result = this._findInLine(term, startRow, startCol, searchOptions, true); + } + } else { + result = this._findInLine(term, startRow, startCol, searchOptions, isReverseSearch); + } // Search from startRow - 1 to top if (!result) { From a1be1f0b3564b02171b8fa444d38c39d35868df8 Mon Sep 17 00:00:00 2001 From: Logan Ramos Date: Thu, 25 Jul 2019 09:02:32 -0700 Subject: [PATCH 6/6] Code cleanup --- addons/xterm-addon-search/src/SearchAddon.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/addons/xterm-addon-search/src/SearchAddon.ts b/addons/xterm-addon-search/src/SearchAddon.ts index 2b8c4234..e9f8a9b4 100644 --- a/addons/xterm-addon-search/src/SearchAddon.ts +++ b/addons/xterm-addon-search/src/SearchAddon.ts @@ -57,7 +57,7 @@ export class SearchAddon implements ITerminalAddon { return false; } - let startCol: number = 0; + let startCol = 0; let startRow = 0; if (this._terminal.hasSelection()) { @@ -71,13 +71,8 @@ export class SearchAddon implements ITerminalAddon { this._initLinesCache(); - // A row that has isWrapped = false - const findingRow = startRow; - // index of beginning column that _findInLine need to scan. - const cumulativeCols = startCol; - // Search startRow - let result = this._findInLine(term, findingRow, cumulativeCols, searchOptions); + let result = this._findInLine(term, startRow, startCol, searchOptions); // Search from startRow + 1 to end if (!result) {