Highlight all matches in Notebook on Find (#15562)

* iterate over every cell and highlight ranges.

* fix yellow for all matches and orange for current

* fix

* avoid duplicate deltaDecorations call

* initialize on declare
This commit is contained in:
Maddy
2021-06-04 15:45:51 -07:00
committed by GitHub
parent b490d53284
commit d04451985c
8 changed files with 267 additions and 139 deletions

View File

@@ -154,14 +154,40 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
return editors;
}
public deltaDecorations(newDecorationRange: NotebookRange, oldDecorationRange: NotebookRange): void {
if (newDecorationRange && newDecorationRange.cell && newDecorationRange.cell.cellType === 'markdown') {
let cell = this.cellEditors.filter(c => c.cellGuid() === newDecorationRange.cell.cellGuid);
cell[cell.length - 1].deltaDecorations(newDecorationRange, undefined);
public deltaDecorations(newDecorationsRange: NotebookRange | NotebookRange[], oldDecorationsRange: NotebookRange | NotebookRange[]): void {
if (oldDecorationsRange) {
if (Array.isArray(oldDecorationsRange)) {
let decoratedCells: string[] = [];
oldDecorationsRange.forEach(oldDecorationRange => {
if (oldDecorationRange.cell.cellType === 'markdown' && decoratedCells.indexOf(oldDecorationRange.cell.cellGuid) === -1) {
let cell = this.cellEditors.filter(c => c.cellGuid() === oldDecorationRange.cell.cellGuid);
cell[cell.length - 1].deltaDecorations(undefined, [oldDecorationRange]);
decoratedCells.push(...oldDecorationRange.cell.cellGuid);
}
});
} else {
if (oldDecorationsRange.cell.cellType === 'markdown') {
let cell = this.cellEditors.filter(c => c.cellGuid() === oldDecorationsRange.cell.cellGuid);
cell[cell.length - 1].deltaDecorations(undefined, oldDecorationsRange);
}
}
}
if (oldDecorationRange && oldDecorationRange.cell && oldDecorationRange.cell.cellType === 'markdown') {
let cell = this.cellEditors.filter(c => c.cellGuid() === oldDecorationRange.cell.cellGuid);
cell[cell.length - 1].deltaDecorations(undefined, oldDecorationRange);
if (newDecorationsRange) {
if (Array.isArray(newDecorationsRange)) {
let decoratedCells: string[] = [];
newDecorationsRange.forEach(newDecorationRange => {
if (newDecorationRange.cell.cellType === 'markdown' && decoratedCells.indexOf(newDecorationRange.cell.cellGuid) === -1) {
let cell = this.cellEditors.filter(c => c.cellGuid() === newDecorationRange.cell.cellGuid);
cell[cell.length - 1].deltaDecorations([newDecorationRange], undefined);
decoratedCells.push(...newDecorationRange.cell.cellGuid);
}
});
} else {
if (newDecorationsRange.cell.cellType === 'markdown') {
let cell = this.cellEditors.filter(c => c.cellGuid() === newDecorationsRange.cell.cellGuid);
cell[cell.length - 1].deltaDecorations(newDecorationsRange, undefined);
}
}
}
}