diff --git a/src/addons/search/SearchHelper.ts b/src/addons/search/SearchHelper.ts index 3537295d..7200539b 100644 --- a/src/addons/search/SearchHelper.ts +++ b/src/addons/search/SearchHelper.ts @@ -60,22 +60,54 @@ export class SearchHelper implements ISearchHelper { // Search from startRow + 1 to end if (!result) { + // A row that has isWrapped = false + let 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. + while (this._terminal._core.buffer.lines.get(findingRow).isWrapped) { + findingRow--; + cumulativeCols += this._terminal.cols; + } + for (let y = startRow + 1; y < this._terminal._core.buffer.ybase + this._terminal.rows; y++) { - result = this._findInLine(term, y, 0, searchOptions); + // Run _findInLine at unwrapped row, scan for cumulativeCols columns + result = this._findInLine(term, findingRow, cumulativeCols, searchOptions); if (result) { break; } + // 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 + if (this._terminal._core.buffer.lines.get(y).isWrapped) { + cumulativeCols += this._terminal.cols; + } else { + cumulativeCols = 0; + findingRow = y; + } } } // Search from the top to the startRow (search the whole startRow again in // case startCol > 0) if (!result) { + // Assume that The first line is always unwrapped line + let findingRow = 0; + // Scan at beginning of the line + let cumulativeCols = 0; for (let y = 0; y <= startRow; y++) { - result = this._findInLine(term, y, 0, searchOptions); + result = this._findInLine(term, findingRow, cumulativeCols, searchOptions); if (result) { break; } + // If the current line is wrapped line, increase index of beginning column + // So we ignore the previous scan + if (this._terminal._core.buffer.lines.get(y).isWrapped) { + cumulativeCols += this._terminal.cols; + } else { + cumulativeCols = 0; + findingRow = y; + } } } @@ -118,11 +150,24 @@ export class SearchHelper implements ISearchHelper { // 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._core.buffer.lines.get(startRow).isWrapped) { + cumulativeCols += startCol; + } for (let y = startRow - 1; y >= 0; y--) { - result = this._findInLine(term, y, this._terminal.cols, searchOptions, isReverseSearch); + result = this._findInLine(term, y, cumulativeCols, searchOptions, isReverseSearch); if (result) { break; } + // If the current line is wrapped line, increase scanning range, + // preparing for scanning on unwrapped line + if (this._terminal._core.buffer.lines.get(y).isWrapped) { + cumulativeCols += this._terminal.cols; + } else { + cumulativeCols = this._terminal.cols; + } } } @@ -130,11 +175,17 @@ export class SearchHelper implements ISearchHelper { // case startCol > 0) if (!result) { const searchFrom = this._terminal._core.buffer.ybase + this._terminal.rows - 1; + let cumulativeCols = this._terminal.cols; for (let y = searchFrom; y >= startRow; y--) { - result = this._findInLine(term, y, this._terminal.cols, searchOptions, isReverseSearch); + result = this._findInLine(term, y, cumulativeCols, searchOptions, isReverseSearch); if (result) { break; } + if (this._terminal._core.buffer.lines.get(y).isWrapped) { + cumulativeCols += this._terminal.cols; + } else { + cumulativeCols = this._terminal.cols; + } } } @@ -188,6 +239,10 @@ export class SearchHelper implements ISearchHelper { */ protected _findInLine(term: string, row: number, col: number, searchOptions: ISearchOptions = {}, isReverseSearch: boolean = false): ISearchResult { + // Ignore wrapped lines, only consider on unwrapped line (first row of command string). + if (this._terminal._core.buffer.lines.get(row).isWrapped) { + return; + } let stringLine = this._linesCache ? this._linesCache[row] : void 0; if (stringLine === void 0) { stringLine = this.translateBufferLineToStringWithWrap(row, true); @@ -219,12 +274,7 @@ export class SearchHelper implements ISearchHelper { } } else { if (isReverseSearch) { - // If the given row has no selection (col is equal to row length), - // lastIndexOf needs to scan at the end of the searchStringLine - if (col === this._terminal.cols) { - resultIndex = searchStringLine.lastIndexOf(searchTerm, col - 1); - } - else if (col - searchTerm.length >= 0) { + if (col - searchTerm.length >= 0) { resultIndex = searchStringLine.lastIndexOf(searchTerm, col - searchTerm.length); } } else {