Skip to content

Commit c3e49b5

Browse files
rebornixchenjigeng
authored and
chenjigeng
committed
re microsoft#109549. Reveal the first change in notebook diff editor on open.
1 parent 39baa27 commit c3e49b5

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/vs/workbench/contrib/notebook/browser/diff/notebookTextDiffEditor.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
6060
return this._model?.modified.notebook;
6161
}
6262

63+
private _revealFirst: boolean;
64+
6365
constructor(
6466
@IInstantiationService readonly instantiationService: IInstantiationService,
6567
@IThemeService readonly themeService: IThemeService,
@@ -74,6 +76,7 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
7476
super(NotebookTextDiffEditor.ID, telemetryService, themeService, storageService);
7577
const editorOptions = this.configurationService.getValue<IEditorOptions>('editor');
7678
this._fontInfo = BareFontInfo.createFromRawSettings(editorOptions, getZoomLevel());
79+
this._revealFirst = true;
7780

7881
this._register(this._modifiedResourceDisposableStore);
7982
}
@@ -152,6 +155,8 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
152155
return;
153156
}
154157

158+
this._revealFirst = true;
159+
155160
this._modifiedResourceDisposableStore.add(this._fileService.watch(this._model.modified.resource));
156161
this._modifiedResourceDisposableStore.add(this._fileService.onDidFilesChange(async e => {
157162
if (this._model === null) {
@@ -223,6 +228,8 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
223228
let originalCellIndex = 0;
224229
let modifiedCellIndex = 0;
225230

231+
let firstChangeIndex = -1;
232+
226233
for (let i = 0; i < cellChanges.length; i++) {
227234
const change = cellChanges[i];
228235
// common cells
@@ -238,6 +245,10 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
238245
this._eventDispatcher!
239246
));
240247
} else {
248+
if (firstChangeIndex === -1) {
249+
firstChangeIndex = cellDiffViewModels.length;
250+
}
251+
241252
cellDiffViewModels.push(new CellDiffViewModel(
242253
originalCell,
243254
modifiedCell,
@@ -247,7 +258,12 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
247258
}
248259
}
249260

250-
cellDiffViewModels.push(...this._computeModifiedLCS(change, originalModel, modifiedModel));
261+
const modifiedLCS = this._computeModifiedLCS(change, originalModel, modifiedModel);
262+
if (modifiedLCS.length && firstChangeIndex === -1) {
263+
firstChangeIndex = cellDiffViewModels.length;
264+
}
265+
266+
cellDiffViewModels.push(...modifiedLCS);
251267
originalCellIndex = change.originalStart + change.originalLength;
252268
modifiedCellIndex = change.modifiedStart + change.modifiedLength;
253269
}
@@ -262,6 +278,12 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
262278
}
263279

264280
this._list.splice(0, this._list.length, cellDiffViewModels);
281+
282+
if (this._revealFirst && firstChangeIndex !== -1) {
283+
this._revealFirst = false;
284+
this._list.setFocus([firstChangeIndex]);
285+
this._list.reveal(firstChangeIndex, 0.3);
286+
}
265287
}
266288

267289
private _computeModifiedLCS(change: IDiffChange, originalModel: NotebookTextModel, modifiedModel: NotebookTextModel) {

0 commit comments

Comments
 (0)