Skip to content

Commit 14a1c7e

Browse files
authored
allow multiple callers for decorating notebook webview (microsoft#187743)
1 parent 52d4622 commit 14a1c7e

17 files changed

+226
-131
lines changed

src/vs/workbench/contrib/notebook/browser/contrib/find/findMatchDecorationModel.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export class FindMatchDecorationModel extends Disposable {
1717
private _currentMatchDecorations: { kind: 'input'; decorations: ICellModelDecorations[] } | { kind: 'output'; index: number } | null = null;
1818

1919
constructor(
20-
private readonly _notebookEditor: INotebookEditor
20+
private readonly _notebookEditor: INotebookEditor,
21+
private readonly ownerID: string,
2122
) {
2223
super();
2324
}
@@ -26,7 +27,7 @@ export class FindMatchDecorationModel extends Disposable {
2627
return this._currentMatchDecorations;
2728
}
2829

29-
public clearDecorations() {
30+
private clearDecorations() {
3031
this.clearCurrentFindMatchDecoration();
3132
this.setAllFindMatchesDecorations([]);
3233
}
@@ -75,7 +76,7 @@ export class FindMatchDecorationModel extends Disposable {
7576

7677
this.clearCurrentFindMatchDecoration();
7778

78-
const offset = await this._notebookEditor.highlightFind(index);
79+
const offset = await this._notebookEditor.findHighlightCurrent(index, this.ownerID);
7980
this._currentMatchDecorations = { kind: 'output', index: index };
8081

8182
this._currentMatchCellDecorations = this._notebookEditor.deltaCellDecorations(this._currentMatchCellDecorations, [{
@@ -101,7 +102,7 @@ export class FindMatchDecorationModel extends Disposable {
101102
this._currentMatchDecorations = null;
102103
});
103104
} else if (this._currentMatchDecorations?.kind === 'output') {
104-
this._notebookEditor.unHighlightFind(this._currentMatchDecorations.index);
105+
this._notebookEditor.findUnHighlightCurrent(this._currentMatchDecorations.index, this.ownerID);
105106
}
106107

107108
this._currentMatchCellDecorations = this._notebookEditor.deltaCellDecorations(this._currentMatchCellDecorations, []);
@@ -145,7 +146,7 @@ export class FindMatchDecorationModel extends Disposable {
145146
}
146147

147148
stopWebviewFind() {
148-
this._notebookEditor.findStop();
149+
this._notebookEditor.findStop(this.ownerID);
149150
}
150151

151152
override dispose() {

src/vs/workbench/contrib/notebook/browser/contrib/find/findModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export class FindModel extends Disposable {
111111
this._registerModelListener(this._notebookEditor.textModel);
112112
}
113113

114-
this._findMatchDecorationModel = new FindMatchDecorationModel(this._notebookEditor);
114+
this._findMatchDecorationModel = new FindMatchDecorationModel(this._notebookEditor, this._notebookEditor.getId());
115115
}
116116

117117
private _updateCellStates(e: FindReplaceStateChangedEvent) {

src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -673,10 +673,10 @@ export interface INotebookEditor {
673673
getCellIndex(cell: ICellViewModel): number | undefined;
674674
getNextVisibleCellIndex(index: number): number | undefined;
675675
getPreviousVisibleCellIndex(index: number): number | undefined;
676-
find(query: string, options: INotebookSearchOptions, token: CancellationToken): Promise<CellFindMatchWithIndex[]>;
677-
highlightFind(matchIndex: number): Promise<number>;
678-
unHighlightFind(matchIndex: number): Promise<void>;
679-
findStop(): void;
676+
find(query: string, options: INotebookSearchOptions, token: CancellationToken, skipWarmup?: boolean, shouldGetSearchPreviewInfo?: boolean, ownerID?: string): Promise<CellFindMatchWithIndex[]>;
677+
findHighlightCurrent(matchIndex: number, ownerID?: string): Promise<number>;
678+
findUnHighlightCurrent(matchIndex: number, ownerID?: string): Promise<void>;
679+
findStop(ownerID?: string): void;
680680
showProgress(): void;
681681
hideProgress(): void;
682682

src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2430,15 +2430,19 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
24302430
return Promise.all(requests);
24312431
}
24322432

2433-
async find(query: string, options: INotebookSearchOptions, token: CancellationToken, skipWarmup: boolean = false, shouldGetSearchPreviewInfo = false): Promise<CellFindMatchWithIndex[]> {
2433+
async find(query: string, options: INotebookSearchOptions, token: CancellationToken, skipWarmup: boolean = false, shouldGetSearchPreviewInfo = false, ownerID?: string): Promise<CellFindMatchWithIndex[]> {
24342434
if (!this._notebookViewModel) {
24352435
return [];
24362436
}
24372437

2438+
if (!ownerID) {
2439+
ownerID = this.getId();
2440+
}
2441+
24382442
const findMatches = this._notebookViewModel.find(query, options).filter(match => match.length > 0);
24392443

24402444
if (!options.includeMarkupPreview && !options.includeOutput) {
2441-
this._webview?.findStop();
2445+
this._webview?.findStop(ownerID);
24422446
return findMatches;
24432447
}
24442448

@@ -2461,7 +2465,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
24612465
return [];
24622466
}
24632467

2464-
const webviewMatches = await this._webview.find(query, { caseSensitive: options.caseSensitive, wholeWord: options.wholeWord, includeMarkup: !!options.includeMarkupPreview, includeOutput: !!options.includeOutput, shouldGetSearchPreviewInfo });
2468+
const webviewMatches = await this._webview.find(query, { caseSensitive: options.caseSensitive, wholeWord: options.wholeWord, includeMarkup: !!options.includeMarkupPreview, includeOutput: !!options.includeOutput, shouldGetSearchPreviewInfo, ownerID });
24652469

24662470
if (token.isCancellationRequested) {
24672471
return [];
@@ -2517,24 +2521,24 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
25172521
return ret;
25182522
}
25192523

2520-
async highlightFind(matchIndex: number): Promise<number> {
2524+
async findHighlightCurrent(matchIndex: number, ownerID?: string): Promise<number> {
25212525
if (!this._webview) {
25222526
return 0;
25232527
}
25242528

2525-
return this._webview?.findHighlight(matchIndex);
2529+
return this._webview?.findHighlightCurrent(matchIndex, ownerID ?? this.getId());
25262530
}
25272531

2528-
async unHighlightFind(matchIndex: number): Promise<void> {
2532+
async findUnHighlightCurrent(matchIndex: number, ownerID?: string): Promise<void> {
25292533
if (!this._webview) {
25302534
return;
25312535
}
25322536

2533-
return this._webview?.findUnHighlight(matchIndex);
2537+
return this._webview?.findUnHighlightCurrent(matchIndex, ownerID ?? this.getId());
25342538
}
25352539

2536-
findStop() {
2537-
this._webview?.findStop();
2540+
findStop(ownerID?: string) {
2541+
this._webview?.findStop(ownerID ?? this.getId());
25382542
}
25392543

25402544
//#endregion

src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,7 +1608,7 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
16081608
});
16091609
}
16101610

1611-
async find(query: string, options: { wholeWord?: boolean; caseSensitive?: boolean; includeMarkup: boolean; includeOutput: boolean; shouldGetSearchPreviewInfo: boolean }): Promise<IFindMatch[]> {
1611+
async find(query: string, options: { wholeWord?: boolean; caseSensitive?: boolean; includeMarkup: boolean; includeOutput: boolean; shouldGetSearchPreviewInfo: boolean; ownerID: string }): Promise<IFindMatch[]> {
16121612
if (query === '') {
16131613
return [];
16141614
}
@@ -1632,35 +1632,38 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
16321632
return ret;
16331633
}
16341634

1635-
findStop() {
1635+
findStop(ownerID: string) {
16361636
this._sendMessageToWebview({
1637-
type: 'findStop'
1637+
type: 'findStop',
1638+
ownerID
16381639
});
16391640
}
16401641

1641-
async findHighlight(index: number): Promise<number> {
1642+
async findHighlightCurrent(index: number, ownerID: string): Promise<number> {
16421643
const p = new Promise<number>(resolve => {
16431644
const sub = this.webview?.onMessage(e => {
1644-
if (e.message.type === 'didFindHighlight') {
1645+
if (e.message.type === 'didFindHighlightCurrent') {
16451646
resolve(e.message.offset);
16461647
sub?.dispose();
16471648
}
16481649
});
16491650
});
16501651

16511652
this._sendMessageToWebview({
1652-
type: 'findHighlight',
1653-
index
1653+
type: 'findHighlightCurrent',
1654+
index,
1655+
ownerID
16541656
});
16551657

16561658
const ret = await p;
16571659
return ret;
16581660
}
16591661

1660-
async findUnHighlight(index: number): Promise<void> {
1662+
async findUnHighlightCurrent(index: number, ownerID: string): Promise<void> {
16611663
this._sendMessageToWebview({
1662-
type: 'findUnHighlight',
1663-
index
1664+
type: 'findUnHighlightCurrent',
1665+
index,
1666+
ownerID
16641667
});
16651668
}
16661669

src/vs/workbench/contrib/notebook/browser/view/renderers/webviewMessages.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -397,22 +397,25 @@ export interface ITokenizedStylesChangedMessage {
397397
export interface IFindMessage {
398398
readonly type: 'find';
399399
readonly query: string;
400-
readonly options: { wholeWord?: boolean; caseSensitive?: boolean; includeMarkup: boolean; includeOutput: boolean; shouldGetSearchPreviewInfo: boolean };
400+
readonly options: { wholeWord?: boolean; caseSensitive?: boolean; includeMarkup: boolean; includeOutput: boolean; shouldGetSearchPreviewInfo: boolean; ownerID: string };
401401
}
402402

403403

404-
export interface IFindHighlightMessage {
405-
readonly type: 'findHighlight';
404+
export interface IFindHighlightCurrentMessage {
405+
readonly type: 'findHighlightCurrent';
406406
readonly index: number;
407+
readonly ownerID: string;
407408
}
408409

409-
export interface IFindUnHighlightMessage {
410-
readonly type: 'findUnHighlight';
410+
export interface IFindUnHighlightCurrentMessage {
411+
readonly type: 'findUnHighlightCurrent';
411412
readonly index: number;
413+
readonly ownerID: string;
412414
}
413415

414416
export interface IFindStopMessage {
415417
readonly type: 'findStop';
418+
readonly ownerID: string;
416419
}
417420

418421
export interface ISearchPreviewInfo {
@@ -436,8 +439,8 @@ export interface IDidFindMessage extends BaseToWebviewMessage {
436439
readonly matches: IFindMatch[];
437440
}
438441

439-
export interface IDidFindHighlightMessage extends BaseToWebviewMessage {
440-
readonly type: 'didFindHighlight';
442+
export interface IDidFindHighlightCurrentMessage extends BaseToWebviewMessage {
443+
readonly type: 'didFindHighlightCurrent';
441444
readonly offset: number;
442445
}
443446

@@ -502,7 +505,7 @@ export type FromWebviewMessage = WebviewInitialized |
502505
IRenderedMarkupMessage |
503506
IRenderedCellOutputMessage |
504507
IDidFindMessage |
505-
IDidFindHighlightMessage |
508+
IDidFindHighlightCurrentMessage |
506509
IOutputResizedMessage |
507510
IGetOutputItemMessage |
508511
ILogRendererDebugMessage |
@@ -534,8 +537,8 @@ export type ToWebviewMessage = IClearMessage |
534537
ITokenizedCodeBlockMessage |
535538
ITokenizedStylesChangedMessage |
536539
IFindMessage |
537-
IFindHighlightMessage |
538-
IFindUnHighlightMessage |
540+
IFindHighlightCurrentMessage |
541+
IFindUnHighlightCurrentMessage |
539542
IFindStopMessage |
540543
IReturnOutputItemMessage;
541544

0 commit comments

Comments
 (0)