on dispose, clear the canvas at that position

This commit is contained in:
meganrogge
2022-03-17 10:38:44 -04:00
parent 90f64ba6cc
commit c2145d5125
2 changed files with 19 additions and 14 deletions
+9 -8
View File
@@ -62,6 +62,14 @@ export class SearchAddon implements ITerminalAddon {
public dispose(): void { } public dispose(): void { }
public clear(): void {
this._terminal?.clearSelection();
this._resultDecorations.forEach(d => d.dispose());
this._selectedDecoration?.dispose();
this._resultDecorations = [];
this._reset = true;
}
/** /**
* Find all instances of the term, selecting the next one with each * Find all instances of the term, selecting the next one with each
* enter. If it doesn't exist, do nothing. * enter. If it doesn't exist, do nothing.
@@ -75,9 +83,7 @@ export class SearchAddon implements ITerminalAddon {
} }
if (!term || term.length === 0) { if (!term || term.length === 0) {
this._terminal.clearSelection(); this.clear();
this._resultDecorations.forEach(d => d.dispose());
this._resultDecorations = [];
return false; return false;
} }
@@ -92,7 +98,6 @@ 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());
console.log('clearing');
const results: ISearchResult[] = []; const results: ISearchResult[] = [];
searchOptions = searchOptions || {}; searchOptions = searchOptions || {};
searchOptions.incremental = false; searchOptions.incremental = false;
@@ -103,7 +108,6 @@ export class SearchAddon implements ITerminalAddon {
} }
found = this.findNext(term, searchOptions); found = this.findNext(term, searchOptions);
} }
console.log(results);
for (const result of results) { for (const result of results) {
if (result) { if (result) {
const resultDecoration = this._showResultDecoration(result); const resultDecoration = this._showResultDecoration(result);
@@ -542,10 +546,7 @@ export class SearchAddon implements ITerminalAddon {
*/ */
private _showResultDecoration(result: ISearchResult): IDecoration | undefined { private _showResultDecoration(result: ISearchResult): IDecoration | undefined {
const terminal = this._terminal!; const terminal = this._terminal!;
// for demo to work
// const marker = terminal.registerMarker(undefined, result.row);
const marker = terminal.registerMarker(undefined, result.row); const marker = terminal.registerMarker(undefined, result.row);
console.log(result.row, marker?.line);
if (!marker) { if (!marker) {
return undefined; return undefined;
} }
@@ -67,12 +67,7 @@ export class OverviewRulerRenderer extends Disposable {
public override dispose(): void { public override dispose(): void {
for (const decoration of this._decorationElements) { for (const decoration of this._decorationElements) {
this._ctx?.clearRect( decoration[0].dispose();
0,
Math.round(this._canvas.height * (decoration[0].marker.line / this._bufferService.buffers.active.lines.length)),
this._canvas.width,
window.devicePixelRatio
);
} }
this._decorationElements.clear(); this._decorationElements.clear();
this._canvas?.remove(); this._canvas?.remove();
@@ -119,6 +114,15 @@ export class OverviewRulerRenderer extends Disposable {
const element = this._decorationElements.get(decoration); const element = this._decorationElements.get(decoration);
if (!element) { if (!element) {
this._decorationElements.set(decoration, this._canvas); this._decorationElements.set(decoration, this._canvas);
decoration.onDispose(() => {
this._ctx?.clearRect(
!decoration!.options!.overviewRulerOptions?.position || decoration!.options!.overviewRulerOptions?.position === 'left' ? 0 : decoration!.options!.overviewRulerOptions?.position === 'right' ? renderSizes[SizeIndex.OUTER_SIZE] + renderSizes[SizeIndex.INNER_SIZE]: renderSizes[SizeIndex.OUTER_SIZE],
Math.round(this._canvas.height * (decoration!.options!.marker.line / this._bufferService.buffers.active.lines.length)),
!decoration!.options!.overviewRulerOptions?.position ? this._width : decoration!.options!.overviewRulerOptions?.position === 'center' ? renderSizes[SizeIndex.INNER_SIZE] : renderSizes[SizeIndex.OUTER_SIZE],
// when a position is provided, the element has less width, so increase its height
window.devicePixelRatio * (decoration!.options!.overviewRulerOptions?.position ? 6 : 2)
);
});
} }
this._refreshStyle(decoration, updateAnchor); this._refreshStyle(decoration, updateAnchor);
} }