start work on selection color
This commit is contained in:
@@ -44,6 +44,7 @@ export class SearchAddon implements ITerminalAddon {
|
|||||||
private _result: ISearchResult | undefined;
|
private _result: ISearchResult | undefined;
|
||||||
private _reset: boolean = false;
|
private _reset: boolean = false;
|
||||||
private _cachedSearchTerm: string | undefined;
|
private _cachedSearchTerm: string | undefined;
|
||||||
|
private _cachedResults: ISearchResult[] = [];
|
||||||
/**
|
/**
|
||||||
* translateBufferLineToStringWithWrap is a fairly expensive call.
|
* translateBufferLineToStringWithWrap is a fairly expensive call.
|
||||||
* We memoize the calls into an array that has a time based ttl.
|
* We memoize the calls into an array that has a time based ttl.
|
||||||
@@ -81,6 +82,11 @@ export class SearchAddon implements ITerminalAddon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!this._reset && term === this._cachedSearchTerm) {
|
if (!this._reset && term === this._cachedSearchTerm) {
|
||||||
|
// this._resultDecorations.forEach(d => d.dispose());
|
||||||
|
// this._resultDecorations = [];
|
||||||
|
// for (const decoration of this._cachedResults) {
|
||||||
|
// this._showResultDecoration(decoration);
|
||||||
|
// }
|
||||||
return this.findNext(term, searchOptions);
|
return this.findNext(term, searchOptions);
|
||||||
}
|
}
|
||||||
this._reset = false;
|
this._reset = false;
|
||||||
@@ -89,18 +95,17 @@ export class SearchAddon implements ITerminalAddon {
|
|||||||
// new search, clear out the old decorations
|
// new search, clear out the old decorations
|
||||||
this._resultDecorations.forEach(d => d.dispose());
|
this._resultDecorations.forEach(d => d.dispose());
|
||||||
this._resultDecorations = [];
|
this._resultDecorations = [];
|
||||||
const results: ISearchResult[] = [];
|
|
||||||
searchOptions = searchOptions || {};
|
searchOptions = searchOptions || {};
|
||||||
searchOptions.incremental = false;
|
searchOptions.incremental = false;
|
||||||
let found = this.findNext(term, searchOptions);
|
let found = this.findNext(term, searchOptions);
|
||||||
while (found && !results.find(r => r?.col === this._result?.col && r?.row === this._result?.row)) {
|
while (found && !this._cachedResults.find(r => r?.col === this._result?.col && r?.row === this._result?.row)) {
|
||||||
if (this._result) {
|
if (this._result) {
|
||||||
results.push(this._result);
|
this._cachedResults.push(this._result);
|
||||||
}
|
}
|
||||||
found = this.findNext(term, searchOptions);
|
found = this.findNext(term, searchOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const result of results) {
|
for (const result of this._cachedResults) {
|
||||||
if (result) {
|
if (result) {
|
||||||
const resultDecoration = this._showResultDecoration(result);
|
const resultDecoration = this._showResultDecoration(result);
|
||||||
if (resultDecoration) {
|
if (resultDecoration) {
|
||||||
@@ -108,7 +113,7 @@ export class SearchAddon implements ITerminalAddon {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (results.length > 0) {
|
if (this._cachedResults.length > 0) {
|
||||||
this._cachedSearchTerm = term;
|
this._cachedSearchTerm = term;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -517,6 +522,10 @@ export class SearchAddon implements ITerminalAddon {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
terminal.select(result.col, result.row, result.size);
|
terminal.select(result.col, result.row, result.size);
|
||||||
|
const marker = terminal.registerMarker(undefined, result.row);
|
||||||
|
if (marker) {
|
||||||
|
terminal.registerDecoration({ marker, overviewRulerOptions: { color: 'yellow' } });
|
||||||
|
}
|
||||||
// If it is not in the viewport then we scroll else it just gets selected
|
// If it is not in the viewport then we scroll else it just gets selected
|
||||||
if (result.row >= (terminal.buffer.active.viewportY + terminal.rows) || result.row < terminal.buffer.active.viewportY) {
|
if (result.row >= (terminal.buffer.active.viewportY + terminal.rows) || result.row < terminal.buffer.active.viewportY) {
|
||||||
let scroll = result.row - terminal.buffer.active.viewportY;
|
let scroll = result.row - terminal.buffer.active.viewportY;
|
||||||
@@ -537,9 +546,10 @@ export class SearchAddon implements ITerminalAddon {
|
|||||||
if (!marker) {
|
if (!marker) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
const findResultDecoration = terminal.registerDecoration({ marker, overviewRulerOptions: { color: 'yellow' } });
|
terminal.options.overviewRulerWidth = 10;
|
||||||
|
const findResultDecoration = terminal.registerDecoration({ marker, overviewRulerOptions: { color: 'blue' } });
|
||||||
findResultDecoration?.onRender((e) => {
|
findResultDecoration?.onRender((e) => {
|
||||||
if (!e.classList.contains('xterm-find-result-decoration') && result.term.length && e.clientWidth > 0) {
|
if (!e.classList.contains('xterm-find-result-decoration') && result.term.length && e.clientWidth > 0 && !e.classList.contains('xterm-decoration-overview-ruler')) {
|
||||||
e.classList.add('xterm-find-result-decoration');
|
e.classList.add('xterm-find-result-decoration');
|
||||||
// decoration's clientWidth = actualCellWidth
|
// decoration's clientWidth = actualCellWidth
|
||||||
e.style.left = `${e.clientWidth * result.col}px`;
|
e.style.left = `${e.clientWidth * result.col}px`;
|
||||||
|
|||||||
+1
-1
@@ -180,7 +180,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.xterm-find-result-decoration {
|
.xterm-find-result-decoration {
|
||||||
background-color: yellow;
|
background-color: blue;
|
||||||
opacity: 60%;
|
opacity: 60%;
|
||||||
}
|
}
|
||||||
.xterm-decoration-overview-ruler {
|
.xterm-decoration-overview-ruler {
|
||||||
|
|||||||
Reference in New Issue
Block a user