Introduce an onDidModelChange

This commit is contained in:
Logan Ramos 2021-11-17 15:16:49 -05:00
parent c37587ee2d
commit 6e42bf706e
No known key found for this signature in database
GPG key ID: D9CCFF14F0B18183
4 changed files with 22 additions and 3 deletions

View file

@ -90,6 +90,9 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
private readonly _onDidGroupChange = this._register(new Emitter<IGroupChangeEvent>());
readonly onDidGroupChange = this._onDidGroupChange.event;
private readonly _onDidModelChange = this._register(new Emitter<IGroupChangeEvent>());
readonly onDidModelChange = this._onDidModelChange.event;
private readonly _onDidOpenEditorFail = this._register(new Emitter<EditorInput>());
readonly onDidOpenEditorFail = this._onDidOpenEditorFail.event;
@ -524,6 +527,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
// Model Events
this._register(this.model.onDidModelChange(e => {
this._onDidModelChange.fire(e);
if (e.kind === GroupChangeKind.GROUP_LOCKED) {
this.onDidChangeGroupLocked();
return;
@ -828,6 +832,8 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
if (this._index !== newIndex) {
this._index = newIndex;
this._onDidGroupChange.fire({ kind: GroupChangeKind.GROUP_INDEX });
// TODO @lramos15 ENRICH THE MODEL TO LEARN ABOUT INDEX CHANGES THIS IS A HACK
this._onDidModelChange.fire({ kind: GroupChangeKind.GROUP_INDEX });
}
}

View file

@ -147,14 +147,12 @@ export class EditorService extends Disposable implements EditorServiceImpl {
private registerGroupListeners(group: IEditorGroupView): void {
const groupDisposables = new DisposableStore();
groupDisposables.add(group.onDidGroupChange(e => {
groupDisposables.add(group.onDidModelChange(e => {
switch (e.kind) {
case GroupChangeKind.EDITOR_ACTIVE:
if (group.activeEditor) {
this._onDidEditorsChange.fire([{ groupId: group.id, editor: group.activeEditor, kind: GroupChangeKind.EDITOR_ACTIVE }]);
}
this.handleActiveEditorChange(group);
this._onDidVisibleEditorsChange.fire();
break;
default:
this._onDidEditorsChange.fire([{ groupId: group.id, ...e }]);
@ -162,6 +160,15 @@ export class EditorService extends Disposable implements EditorServiceImpl {
}
}));
// Need to separatly listen to the group change for things like active editor changing
// as this doesn't always change the model (This could be a bug that needs more investigation)
groupDisposables.add(group.onDidGroupChange(e => {
if (e.kind === GroupChangeKind.EDITOR_ACTIVE) {
this.handleActiveEditorChange(group);
this._onDidVisibleEditorsChange.fire();
}
}));
groupDisposables.add(group.onDidCloseEditor(event => {
this._onDidCloseEditor.fire(event);
}));

View file

@ -470,6 +470,11 @@ export interface IEditorGroup {
*/
readonly onDidGroupChange: Event<IGroupChangeEvent>;
/**
* An event which fires whenever the underlying group model changes.
*/
readonly onDidModelChange: Event<IGroupChangeEvent>;
/**
* An event that is fired when the group gets disposed.
*/

View file

@ -816,6 +816,7 @@ export class TestEditorGroupView implements IEditorGroupView {
onWillDispose: Event<void> = Event.None;
onDidGroupChange: Event<IGroupChangeEvent> = Event.None;
onDidModelChange: Event<IGroupChangeEvent> = Event.None;
onWillCloseEditor: Event<IEditorCloseEvent> = Event.None;
onDidCloseEditor: Event<IEditorCloseEvent> = Event.None;
onDidOpenEditorFail: Event<EditorInput> = Event.None;