Fix incremental
This commit is contained in:
@@ -220,24 +220,22 @@ export class SearchAddon extends Disposable implements ITerminalAddon {
|
|||||||
if (!this._terminal || !term || term.length === 0) {
|
if (!this._terminal || !term || term.length === 0) {
|
||||||
this._terminal?.clearSelection();
|
this._terminal?.clearSelection();
|
||||||
this.clearDecorations();
|
this.clearDecorations();
|
||||||
this._cachedSearchTerm = undefined;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._cachedSearchTerm !== term) {
|
const prevSelectedPos = this._terminal.getSelectionPosition();
|
||||||
this._terminal.clearSelection();
|
this._terminal.clearSelection();
|
||||||
}
|
|
||||||
|
|
||||||
let startCol = 0;
|
let startCol = 0;
|
||||||
let startRow = 0;
|
let startRow = 0;
|
||||||
let currentSelection: IBufferRange | undefined;
|
if (prevSelectedPos) {
|
||||||
if (this._terminal.hasSelection()) {
|
if (this._cachedSearchTerm === term) {
|
||||||
// const incremental = searchOptions ? searchOptions.incremental : false;
|
startCol = prevSelectedPos.end.x;
|
||||||
// Start from the selection end if there is a selection
|
startRow = prevSelectedPos.end.y;
|
||||||
// For incremental search, use existing row
|
} else {
|
||||||
currentSelection = this._terminal.getSelectionPosition()!;
|
startCol = prevSelectedPos.start.x;
|
||||||
startRow = currentSelection.end.y;
|
startRow = prevSelectedPos.start.y;
|
||||||
startCol = currentSelection.end.x;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this._initLinesCache();
|
this._initLinesCache();
|
||||||
@@ -276,8 +274,8 @@ export class SearchAddon extends Disposable implements ITerminalAddon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If there is only one result, wrap back and return selection if it exists.
|
// If there is only one result, wrap back and return selection if it exists.
|
||||||
if (!result && currentSelection) {
|
if (!result && prevSelectedPos) {
|
||||||
searchPosition.startRow = currentSelection.start.y;
|
searchPosition.startRow = prevSelectedPos.start.y;
|
||||||
searchPosition.startCol = 0;
|
searchPosition.startCol = 0;
|
||||||
result = this._findInLine(term, searchPosition, searchOptions);
|
result = this._findInLine(term, searchPosition, searchOptions);
|
||||||
}
|
}
|
||||||
@@ -331,52 +329,43 @@ export class SearchAddon extends Disposable implements ITerminalAddon {
|
|||||||
if (!this._terminal) {
|
if (!this._terminal) {
|
||||||
throw new Error('Cannot use addon until it has been loaded');
|
throw new Error('Cannot use addon until it has been loaded');
|
||||||
}
|
}
|
||||||
let result: ISearchResult | undefined;
|
|
||||||
if (!this._terminal || !term || term.length === 0) {
|
if (!this._terminal || !term || term.length === 0) {
|
||||||
result = undefined;
|
|
||||||
this._terminal?.clearSelection();
|
this._terminal?.clearSelection();
|
||||||
this.clearDecorations();
|
this.clearDecorations();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._cachedSearchTerm !== term) {
|
const prevSelectedPos = this._terminal.getSelectionPosition();
|
||||||
this._terminal.clearSelection();
|
this._terminal.clearSelection();
|
||||||
}
|
|
||||||
|
|
||||||
let startRow = this._terminal.buffer.active.baseY + this._terminal.rows - 1;
|
let startRow = this._terminal.buffer.active.baseY + this._terminal.rows - 1;
|
||||||
let startCol = this._terminal.cols;
|
let startCol = this._terminal.cols;
|
||||||
const isReverseSearch = true;
|
const isReverseSearch = true;
|
||||||
|
|
||||||
let currentSelection: IBufferRange | undefined;
|
|
||||||
if (this._terminal.hasSelection()) {
|
|
||||||
currentSelection = this._terminal.getSelectionPosition()!;
|
|
||||||
// Start from selection start if there is a selection
|
|
||||||
startRow = currentSelection.start.y;
|
|
||||||
startCol = currentSelection.start.x;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._initLinesCache();
|
this._initLinesCache();
|
||||||
const searchPosition: ISearchPosition = {
|
const searchPosition: ISearchPosition = {
|
||||||
startRow,
|
startRow,
|
||||||
startCol
|
startCol
|
||||||
};
|
};
|
||||||
|
|
||||||
// const incremental = searchOptions ? searchOptions.incremental : false;
|
let result: ISearchResult | undefined;
|
||||||
// if (incremental) {
|
if (prevSelectedPos) {
|
||||||
// // Try to expand selection to right first.
|
searchPosition.startRow = startRow = prevSelectedPos.start.y;
|
||||||
// result = this._findInLine(term, searchPosition, searchOptions, false);
|
searchPosition.startCol = startCol = prevSelectedPos.start.x;
|
||||||
// const isOldResultHighlighted = result && result.row === startRow && result.col === startCol;
|
if (this._cachedSearchTerm !== term) {
|
||||||
// if (!isOldResultHighlighted) {
|
// Try to expand selection to right first.
|
||||||
// // If selection was not able to be expanded to the right, then try reverse search
|
result = this._findInLine(term, searchPosition, searchOptions, false);
|
||||||
// if (currentSelection) {
|
if (!result) {
|
||||||
// searchPosition.startRow = currentSelection.end.y;
|
// If selection was not able to be expanded to the right, then try reverse search
|
||||||
// searchPosition.startCol = currentSelection.end.x;
|
searchPosition.startRow = startRow = prevSelectedPos.end.y;
|
||||||
// }
|
searchPosition.startCol = startCol = prevSelectedPos.end.x;
|
||||||
// result = this._findInLine(term, searchPosition, searchOptions, true);
|
}
|
||||||
// }
|
}
|
||||||
// } else {
|
}
|
||||||
result = this._findInLine(term, searchPosition, searchOptions, isReverseSearch);
|
|
||||||
// }
|
if (!result) {
|
||||||
|
result = this._findInLine(term, searchPosition, searchOptions, isReverseSearch);
|
||||||
|
}
|
||||||
|
|
||||||
// Search from startRow - 1 to top
|
// Search from startRow - 1 to top
|
||||||
if (!result) {
|
if (!result) {
|
||||||
@@ -400,9 +389,6 @@ export class SearchAddon extends Disposable implements ITerminalAddon {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is only one result, return true.
|
|
||||||
if (!result && currentSelection) return true;
|
|
||||||
|
|
||||||
// Set selection and scroll if a result was found
|
// Set selection and scroll if a result was found
|
||||||
return this._selectResult(result, searchOptions?.decorations, searchOptions?.noScroll);
|
return this._selectResult(result, searchOptions?.decorations, searchOptions?.noScroll);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ describe('Search Tests', function (): void {
|
|||||||
window.calls = [];
|
window.calls = [];
|
||||||
window.search.onDidChangeResults(e => window.calls.push(e));
|
window.search.onDidChangeResults(e => window.calls.push(e));
|
||||||
`);
|
`);
|
||||||
await writeSync(page, 'abc aabc');
|
await writeSync(page, 'd abc aabc d');
|
||||||
assert.deepStrictEqual(await page.evaluate(`window.search.findNext('a', { incremental: true, decorations: { activeMatchColorOverviewRuler: '#ff0000' } })`), true);
|
assert.deepStrictEqual(await page.evaluate(`window.search.findNext('a', { incremental: true, decorations: { activeMatchColorOverviewRuler: '#ff0000' } })`), true);
|
||||||
assert.deepStrictEqual(await page.evaluate('window.calls'), [
|
assert.deepStrictEqual(await page.evaluate('window.calls'), [
|
||||||
{ resultCount: 3, resultIndex: 0 }
|
{ resultCount: 3, resultIndex: 0 }
|
||||||
@@ -201,12 +201,21 @@ describe('Search Tests', function (): void {
|
|||||||
{ resultCount: 2, resultIndex: 0 },
|
{ resultCount: 2, resultIndex: 0 },
|
||||||
{ resultCount: 2, resultIndex: 1 }
|
{ resultCount: 2, resultIndex: 1 }
|
||||||
]);
|
]);
|
||||||
|
assert.deepStrictEqual(await page.evaluate(`window.search.findNext('d', { incremental: true, decorations: { activeMatchColorOverviewRuler: '#ff0000' } })`), true);
|
||||||
|
assert.deepStrictEqual(await page.evaluate('window.calls'), [
|
||||||
|
{ resultCount: 3, resultIndex: 0 },
|
||||||
|
{ resultCount: 2, resultIndex: 0 },
|
||||||
|
{ resultCount: 2, resultIndex: 0 },
|
||||||
|
{ resultCount: 2, resultIndex: 1 },
|
||||||
|
{ resultCount: 2, resultIndex: 1 }
|
||||||
|
]);
|
||||||
assert.deepStrictEqual(await page.evaluate(`window.search.findNext('abcd', { incremental: true, decorations: { activeMatchColorOverviewRuler: '#ff0000' } })`), false);
|
assert.deepStrictEqual(await page.evaluate(`window.search.findNext('abcd', { incremental: true, decorations: { activeMatchColorOverviewRuler: '#ff0000' } })`), false);
|
||||||
assert.deepStrictEqual(await page.evaluate('window.calls'), [
|
assert.deepStrictEqual(await page.evaluate('window.calls'), [
|
||||||
{ resultCount: 3, resultIndex: 0 },
|
{ resultCount: 3, resultIndex: 0 },
|
||||||
{ resultCount: 2, resultIndex: 0 },
|
{ resultCount: 2, resultIndex: 0 },
|
||||||
{ resultCount: 2, resultIndex: 0 },
|
{ resultCount: 2, resultIndex: 0 },
|
||||||
{ resultCount: 2, resultIndex: 1 },
|
{ resultCount: 2, resultIndex: 1 },
|
||||||
|
{ resultCount: 2, resultIndex: 1 },
|
||||||
{ resultCount: 0, resultIndex: -1 }
|
{ resultCount: 0, resultIndex: -1 }
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
@@ -230,7 +239,7 @@ describe('Search Tests', function (): void {
|
|||||||
assert.deepStrictEqual(await page.evaluate('window.calls'), [
|
assert.deepStrictEqual(await page.evaluate('window.calls'), [
|
||||||
{ resultCount: 1000, resultIndex: 0 },
|
{ resultCount: 1000, resultIndex: 0 },
|
||||||
{ resultCount: 1000, resultIndex: 1 },
|
{ resultCount: 1000, resultIndex: 1 },
|
||||||
{ resultCount: 1000, resultIndex: 0 }
|
{ resultCount: 1000, resultIndex: 1 }
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -256,6 +265,7 @@ describe('Search Tests', function (): void {
|
|||||||
assert.deepStrictEqual(await page.evaluate('window.calls'), [
|
assert.deepStrictEqual(await page.evaluate('window.calls'), [
|
||||||
{ resultCount: 1, resultIndex: 0 }
|
{ resultCount: 1, resultIndex: 0 }
|
||||||
]);
|
]);
|
||||||
|
await page.evaluate(`window.term.clearSelection()`);
|
||||||
assert.strictEqual(await page.evaluate(`window.search.findPrevious('b', { decorations: { activeMatchColorOverviewRuler: '#ff0000' } })`), true);
|
assert.strictEqual(await page.evaluate(`window.search.findPrevious('b', { decorations: { activeMatchColorOverviewRuler: '#ff0000' } })`), true);
|
||||||
assert.deepStrictEqual(await page.evaluate('window.calls'), [
|
assert.deepStrictEqual(await page.evaluate('window.calls'), [
|
||||||
{ resultCount: 1, resultIndex: 0 },
|
{ resultCount: 1, resultIndex: 0 },
|
||||||
@@ -285,7 +295,7 @@ describe('Search Tests', function (): void {
|
|||||||
window.calls = [];
|
window.calls = [];
|
||||||
window.search.onDidChangeResults(e => window.calls.push(e));
|
window.search.onDidChangeResults(e => window.calls.push(e));
|
||||||
`);
|
`);
|
||||||
await writeSync(page, 'abc aabc');
|
await writeSync(page, 'd abc aabc d');
|
||||||
assert.deepStrictEqual(await page.evaluate(`window.search.findPrevious('a', { incremental: true, decorations: { activeMatchColorOverviewRuler: '#ff0000' } })`), true);
|
assert.deepStrictEqual(await page.evaluate(`window.search.findPrevious('a', { incremental: true, decorations: { activeMatchColorOverviewRuler: '#ff0000' } })`), true);
|
||||||
assert.deepStrictEqual(await page.evaluate('window.calls'), [
|
assert.deepStrictEqual(await page.evaluate('window.calls'), [
|
||||||
{ resultCount: 3, resultIndex: 2 }
|
{ resultCount: 3, resultIndex: 2 }
|
||||||
@@ -308,12 +318,21 @@ describe('Search Tests', function (): void {
|
|||||||
{ resultCount: 2, resultIndex: 1 },
|
{ resultCount: 2, resultIndex: 1 },
|
||||||
{ resultCount: 2, resultIndex: 0 }
|
{ resultCount: 2, resultIndex: 0 }
|
||||||
]);
|
]);
|
||||||
|
assert.deepStrictEqual(await page.evaluate(`window.search.findPrevious('d', { incremental: true, decorations: { activeMatchColorOverviewRuler: '#ff0000' } })`), true);
|
||||||
|
assert.deepStrictEqual(await page.evaluate('window.calls'), [
|
||||||
|
{ resultCount: 3, resultIndex: 2 },
|
||||||
|
{ resultCount: 2, resultIndex: 1 },
|
||||||
|
{ resultCount: 2, resultIndex: 1 },
|
||||||
|
{ resultCount: 2, resultIndex: 0 },
|
||||||
|
{ resultCount: 2, resultIndex: 1 }
|
||||||
|
]);
|
||||||
assert.deepStrictEqual(await page.evaluate(`window.search.findPrevious('abcd', { incremental: true, decorations: { activeMatchColorOverviewRuler: '#ff0000' } })`), false);
|
assert.deepStrictEqual(await page.evaluate(`window.search.findPrevious('abcd', { incremental: true, decorations: { activeMatchColorOverviewRuler: '#ff0000' } })`), false);
|
||||||
assert.deepStrictEqual(await page.evaluate('window.calls'), [
|
assert.deepStrictEqual(await page.evaluate('window.calls'), [
|
||||||
{ resultCount: 3, resultIndex: 2 },
|
{ resultCount: 3, resultIndex: 2 },
|
||||||
{ resultCount: 2, resultIndex: 1 },
|
{ resultCount: 2, resultIndex: 1 },
|
||||||
{ resultCount: 2, resultIndex: 1 },
|
{ resultCount: 2, resultIndex: 1 },
|
||||||
{ resultCount: 2, resultIndex: 0 },
|
{ resultCount: 2, resultIndex: 0 },
|
||||||
|
{ resultCount: 2, resultIndex: 1 },
|
||||||
{ resultCount: 0, resultIndex: -1 }
|
{ resultCount: 0, resultIndex: -1 }
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user