Skip to content

Commit bf786f9

Browse files
author
Eric Amodio
committed
Dynamically updates diff context to cause updates
Important for menu recalc based on diff contexts
1 parent 4de754d commit bf786f9

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

src/vs/editor/browser/widget/diffEditorWidget.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -348,21 +348,19 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
348348
this._diffComputationResult = null;
349349

350350
const leftContextKeyService = this._contextKeyService.createScoped();
351-
leftContextKeyService.createKey('isInDiffLeftEditor', true);
352351

353352
const leftServices = new ServiceCollection();
354353
leftServices.set(IContextKeyService, leftContextKeyService);
355354
const leftScopedInstantiationService = instantiationService.createChild(leftServices);
356355

357356
const rightContextKeyService = this._contextKeyService.createScoped();
358-
rightContextKeyService.createKey('isInDiffRightEditor', true);
359357

360358
const rightServices = new ServiceCollection();
361359
rightServices.set(IContextKeyService, rightContextKeyService);
362360
const rightScopedInstantiationService = instantiationService.createChild(rightServices);
363361

364-
this.originalEditor = this._createLeftHandSideEditor(options, leftScopedInstantiationService);
365-
this.modifiedEditor = this._createRightHandSideEditor(options, rightScopedInstantiationService);
362+
this.originalEditor = this._createLeftHandSideEditor(options, leftScopedInstantiationService, leftContextKeyService);
363+
this.modifiedEditor = this._createRightHandSideEditor(options, rightScopedInstantiationService, rightContextKeyService);
366364

367365
this._originalOverviewRuler = null;
368366
this._modifiedOverviewRuler = null;
@@ -372,8 +370,6 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
372370
this._containerDomElement.appendChild(this._reviewPane.shadow.domNode);
373371
this._containerDomElement.appendChild(this._reviewPane.actionBarContainer.domNode);
374372

375-
376-
377373
// enableSplitViewResizing
378374
this._enableSplitViewResizing = true;
379375
if (typeof options.enableSplitViewResizing !== 'undefined') {
@@ -480,7 +476,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
480476
this._layoutOverviewRulers();
481477
}
482478

483-
private _createLeftHandSideEditor(options: IDiffEditorOptions, instantiationService: IInstantiationService): CodeEditorWidget {
479+
private _createLeftHandSideEditor(options: IDiffEditorOptions, instantiationService: IInstantiationService, contextKeyService: IContextKeyService): CodeEditorWidget {
484480
const editor = this._createInnerEditor(instantiationService, this._originalDomNode, this._adjustOptionsForLeftHandSide(options, this._originalIsEditable, this._originalCodeLens));
485481

486482
this._register(editor.onDidScrollChange((e) => {
@@ -510,10 +506,14 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
510506
}
511507
}));
512508

509+
const isInDiffLeftEditorKey = contextKeyService.createKey<boolean>('isInDiffLeftEditor', undefined);
510+
this._register(Event.any(editor.onDidFocusEditorText, editor.onDidFocusEditorWidget)(() => isInDiffLeftEditorKey.set(true)));
511+
this._register(Event.any(editor.onDidBlurEditorText, editor.onDidBlurEditorWidget)(() => isInDiffLeftEditorKey.set(false)));
512+
513513
return editor;
514514
}
515515

516-
private _createRightHandSideEditor(options: IDiffEditorOptions, instantiationService: IInstantiationService): CodeEditorWidget {
516+
private _createRightHandSideEditor(options: IDiffEditorOptions, instantiationService: IInstantiationService, contextKeyService: IContextKeyService): CodeEditorWidget {
517517
const editor = this._createInnerEditor(instantiationService, this._modifiedDomNode, this._adjustOptionsForRightHandSide(options, this._modifiedCodeLens));
518518

519519
this._register(editor.onDidScrollChange((e) => {
@@ -555,6 +555,10 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
555555
}
556556
}));
557557

558+
const isInDiffRightEditorKey = contextKeyService.createKey<boolean>('isInDiffRightEditor', undefined);
559+
this._register(Event.any(editor.onDidFocusEditorText, editor.onDidFocusEditorWidget)(() => isInDiffRightEditorKey.set(true)));
560+
this._register(Event.any(editor.onDidBlurEditorText, editor.onDidBlurEditorWidget)(() => isInDiffRightEditorKey.set(false)));
561+
558562
return editor;
559563
}
560564

0 commit comments

Comments
 (0)