Adopt the model change events in favour of the group events (#139090)

* deprecate `onDidGroupChange`

* adopt `GROUP_LOCKED` from model

* adopt `GROUP_INDEX` from model

* adopt `GROUP_ACTIVE` from model

* adopt `EDITOR_PIN` from model

* adopt `EDITOR_STICKY` from model

* adopt `EDITOR_CAPABILITIES` from model

* adopt `EDITOR_LABEL` from model

* adopt `EDITOR_WILL_DISPOSE` from model

* adopt `EDITOR_DIRTY` from model

* adopt `EDITOR_MOVE` from model

* adopt `EDITOR_CLOSE` from model

* adopt `EDITOR_OPEN` from model

* adopt `EDITOR_ACTIVE` from model but also introduce new event

* remove onDidGroupChange

* group change => group model change

* fix regression with tracking empty editor area
This commit is contained in:
Benjamin Pasero 2021-12-15 19:03:40 +01:00 committed by GitHub
parent 36bb6a6848
commit cc76605726
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 279 additions and 273 deletions

View file

@ -7,7 +7,7 @@ import { DisposableStore } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { ExtHostContext, IExtHostEditorTabsShape, IExtHostContext, MainContext, IEditorTabDto } from 'vs/workbench/api/common/extHost.protocol';
import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
import { EditorResourceAccessor, IUntypedEditorInput, SideBySideEditor, GroupChangeKind } from 'vs/workbench/common/editor';
import { EditorResourceAccessor, IUntypedEditorInput, SideBySideEditor, GroupModelChangeKind } from 'vs/workbench/common/editor';
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
import { isGroupEditorCloseEvent, isGroupEditorMoveEvent, isGroupEditorOpenEvent } from 'vs/workbench/common/editor/editorGroupModel';
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
@ -157,7 +157,7 @@ export class MainThreadEditorTabs {
}
private _onDidGroupActivate(event: IEditorsChangeEvent): void {
if (event.kind !== GroupChangeKind.GROUP_INDEX && event.kind !== GroupChangeKind.EDITOR_ACTIVE) {
if (event.kind !== GroupModelChangeKind.GROUP_INDEX && event.kind !== GroupModelChangeKind.EDITOR_ACTIVE) {
return;
}
this._findAndUpdateActiveTab();
@ -188,15 +188,15 @@ export class MainThreadEditorTabs {
// let eventString = '[';
// events.forEach(event => {
// switch (event.kind) {
// case GroupChangeKind.GROUP_INDEX: eventString += 'GROUP_INDEX, '; break;
// case GroupChangeKind.EDITOR_ACTIVE: eventString += 'EDITOR_ACTIVE, '; break;
// case GroupChangeKind.EDITOR_PIN: eventString += 'EDITOR_PIN, '; break;
// case GroupChangeKind.EDITOR_OPEN: eventString += 'EDITOR_OPEN, '; break;
// case GroupChangeKind.EDITOR_CLOSE: eventString += 'EDITOR_CLOSE, '; break;
// case GroupChangeKind.EDITOR_MOVE: eventString += 'EDITOR_MOVE, '; break;
// case GroupChangeKind.EDITOR_LABEL: eventString += 'EDITOR_LABEL, '; break;
// case GroupChangeKind.GROUP_ACTIVE: eventString += 'GROUP_ACTIVE, '; break;
// case GroupChangeKind.GROUP_LOCKED: eventString += 'GROUP_LOCKED, '; break;
// case GroupModelChangeKind.GROUP_INDEX: eventString += 'GROUP_INDEX, '; break;
// case GroupModelChangeKind.EDITOR_ACTIVE: eventString += 'EDITOR_ACTIVE, '; break;
// case GroupModelChangeKind.EDITOR_PIN: eventString += 'EDITOR_PIN, '; break;
// case GroupModelChangeKind.EDITOR_OPEN: eventString += 'EDITOR_OPEN, '; break;
// case GroupModelChangeKind.EDITOR_CLOSE: eventString += 'EDITOR_CLOSE, '; break;
// case GroupModelChangeKind.EDITOR_MOVE: eventString += 'EDITOR_MOVE, '; break;
// case GroupModelChangeKind.EDITOR_LABEL: eventString += 'EDITOR_LABEL, '; break;
// case GroupModelChangeKind.GROUP_ACTIVE: eventString += 'GROUP_ACTIVE, '; break;
// case GroupModelChangeKind.GROUP_LOCKED: eventString += 'GROUP_LOCKED, '; break;
// default: eventString += 'UNKNOWN, '; break;
// }
// });
@ -212,24 +212,24 @@ export class MainThreadEditorTabs {
events.forEach(event => {
// Call the correct function for the change type
switch (event.kind) {
case GroupChangeKind.EDITOR_OPEN:
case GroupModelChangeKind.EDITOR_OPEN:
this._onDidTabOpen(event);
break;
case GroupChangeKind.EDITOR_CLOSE:
case GroupModelChangeKind.EDITOR_CLOSE:
this._onDidTabClose(event);
break;
case GroupChangeKind.EDITOR_ACTIVE:
case GroupChangeKind.GROUP_ACTIVE:
case GroupModelChangeKind.EDITOR_ACTIVE:
case GroupModelChangeKind.GROUP_ACTIVE:
if (this._editorGroupsService.activeGroup.id !== event.groupId) {
return;
}
this._onDidGroupActivate(event);
break;
case GroupChangeKind.GROUP_INDEX:
case GroupModelChangeKind.GROUP_INDEX:
this._createTabsModel();
// Here we stop the loop as no need to process other events
break;
case GroupChangeKind.EDITOR_MOVE:
case GroupModelChangeKind.EDITOR_MOVE:
this._onDidTabMove(event);
break;
default:

View file

@ -4,8 +4,8 @@
*--------------------------------------------------------------------------------------------*/
import 'vs/css!./media/editorgroupview';
import { EditorGroupModel, IEditorOpenOptions, IGroupChangeEvent, IGroupEditorCloseEvent, IGroupEditorMoveEvent, IGroupEditorOpenEvent, ISerializedEditorGroupModel, isGroupEditorCloseEvent, isGroupEditorMoveEvent, isGroupEditorOpenEvent, isSerializedEditorGroupModel } from 'vs/workbench/common/editor/editorGroupModel';
import { GroupIdentifier, CloseDirection, IEditorCloseEvent, ActiveEditorDirtyContext, IEditorPane, EditorGroupEditorsCountContext, SaveReason, IEditorPartOptionsChangeEvent, EditorsOrder, IVisibleEditorPane, ActiveEditorStickyContext, ActiveEditorPinnedContext, EditorResourceAccessor, EditorInputCapabilities, IUntypedEditorInput, DEFAULT_EDITOR_ASSOCIATION, ActiveEditorGroupLockedContext, SideBySideEditor, EditorCloseContext, IEditorWillMoveEvent, IEditorWillOpenEvent, IMatchEditorOptions, GroupChangeKind } from 'vs/workbench/common/editor';
import { EditorGroupModel, IEditorOpenOptions, IGroupModelChangeEvent, ISerializedEditorGroupModel, isGroupEditorCloseEvent, isGroupEditorOpenEvent, isSerializedEditorGroupModel } from 'vs/workbench/common/editor/editorGroupModel';
import { GroupIdentifier, CloseDirection, IEditorCloseEvent, ActiveEditorDirtyContext, IEditorPane, EditorGroupEditorsCountContext, SaveReason, IEditorPartOptionsChangeEvent, EditorsOrder, IVisibleEditorPane, ActiveEditorStickyContext, ActiveEditorPinnedContext, EditorResourceAccessor, EditorInputCapabilities, IUntypedEditorInput, DEFAULT_EDITOR_ASSOCIATION, ActiveEditorGroupLockedContext, SideBySideEditor, EditorCloseContext, IEditorWillMoveEvent, IEditorWillOpenEvent, IMatchEditorOptions, GroupModelChangeKind, IActiveEditorChangeEvent } from 'vs/workbench/common/editor';
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { SideBySideEditorInput } from 'vs/workbench/common/editor/sideBySideEditorInput';
import { Event, Emitter, Relay } from 'vs/base/common/event';
@ -87,12 +87,12 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
private readonly _onWillDispose = this._register(new Emitter<void>());
readonly onWillDispose = this._onWillDispose.event;
private readonly _onDidGroupChange = this._register(new Emitter<IGroupChangeEvent>());
readonly onDidGroupChange = this._onDidGroupChange.event;
private readonly _onDidModelChange = this._register(new Emitter<IGroupChangeEvent>());
private readonly _onDidModelChange = this._register(new Emitter<IGroupModelChangeEvent>());
readonly onDidModelChange = this._onDidModelChange.event;
private readonly _onDidActiveEditorChange = this._register(new Emitter<IActiveEditorChangeEvent>());
readonly onDidActiveEditorChange = this._onDidActiveEditorChange.event;
private readonly _onDidOpenEditorFail = this._register(new Emitter<EditorInput>());
readonly onDidOpenEditorFail = this._onDidOpenEditorFail.event;
@ -266,32 +266,33 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
};
// Update group contexts based on group changes
this._register(this.onDidGroupChange(e => {
this._register(this.onDidModelChange(e => {
switch (e.kind) {
case GroupChangeKind.EDITOR_ACTIVE:
// Track the active editor and update context key that reflects
// the dirty state of this editor
observeActiveEditor();
case GroupModelChangeKind.GROUP_LOCKED:
groupLockedContext.set(this.isLocked);
break;
case GroupChangeKind.EDITOR_PIN:
case GroupModelChangeKind.EDITOR_PIN:
if (e.editor && e.editor === this.model.activeEditor) {
groupActiveEditorPinnedContext.set(this.model.isPinned(this.model.activeEditor));
}
break;
case GroupChangeKind.EDITOR_STICKY:
case GroupModelChangeKind.EDITOR_STICKY:
if (e.editor && e.editor === this.model.activeEditor) {
groupActiveEditorStickyContext.set(this.model.isSticky(this.model.activeEditor));
}
break;
case GroupChangeKind.GROUP_LOCKED:
groupLockedContext.set(this.isLocked);
break;
}
// Group editors count context
groupEditorsCountContext.set(this.count);
}));
// Track the active editor and update context key that reflects
// the dirty state of this editor
this._register(this.onDidActiveEditorChange(() => {
observeActiveEditor();
}));
observeActiveEditor();
}
@ -535,76 +536,40 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
this._register(this.accessor.onDidVisibilityChange(e => this.onDidVisibilityChange(e)));
}
private onDidGroupModelChange(e: IGroupChangeEvent): void {
private onDidGroupModelChange(e: IGroupModelChangeEvent): void {
// Re-emit to outside
this._onDidModelChange.fire(e);
// Handle within
if (e.kind === GroupChangeKind.GROUP_LOCKED) {
this.onDidChangeGroupLocked();
return;
}
if (!e.editor) {
return;
}
switch (e.kind) {
case GroupChangeKind.EDITOR_PIN:
this.onDidChangeEditorPinned(e.editor);
break;
case GroupChangeKind.EDITOR_STICKY:
this.onDidChangeEditorSticky(e.editor);
break;
case GroupChangeKind.EDITOR_MOVE:
if (isGroupEditorMoveEvent(e)) {
this.onDidMoveEditor(e.editor, e.oldEditorIndex, e.editorIndex);
}
break;
case GroupChangeKind.EDITOR_OPEN:
case GroupModelChangeKind.EDITOR_OPEN:
if (isGroupEditorOpenEvent(e)) {
this.onDidOpenEditor(e.editor, e.editorIndex);
}
break;
case GroupChangeKind.EDITOR_CLOSE:
case GroupModelChangeKind.EDITOR_CLOSE:
if (isGroupEditorCloseEvent(e)) {
this.handleOnDidCloseEditor(e.editor, e.editorIndex, e.context, e.sticky);
}
break;
case GroupChangeKind.EDITOR_WILL_DISPOSE:
case GroupModelChangeKind.EDITOR_WILL_DISPOSE:
this.onWillDisposeEditor(e.editor);
break;
case GroupChangeKind.EDITOR_DIRTY:
case GroupModelChangeKind.EDITOR_DIRTY:
this.onDidChangeEditorDirty(e.editor);
break;
case GroupChangeKind.EDITOR_LABEL:
case GroupModelChangeKind.EDITOR_LABEL:
this.onDidChangeEditorLabel(e.editor);
break;
case GroupChangeKind.EDITOR_CAPABILITIES:
this.onDidChangeEditorCapabilities(e.editor);
break;
}
}
private onDidChangeGroupLocked(): void {
this._onDidGroupChange.fire({ kind: GroupChangeKind.GROUP_LOCKED });
}
private onDidChangeEditorPinned(editor: EditorInput): void {
this._onDidGroupChange.fire({ kind: GroupChangeKind.EDITOR_PIN, editor });
}
private onDidChangeEditorSticky(editor: EditorInput): void {
this._onDidGroupChange.fire({ kind: GroupChangeKind.EDITOR_STICKY, editor });
}
private onDidMoveEditor(editor: EditorInput, oldEditorIndex: number, editorIndex: number): void {
const event: IGroupEditorMoveEvent = { kind: GroupChangeKind.EDITOR_MOVE, editor, oldEditorIndex, editorIndex };
this._onDidGroupChange.fire(event);
}
private onDidOpenEditor(editor: EditorInput, editorIndex: number): void {
/* __GDPR__
@ -618,10 +583,6 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
// Update container
this.updateContainer();
// Event
const event: IGroupEditorOpenEvent = { kind: GroupChangeKind.EDITOR_OPEN, editor, editorIndex };
this._onDidGroupChange.fire(event);
}
private handleOnDidCloseEditor(editor: EditorInput, editorIndex: number, context: EditorCloseContext, sticky: boolean): void {
@ -661,8 +622,6 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
// Event
this._onDidCloseEditor.fire({ groupId: this.id, editor, context, index: editorIndex, sticky });
const event: IGroupEditorCloseEvent = { kind: GroupChangeKind.EDITOR_CLOSE, editor, editorIndex, context, sticky };
this._onDidGroupChange.fire(event);
}
private canDispose(editor: EditorInput): boolean {
@ -776,24 +735,12 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
// Forward to title control
this.titleAreaControl.updateEditorDirty(editor);
// Event
this._onDidGroupChange.fire({ kind: GroupChangeKind.EDITOR_DIRTY, editor });
}
private onDidChangeEditorLabel(editor: EditorInput): void {
// Forward to title control
this.titleAreaControl.updateEditorLabel(editor);
// Event
this._onDidGroupChange.fire({ kind: GroupChangeKind.EDITOR_LABEL, editor });
}
private onDidChangeEditorCapabilities(editor: EditorInput): void {
// Event
this._onDidGroupChange.fire({ kind: GroupChangeKind.EDITOR_CAPABILITIES, editor });
}
private onDidVisibilityChange(visible: boolean): void {
@ -843,8 +790,6 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
if (this._index !== newIndex) {
this._index = newIndex;
this.model.setIndex(newIndex);
this._onDidGroupChange.fire({ kind: GroupChangeKind.GROUP_INDEX });
}
}
@ -861,8 +806,8 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
// Update styles
this.updateStyles();
// Event
this._onDidGroupChange.fire({ kind: GroupChangeKind.GROUP_ACTIVE });
// Update model
this.model.setActive(undefined /* entire group got active */);
}
//#endregion
@ -1119,7 +1064,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
// Editor change event
if (changed) {
this._onDidGroupChange.fire({ kind: GroupChangeKind.EDITOR_ACTIVE, editor });
this._onDidActiveEditorChange.fire({ editor });
}
// Handle errors but do not bubble them up
@ -1535,7 +1480,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
}
// Events
this._onDidGroupChange.fire({ kind: GroupChangeKind.EDITOR_ACTIVE });
this._onDidActiveEditorChange.fire({ editor: undefined });
// Remove empty group if we should
if (closeEmptyGroup) {

View file

@ -11,7 +11,7 @@ import { contrastBorder, editorBackground } from 'vs/platform/theme/common/color
import { GroupDirection, IAddGroupOptions, GroupsArrangement, GroupOrientation, IMergeGroupOptions, MergeGroupMode, GroupsOrder, GroupLocation, IFindGroupScope, EditorGroupLayout, GroupLayoutArgument, IEditorGroupsService, IEditorSideGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IView, orthogonal, LayoutPriority, IViewSize, Direction, SerializableGrid, Sizing, ISerializedGrid, Orientation, GridBranchNode, isGridBranchNode, GridNode, createSerializedGrid, Grid } from 'vs/base/browser/ui/grid/grid';
import { GroupIdentifier, EditorInputWithOptions, IEditorPartOptions, IEditorPartOptionsChangeEvent, GroupChangeKind } from 'vs/workbench/common/editor';
import { GroupIdentifier, EditorInputWithOptions, IEditorPartOptions, IEditorPartOptionsChangeEvent, GroupModelChangeKind } from 'vs/workbench/common/editor';
import { EDITOR_GROUP_BORDER, EDITOR_PANE_BACKGROUND } from 'vs/workbench/common/theme';
import { distinct, coalesce, firstOrDefault } from 'vs/base/common/arrays';
import { IEditorGroupsAccessor, IEditorGroupView, getEditorPartOptions, impactsEditorPartOptions, IEditorPartCreationOptions } from 'vs/workbench/browser/parts/editor/editor';
@ -550,21 +550,23 @@ export class EditorPart extends Part implements IEditorGroupsService, IEditorGro
this.doSetGroupActive(groupView);
}));
// Track editor change
groupDisposables.add(groupView.onDidGroupChange(e => {
// Track group changes
groupDisposables.add(groupView.onDidModelChange(e => {
switch (e.kind) {
case GroupChangeKind.EDITOR_ACTIVE:
this.updateContainer();
break;
case GroupChangeKind.GROUP_INDEX:
this._onDidChangeGroupIndex.fire(groupView);
break;
case GroupChangeKind.GROUP_LOCKED:
case GroupModelChangeKind.GROUP_LOCKED:
this._onDidChangeGroupLocked.fire(groupView);
break;
case GroupModelChangeKind.GROUP_INDEX:
this._onDidChangeGroupIndex.fire(groupView);
break;
}
}));
// Track active editor change after it occurred
groupDisposables.add(groupView.onDidActiveEditorChange(() => {
this.updateContainer();
}));
// Track dispose
Event.once(groupView.onWillDispose)(() => {
dispose(groupDisposables);

View file

@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IEditorFactoryRegistry, IEditorIdentifier, GroupIdentifier, EditorExtensions, IEditorPartOptionsChangeEvent, EditorsOrder, GroupChangeKind } from 'vs/workbench/common/editor';
import { IEditorFactoryRegistry, IEditorIdentifier, GroupIdentifier, EditorExtensions, IEditorPartOptionsChangeEvent, EditorsOrder, GroupModelChangeKind } from 'vs/workbench/common/editor';
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { SideBySideEditorInput } from 'vs/workbench/common/editor/sideBySideEditorInput';
import { dispose, Disposable, DisposableStore } from 'vs/base/common/lifecycle';
@ -115,11 +115,11 @@ export class EditorsObserver extends Disposable {
private registerGroupListeners(group: IEditorGroup): void {
const groupDisposables = new DisposableStore();
groupDisposables.add(group.onDidGroupChange(e => {
groupDisposables.add(group.onDidModelChange(e => {
switch (e.kind) {
// Group gets active: put active editor as most recent
case GroupChangeKind.GROUP_ACTIVE: {
case GroupModelChangeKind.GROUP_ACTIVE: {
if (this.editorGroupsService.activeGroup === group && group.activeEditor) {
this.addMostRecentEditor(group, group.activeEditor, true /* is active */, false /* editor already opened */);
}
@ -127,21 +127,11 @@ export class EditorsObserver extends Disposable {
break;
}
// Editor gets active: put active editor as most recent
// if group is active, otherwise second most recent
case GroupChangeKind.EDITOR_ACTIVE: {
if (e.editor) {
this.addMostRecentEditor(group, e.editor, this.editorGroupsService.activeGroup === group, false /* editor already opened */);
}
break;
}
// Editor opens: put it as second most recent
//
// Also check for maximum allowed number of editors and
// start to close oldest ones if needed.
case GroupChangeKind.EDITOR_OPEN: {
case GroupModelChangeKind.EDITOR_OPEN: {
if (e.editor) {
this.addMostRecentEditor(group, e.editor, false /* is not active */, true /* is new */);
this.ensureOpenedEditorsLimit({ groupId: group.id, editor: e.editor }, group.id);
@ -149,15 +139,19 @@ export class EditorsObserver extends Disposable {
break;
}
}
}));
// Editor closes: remove from recently opened
case GroupChangeKind.EDITOR_CLOSE: {
if (e.editor) {
this.removeMostRecentEditor(group, e.editor);
}
// Editor closes: remove from recently opened
groupDisposables.add(group.onDidCloseEditor(e => {
this.removeMostRecentEditor(group, e.editor);
}));
break;
}
// Editor gets active: put active editor as most recent
// if group is active, otherwise second most recent
groupDisposables.add(group.onDidActiveEditorChange(e => {
if (e.editor) {
this.addMostRecentEditor(group, e.editor, this.editorGroupsService.activeGroup === group, false /* editor already opened */);
}
}));

View file

@ -785,6 +785,14 @@ export interface IEditorCloseEvent extends IEditorIdentifier {
readonly sticky: boolean;
}
export interface IActiveEditorChangeEvent {
/**
* The new active editor or `undefined` if the group is empty.
*/
editor: EditorInput | undefined;
}
export interface IEditorWillMoveEvent extends IEditorIdentifier {
/**
@ -823,7 +831,7 @@ export interface IEditorOpenEvent extends IEditorIdentifier {
export type GroupIdentifier = number;
export const enum GroupChangeKind {
export const enum GroupModelChangeKind {
/* Group Changes */
GROUP_ACTIVE,

View file

@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { Event, Emitter } from 'vs/base/common/event';
import { IEditorFactoryRegistry, GroupIdentifier, EditorsOrder, EditorExtensions, IUntypedEditorInput, SideBySideEditor, EditorCloseContext, IMatchEditorOptions, GroupChangeKind } from 'vs/workbench/common/editor';
import { IEditorFactoryRegistry, GroupIdentifier, EditorsOrder, EditorExtensions, IUntypedEditorInput, SideBySideEditor, EditorCloseContext, IMatchEditorOptions, GroupModelChangeKind } from 'vs/workbench/common/editor';
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { SideBySideEditorInput } from 'vs/workbench/common/editor/sideBySideEditorInput';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
@ -70,12 +70,12 @@ export interface IMatchOptions {
readonly strictEquals?: boolean;
}
export interface IGroupChangeEvent {
export interface IGroupModelChangeEvent {
/**
* The kind of change that occured in the group.
* The kind of change that occured in the group model.
*/
readonly kind: GroupChangeKind;
readonly kind: GroupModelChangeKind;
/**
* Only applies when editors change providing
@ -84,13 +84,13 @@ export interface IGroupChangeEvent {
readonly editor?: EditorInput;
}
export interface IGroupEditorChangeEvent extends IGroupChangeEvent {
export interface IGroupEditorChangeEvent extends IGroupModelChangeEvent {
readonly editor: EditorInput;
}
export interface IGroupEditorOpenEvent extends IGroupEditorChangeEvent {
readonly kind: GroupChangeKind.EDITOR_OPEN;
readonly kind: GroupModelChangeKind.EDITOR_OPEN;
/**
* Identifies the index of the editor in the group.
@ -98,15 +98,15 @@ export interface IGroupEditorOpenEvent extends IGroupEditorChangeEvent {
readonly editorIndex: number;
}
export function isGroupEditorOpenEvent(e: IGroupChangeEvent): e is IGroupEditorOpenEvent {
export function isGroupEditorOpenEvent(e: IGroupModelChangeEvent): e is IGroupEditorOpenEvent {
const candidate = e as IGroupEditorOpenEvent;
return candidate.kind === GroupChangeKind.EDITOR_OPEN && candidate.editorIndex !== undefined;
return candidate.kind === GroupModelChangeKind.EDITOR_OPEN && candidate.editorIndex !== undefined;
}
export interface IGroupEditorMoveEvent extends IGroupEditorChangeEvent {
readonly kind: GroupChangeKind.EDITOR_MOVE;
readonly kind: GroupModelChangeKind.EDITOR_MOVE;
/**
* Identifies the index of the editor in the group.
@ -121,15 +121,15 @@ export interface IGroupEditorMoveEvent extends IGroupEditorChangeEvent {
readonly oldEditorIndex: number;
}
export function isGroupEditorMoveEvent(e: IGroupChangeEvent): e is IGroupEditorMoveEvent {
export function isGroupEditorMoveEvent(e: IGroupModelChangeEvent): e is IGroupEditorMoveEvent {
const candidate = e as IGroupEditorMoveEvent;
return candidate.kind === GroupChangeKind.EDITOR_MOVE && candidate.editorIndex !== undefined && candidate.oldEditorIndex !== undefined;
return candidate.kind === GroupModelChangeKind.EDITOR_MOVE && candidate.editorIndex !== undefined && candidate.oldEditorIndex !== undefined;
}
export interface IGroupEditorCloseEvent extends IGroupEditorChangeEvent {
readonly kind: GroupChangeKind.EDITOR_CLOSE;
readonly kind: GroupModelChangeKind.EDITOR_CLOSE;
/**
* Identifies the index of the editor in the group.
@ -151,10 +151,10 @@ export interface IGroupEditorCloseEvent extends IGroupEditorChangeEvent {
readonly sticky: boolean;
}
export function isGroupEditorCloseEvent(e: IGroupChangeEvent): e is IGroupEditorCloseEvent {
export function isGroupEditorCloseEvent(e: IGroupModelChangeEvent): e is IGroupEditorCloseEvent {
const candidate = e as IGroupEditorCloseEvent;
return candidate.kind === GroupChangeKind.EDITOR_CLOSE && candidate.editorIndex !== undefined && candidate.context !== undefined && candidate.sticky !== undefined;
return candidate.kind === GroupModelChangeKind.EDITOR_CLOSE && candidate.editorIndex !== undefined && candidate.context !== undefined && candidate.sticky !== undefined;
}
interface IEditorCloseResult {
@ -170,7 +170,7 @@ export class EditorGroupModel extends Disposable {
//#region events
private readonly _onDidModelChange = this._register(new Emitter<IGroupChangeEvent>());
private readonly _onDidModelChange = this._register(new Emitter<IGroupModelChangeEvent>());
readonly onDidModelChange = this._onDidModelChange.event;
//#endregion
@ -351,7 +351,7 @@ export class EditorGroupModel extends Disposable {
// Event
const event: IGroupEditorOpenEvent = {
kind: GroupChangeKind.EDITOR_OPEN,
kind: GroupModelChangeKind.EDITOR_OPEN,
editor: newEditor,
editorIndex: targetIndex
};
@ -407,7 +407,7 @@ export class EditorGroupModel extends Disposable {
listeners.add(Event.once(editor.onWillDispose)(() => {
if (this.indexOf(editor) >= 0) {
this._onDidModelChange.fire({
kind: GroupChangeKind.EDITOR_WILL_DISPOSE,
kind: GroupModelChangeKind.EDITOR_WILL_DISPOSE,
editor
});
}
@ -416,7 +416,7 @@ export class EditorGroupModel extends Disposable {
// Re-Emit dirty state changes
listeners.add(editor.onDidChangeDirty(() => {
this._onDidModelChange.fire({
kind: GroupChangeKind.EDITOR_DIRTY,
kind: GroupModelChangeKind.EDITOR_DIRTY,
editor
});
}));
@ -424,7 +424,7 @@ export class EditorGroupModel extends Disposable {
// Re-Emit label changes
listeners.add(editor.onDidChangeLabel(() => {
this._onDidModelChange.fire({
kind: GroupChangeKind.EDITOR_LABEL,
kind: GroupModelChangeKind.EDITOR_LABEL,
editor
});
}));
@ -432,14 +432,14 @@ export class EditorGroupModel extends Disposable {
// Re-Emit capability changes
listeners.add(editor.onDidChangeCapabilities(() => {
this._onDidModelChange.fire({
kind: GroupChangeKind.EDITOR_CAPABILITIES,
kind: GroupModelChangeKind.EDITOR_CAPABILITIES,
editor
});
}));
// Clean up dispose listeners once the editor gets closed
listeners.add(this.onDidModelChange(event => {
if (event.kind === GroupChangeKind.EDITOR_CLOSE && event.editor?.matches(editor)) {
if (event.kind === GroupModelChangeKind.EDITOR_CLOSE && event.editor?.matches(editor)) {
dispose(listeners);
}
}));
@ -455,7 +455,7 @@ export class EditorGroupModel extends Disposable {
if (closeResult) {
const event: IGroupEditorCloseEvent = {
kind: GroupChangeKind.EDITOR_CLOSE,
kind: GroupModelChangeKind.EDITOR_CLOSE,
...closeResult
};
this._onDidModelChange.fire(event);
@ -467,7 +467,7 @@ export class EditorGroupModel extends Disposable {
if (closeResult) {
const event: IGroupEditorCloseEvent = {
kind: GroupChangeKind.EDITOR_CLOSE,
kind: GroupModelChangeKind.EDITOR_CLOSE,
...closeResult
};
this._onDidModelChange.fire(event);
@ -556,7 +556,7 @@ export class EditorGroupModel extends Disposable {
// Event
const event: IGroupEditorMoveEvent = {
kind: GroupChangeKind.EDITOR_MOVE,
kind: GroupModelChangeKind.EDITOR_MOVE,
editor,
oldEditorIndex: index,
editorIndex: toIndex,
@ -566,7 +566,27 @@ export class EditorGroupModel extends Disposable {
return editor;
}
setActive(candidate: EditorInput): EditorInput | undefined {
setActive(candidate: EditorInput | undefined): EditorInput | undefined {
let result: EditorInput | undefined = undefined;
if (!candidate) {
this.setGroupActive();
} else {
result = this.setEditorActive(candidate);
}
return result;
}
private setGroupActive(): void {
// We do not really keep the `active` state in our model because
// it has no special meaning to us here. But for consistency
// we emit a `onDidModelChange` event so that components can
// react.
this._onDidModelChange.fire({ kind: GroupModelChangeKind.GROUP_ACTIVE });
}
private setEditorActive(candidate: EditorInput): EditorInput | undefined {
const res = this.findEditor(candidate);
if (!res) {
return; // not found
@ -593,7 +613,7 @@ export class EditorGroupModel extends Disposable {
// Event
this._onDidModelChange.fire({
kind: GroupChangeKind.EDITOR_ACTIVE,
kind: GroupModelChangeKind.EDITOR_ACTIVE,
editor
});
}
@ -603,7 +623,7 @@ export class EditorGroupModel extends Disposable {
// it has no special meaning to us here. But for consistency
// we emit a `onDidModelChange` event so that components can
// react.
this._onDidModelChange.fire({ kind: GroupChangeKind.GROUP_INDEX });
this._onDidModelChange.fire({ kind: GroupModelChangeKind.GROUP_INDEX });
}
pin(candidate: EditorInput): EditorInput | undefined {
@ -629,7 +649,7 @@ export class EditorGroupModel extends Disposable {
// Event
this._onDidModelChange.fire({
kind: GroupChangeKind.EDITOR_PIN,
kind: GroupModelChangeKind.EDITOR_PIN,
editor
});
}
@ -658,7 +678,7 @@ export class EditorGroupModel extends Disposable {
// Event
this._onDidModelChange.fire({
kind: GroupChangeKind.EDITOR_PIN,
kind: GroupModelChangeKind.EDITOR_PIN,
editor
});
@ -708,7 +728,7 @@ export class EditorGroupModel extends Disposable {
// Event
this._onDidModelChange.fire({
kind: GroupChangeKind.EDITOR_STICKY,
kind: GroupModelChangeKind.EDITOR_STICKY,
editor
});
}
@ -739,7 +759,7 @@ export class EditorGroupModel extends Disposable {
// Event
this._onDidModelChange.fire({
kind: GroupChangeKind.EDITOR_STICKY,
kind: GroupModelChangeKind.EDITOR_STICKY,
editor
});
}
@ -892,7 +912,7 @@ export class EditorGroupModel extends Disposable {
if (this.isLocked !== locked) {
this.locked = locked;
this._onDidModelChange.fire({ kind: GroupChangeKind.GROUP_LOCKED });
this._onDidModelChange.fire({ kind: GroupModelChangeKind.GROUP_LOCKED });
}
}

View file

@ -13,7 +13,7 @@ import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiati
import { IEditorGroupsService, IEditorGroup, GroupsOrder, GroupOrientation } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { Verbosity, EditorResourceAccessor, SideBySideEditor, EditorInputCapabilities, IEditorIdentifier, GroupChangeKind } from 'vs/workbench/common/editor';
import { Verbosity, EditorResourceAccessor, SideBySideEditor, EditorInputCapabilities, IEditorIdentifier, GroupModelChangeKind } from 'vs/workbench/common/editor';
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { SaveAllInGroupAction, CloseGroupAction } from 'vs/workbench/contrib/files/browser/fileActions';
import { OpenEditorsFocusedContext, ExplorerFocusedContext, IFilesConfiguration, OpenEditor } from 'vs/workbench/contrib/files/common/files';
@ -138,7 +138,7 @@ export class OpenEditorsView extends ViewPane {
const groupDisposables = new Map<number, IDisposable>();
const addGroupListener = (group: IEditorGroup) => {
groupDisposables.set(group.id, group.onDidGroupChange(e => {
const groupModelChangeListener = group.onDidModelChange(e => {
if (this.listRefreshScheduler.isScheduled()) {
return;
}
@ -149,34 +149,31 @@ export class OpenEditorsView extends ViewPane {
const index = this.getIndex(group, e.editor);
switch (e.kind) {
case GroupChangeKind.GROUP_INDEX: {
case GroupModelChangeKind.EDITOR_ACTIVE:
case GroupModelChangeKind.GROUP_ACTIVE:
this.focusActiveEditor();
break;
case GroupModelChangeKind.GROUP_INDEX:
if (index >= 0) {
this.list.splice(index, 1, [group]);
}
break;
}
case GroupChangeKind.GROUP_ACTIVE:
case GroupChangeKind.EDITOR_ACTIVE: {
this.focusActiveEditor();
break;
}
case GroupChangeKind.EDITOR_DIRTY:
case GroupChangeKind.EDITOR_LABEL:
case GroupChangeKind.EDITOR_CAPABILITIES:
case GroupChangeKind.EDITOR_STICKY:
case GroupChangeKind.EDITOR_PIN: {
case GroupModelChangeKind.EDITOR_DIRTY:
case GroupModelChangeKind.EDITOR_STICKY:
case GroupModelChangeKind.EDITOR_CAPABILITIES:
case GroupModelChangeKind.EDITOR_PIN:
case GroupModelChangeKind.EDITOR_LABEL:
this.list.splice(index, 1, [new OpenEditor(e.editor!, group)]);
this.focusActiveEditor();
break;
}
case GroupChangeKind.EDITOR_OPEN:
case GroupChangeKind.EDITOR_CLOSE:
case GroupChangeKind.EDITOR_MOVE: {
case GroupModelChangeKind.EDITOR_OPEN:
case GroupModelChangeKind.EDITOR_MOVE:
case GroupModelChangeKind.EDITOR_CLOSE:
updateWholeList();
break;
}
}
}));
});
groupDisposables.set(group.id, groupModelChangeListener);
this._register(groupDisposables.get(group.id)!);
};

View file

@ -140,7 +140,7 @@ export class NotebookEditor extends EditorPane {
if (group) {
this._groupListener.clear();
this._groupListener.add(group.onWillCloseEditor(e => this._saveEditorViewState(e.editor)));
this._groupListener.add(group.onDidGroupChange(() => {
this._groupListener.add(group.onDidModelChange(() => {
if (this._editorGroupService.activeGroup !== group) {
this._widget?.value?.updateEditorFocus();
}

View file

@ -13,7 +13,7 @@ import { IBorrowValue, INotebookEditorService } from 'vs/workbench/contrib/noteb
import { INotebookEditor, INotebookEditorCreationOptions } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { Emitter } from 'vs/base/common/event';
import { INotebookDecorationRenderOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { GroupIdentifier, GroupChangeKind } from 'vs/workbench/common/editor';
import { GroupIdentifier } from 'vs/workbench/common/editor';
export class NotebookEditorWidgetService implements INotebookEditorService {
@ -40,9 +40,9 @@ export class NotebookEditorWidgetService implements INotebookEditorService {
const onNewGroup = (group: IEditorGroup) => {
const { id } = group;
const listeners: IDisposable[] = [];
listeners.push(group.onDidGroupChange(e => {
listeners.push(group.onDidCloseEditor(e => {
const widgets = this._borrowableEditors.get(group.id);
if (!widgets || e.kind !== GroupChangeKind.EDITOR_CLOSE) {
if (!widgets) {
return;
}

View file

@ -5,7 +5,7 @@
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IResourceEditorInput, IEditorOptions, EditorActivation, EditorResolution, IResourceEditorInputIdentifier, ITextResourceEditorInput } from 'vs/platform/editor/common/editor';
import { SideBySideEditor, IEditorPane, GroupIdentifier, IUntitledTextResourceEditorInput, IResourceDiffEditorInput, EditorInputWithOptions, isEditorInputWithOptions, IEditorIdentifier, IEditorCloseEvent, ITextDiffEditorPane, IRevertOptions, SaveReason, EditorsOrder, IWorkbenchEditorConfiguration, EditorResourceAccessor, IVisibleEditorPane, EditorInputCapabilities, isResourceDiffEditorInput, IUntypedEditorInput, isResourceEditorInput, isEditorInput, isEditorInputWithOptionsAndGroup, GroupChangeKind } from 'vs/workbench/common/editor';
import { SideBySideEditor, IEditorPane, GroupIdentifier, IUntitledTextResourceEditorInput, IResourceDiffEditorInput, EditorInputWithOptions, isEditorInputWithOptions, IEditorIdentifier, IEditorCloseEvent, ITextDiffEditorPane, IRevertOptions, SaveReason, EditorsOrder, IWorkbenchEditorConfiguration, EditorResourceAccessor, IVisibleEditorPane, EditorInputCapabilities, isResourceDiffEditorInput, IUntypedEditorInput, isResourceEditorInput, isEditorInput, isEditorInputWithOptionsAndGroup } from 'vs/workbench/common/editor';
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { SideBySideEditorInput } from 'vs/workbench/common/editor/sideBySideEditorInput';
import { ResourceMap } from 'vs/base/common/map';
@ -151,14 +151,9 @@ export class EditorService extends Disposable implements EditorServiceImpl {
this._onDidEditorsChange.fire([{ groupId: group.id, ...e }]);
}));
groupDisposables.add(group.onDidGroupChange(e => {
// TODO@lramos15 TODO@bpasero revisit the need for listening to
// this event specifically vs. using the `onDidModelChange` event
// https://github.com/microsoft/vscode/issues/138200
if (e.kind === GroupChangeKind.EDITOR_ACTIVE) {
this.handleActiveEditorChange(group);
this._onDidVisibleEditorsChange.fire();
}
groupDisposables.add(group.onDidActiveEditorChange(() => {
this.handleActiveEditorChange(group);
this._onDidVisibleEditorsChange.fire();
}));
groupDisposables.add(group.onDidCloseEditor(e => {

View file

@ -5,7 +5,7 @@
import { Event } from 'vs/base/common/event';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IEditorPane, GroupIdentifier, EditorInputWithOptions, CloseDirection, IEditorPartOptions, IEditorPartOptionsChangeEvent, EditorsOrder, IVisibleEditorPane, IEditorCloseEvent, IUntypedEditorInput, isEditorInput, IEditorWillMoveEvent, IEditorWillOpenEvent, IMatchEditorOptions } from 'vs/workbench/common/editor';
import { IEditorPane, GroupIdentifier, EditorInputWithOptions, CloseDirection, IEditorPartOptions, IEditorPartOptionsChangeEvent, EditorsOrder, IVisibleEditorPane, IEditorCloseEvent, IUntypedEditorInput, isEditorInput, IEditorWillMoveEvent, IEditorWillOpenEvent, IMatchEditorOptions, IActiveEditorChangeEvent } from 'vs/workbench/common/editor';
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { IEditorOptions } from 'vs/platform/editor/common/editor';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
@ -13,7 +13,7 @@ import { IDimension } from 'vs/editor/common/editorCommon';
import { IDisposable } from 'vs/base/common/lifecycle';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { URI } from 'vs/base/common/uri';
import { IGroupChangeEvent } from 'vs/workbench/common/editor/editorGroupModel';
import { IGroupModelChangeEvent } from 'vs/workbench/common/editor/editorGroupModel';
export const IEditorGroupsService = createDecorator<IEditorGroupsService>('editorGroupsService');
@ -404,26 +404,31 @@ export const enum OpenEditorContext {
export interface IEditorGroup {
/**
* An aggregated event for when the group changes in any way.
*/
readonly onDidGroupChange: Event<IGroupChangeEvent>;
/**
* An event which fires whenever the underlying group model changes.
*/
readonly onDidModelChange: Event<IGroupChangeEvent>;
readonly onDidModelChange: Event<IGroupModelChangeEvent>;
/**
* An event that is fired when the group gets disposed.
*/
readonly onWillDispose: Event<void>;
/**
* An event that is fired when the active editor in the group changed.
*/
readonly onDidActiveEditorChange: Event<IActiveEditorChangeEvent>;
/**
* An event that is fired when an editor is about to close.
*/
readonly onWillCloseEditor: Event<IEditorCloseEvent>;
/**
* An event that is fired when an editor is closed.
*/
readonly onDidCloseEditor: Event<IEditorCloseEvent>;
/**
* An event that is fired when an editor is about to move to
* a different group.
@ -453,7 +458,7 @@ export interface IEditorGroup {
/**
* A human readable label for the group. This label can change depending
* on the layout of all editor groups. Clients should listen on the
* `onDidGroupChange` event to react to that.
* `onDidGroupModelChange` event to react to that.
*/
readonly label: string;

View file

@ -11,7 +11,7 @@ import { Event } from 'vs/base/common/event';
import { IEditor, IDiffEditor } from 'vs/editor/common/editorCommon';
import { IEditorGroup, IEditorReplacement, isEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
import { URI } from 'vs/base/common/uri';
import { IGroupChangeEvent } from 'vs/workbench/common/editor/editorGroupModel';
import { IGroupModelChangeEvent } from 'vs/workbench/common/editor/editorGroupModel';
export const IEditorService = createDecorator<IEditorService>('editorService');
@ -80,7 +80,7 @@ export interface IOpenEditorsOptions {
readonly validateTrust?: boolean;
}
export interface IEditorsChangeEvent extends IGroupChangeEvent {
export interface IEditorsChangeEvent extends IGroupModelChangeEvent {
groupId: GroupIdentifier;
}

View file

@ -6,7 +6,7 @@
import * as assert from 'assert';
import { workbenchInstantiationService, registerTestEditor, TestFileEditorInput, TestEditorPart, ITestInstantiationService, TestServiceAccessor, createEditorPart } from 'vs/workbench/test/browser/workbenchTestServices';
import { GroupDirection, GroupsOrder, MergeGroupMode, GroupOrientation, GroupLocation, isEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { CloseDirection, IEditorPartOptions, EditorsOrder, EditorInputCapabilities, GroupChangeKind } from 'vs/workbench/common/editor';
import { CloseDirection, IEditorPartOptions, EditorsOrder, EditorInputCapabilities, GroupModelChangeKind } from 'vs/workbench/common/editor';
import { URI } from 'vs/base/common/uri';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { DisposableStore } from 'vs/base/common/lifecycle';
@ -15,7 +15,7 @@ import { ConfirmResult } from 'vs/platform/dialogs/common/dialogs';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { SideBySideEditorInput } from 'vs/workbench/common/editor/sideBySideEditorInput';
import { IGroupChangeEvent, IGroupEditorMoveEvent, IGroupEditorOpenEvent } from 'vs/workbench/common/editor/editorGroupModel';
import { IGroupModelChangeEvent, IGroupEditorMoveEvent, IGroupEditorOpenEvent } from 'vs/workbench/common/editor/editorGroupModel';
suite('EditorGroupsService', () => {
@ -43,9 +43,9 @@ suite('EditorGroupsService', () => {
const instantiationService = workbenchInstantiationService({ contextKeyService: instantiationService => instantiationService.createInstance(MockScopableContextKeyService) }, disposables);
const [part] = await createPart(instantiationService);
let activeGroupChangeCounter = 0;
const activeGroupChangeListener = part.onDidChangeActiveGroup(() => {
activeGroupChangeCounter++;
let activeGroupModelChangeCounter = 0;
const activeGroupModelChangeListener = part.onDidChangeActiveGroup(() => {
activeGroupModelChangeCounter++;
});
let groupAddedCounter = 0;
@ -90,30 +90,30 @@ suite('EditorGroupsService', () => {
assert.strictEqual(mru[0], rootGroup);
assert.strictEqual(mru[1], rightGroup);
assert.strictEqual(activeGroupChangeCounter, 0);
assert.strictEqual(activeGroupModelChangeCounter, 0);
let rootGroupActiveChangeCounter = 0;
const rootGroupChangeListener = rootGroup.onDidGroupChange(e => {
if (e.kind === GroupChangeKind.GROUP_ACTIVE) {
const rootGroupModelChangeListener = rootGroup.onDidModelChange(e => {
if (e.kind === GroupModelChangeKind.GROUP_ACTIVE) {
rootGroupActiveChangeCounter++;
}
});
let rightGroupActiveChangeCounter = 0;
const rightGroupChangeListener = rightGroup.onDidGroupChange(e => {
if (e.kind === GroupChangeKind.GROUP_ACTIVE) {
const rightGroupModelChangeListener = rightGroup.onDidModelChange(e => {
if (e.kind === GroupModelChangeKind.GROUP_ACTIVE) {
rightGroupActiveChangeCounter++;
}
});
part.activateGroup(rightGroup);
assert.ok(part.activeGroup === rightGroup);
assert.strictEqual(activeGroupChangeCounter, 1);
assert.strictEqual(activeGroupModelChangeCounter, 1);
assert.strictEqual(rootGroupActiveChangeCounter, 1);
assert.strictEqual(rightGroupActiveChangeCounter, 1);
rootGroupChangeListener.dispose();
rightGroupChangeListener.dispose();
rootGroupModelChangeListener.dispose();
rightGroupModelChangeListener.dispose();
mru = part.getGroups(GroupsOrder.MOST_RECENTLY_ACTIVE);
assert.strictEqual(mru.length, 2);
@ -188,7 +188,7 @@ suite('EditorGroupsService', () => {
part.setGroupOrientation(part.orientation === GroupOrientation.HORIZONTAL ? GroupOrientation.VERTICAL : GroupOrientation.HORIZONTAL);
activeGroupChangeListener.dispose();
activeGroupModelChangeListener.dispose();
groupAddedListener.dispose();
groupRemovedListener.dispose();
groupMovedListener.dispose();
@ -254,8 +254,8 @@ suite('EditorGroupsService', () => {
});
let indexChangeCounter = 0;
const labelChangeListener = downGroup.onDidGroupChange(e => {
if (e.kind === GroupChangeKind.GROUP_INDEX) {
const labelChangeListener = downGroup.onDidModelChange(e => {
if (e.kind === GroupModelChangeKind.GROUP_INDEX) {
indexChangeCounter++;
}
});
@ -401,35 +401,36 @@ suite('EditorGroupsService', () => {
let activeEditorChangeCounter = 0;
let editorDidOpenCounter = 0;
const editorOpenEvents: IGroupChangeEvent[] = [];
const editorOpenEvents: IGroupModelChangeEvent[] = [];
let editorCloseCounter = 0;
const editorCloseEvents: IGroupChangeEvent[] = [];
const editorCloseEvents: IGroupModelChangeEvent[] = [];
let editorPinCounter = 0;
let editorStickyCounter = 0;
let editorCapabilitiesCounter = 0;
const editorGroupChangeListener = group.onDidGroupChange(e => {
if (e.kind === GroupChangeKind.EDITOR_OPEN) {
const editorGroupModelChangeListener = group.onDidModelChange(e => {
if (e.kind === GroupModelChangeKind.EDITOR_OPEN) {
assert.ok(e.editor);
editorDidOpenCounter++;
editorOpenEvents.push(e);
} else if (e.kind === GroupChangeKind.EDITOR_ACTIVE) {
} else if (e.kind === GroupModelChangeKind.EDITOR_PIN) {
assert.ok(e.editor);
activeEditorChangeCounter++;
} else if (e.kind === GroupChangeKind.EDITOR_CLOSE) {
editorPinCounter++;
} else if (e.kind === GroupModelChangeKind.EDITOR_STICKY) {
assert.ok(e.editor);
editorStickyCounter++;
} else if (e.kind === GroupModelChangeKind.EDITOR_CAPABILITIES) {
assert.ok(e.editor);
editorCapabilitiesCounter++;
} else if (e.kind === GroupModelChangeKind.EDITOR_CLOSE) {
assert.ok(e.editor);
editorCloseCounter++;
editorCloseEvents.push(e);
} else if (e.kind === GroupChangeKind.EDITOR_PIN) {
assert.ok(e.editor);
editorPinCounter++;
} else if (e.kind === GroupChangeKind.EDITOR_CAPABILITIES) {
assert.ok(e.editor);
editorCapabilitiesCounter++;
} else if (e.kind === GroupChangeKind.EDITOR_STICKY) {
assert.ok(e.editor);
editorStickyCounter++;
}
});
const activeEditorChangeListener = group.onDidActiveEditorChange(e => {
assert.ok(e.editor);
activeEditorChangeCounter++;
});
let editorCloseCounter1 = 0;
const editorCloseListener = group.onDidCloseEditor(() => {
@ -441,6 +442,11 @@ suite('EditorGroupsService', () => {
editorWillCloseCounter++;
});
let editorDidCloseCounter = 0;
const editorDidCloseListener = group.onDidCloseEditor(() => {
editorDidCloseCounter++;
});
const input = new TestFileEditorInput(URI.file('foo/bar'), TEST_EDITOR_INPUT_ID);
const inputInactive = new TestFileEditorInput(URI.file('foo/bar/inactive'), TEST_EDITOR_INPUT_ID);
@ -500,6 +506,7 @@ suite('EditorGroupsService', () => {
assert.strictEqual(editorCloseEvents[0].editor, inputInactive);
assert.strictEqual(editorCloseCounter1, 1);
assert.strictEqual(editorWillCloseCounter, 1);
assert.strictEqual(editorDidCloseCounter, 1);
assert.ok(inputInactive.gotDisposed);
@ -513,7 +520,9 @@ suite('EditorGroupsService', () => {
editorCloseListener.dispose();
editorWillCloseListener.dispose();
editorGroupChangeListener.dispose();
editorDidCloseListener.dispose();
activeEditorChangeListener.dispose();
editorGroupModelChangeListener.dispose();
});
test('openEditors / closeEditors', async () => {
@ -939,9 +948,9 @@ suite('EditorGroupsService', () => {
const input = new TestFileEditorInput(URI.file('foo/bar'), TEST_EDITOR_INPUT_ID);
const inputInactive = new TestFileEditorInput(URI.file('foo/bar/inactive'), TEST_EDITOR_INPUT_ID);
const moveEvents: IGroupChangeEvent[] = [];
const editorGroupChangeListener = group.onDidGroupChange(e => {
if (e.kind === GroupChangeKind.EDITOR_MOVE) {
const moveEvents: IGroupModelChangeEvent[] = [];
const editorGroupModelChangeListener = group.onDidModelChange(e => {
if (e.kind === GroupModelChangeKind.EDITOR_MOVE) {
assert.ok(e.editor);
moveEvents.push(e);
}
@ -967,7 +976,7 @@ suite('EditorGroupsService', () => {
assert.strictEqual(group.getEditorByIndex(0), input);
assert.strictEqual(group.getEditorByIndex(1), inputInactive);
editorGroupChangeListener.dispose();
editorGroupModelChangeListener.dispose();
});
test('moveEditor (across groups)', async () => {
@ -1312,8 +1321,8 @@ suite('EditorGroupsService', () => {
assert.strictEqual(group.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE, { excludeSticky: true }).length, 2);
let editorMoveCounter = 0;
const editorGroupChangeListener = group.onDidGroupChange(e => {
if (e.kind === GroupChangeKind.EDITOR_MOVE) {
const editorGroupModelChangeListener = group.onDidModelChange(e => {
if (e.kind === GroupModelChangeKind.EDITOR_MOVE) {
assert.ok(e.editor);
editorMoveCounter++;
}
@ -1358,7 +1367,7 @@ suite('EditorGroupsService', () => {
assert.strictEqual(group.getIndexOfEditor(inputSticky), 1);
assert.strictEqual(group.getIndexOfEditor(input), 2);
editorGroupChangeListener.dispose();
editorGroupModelChangeListener.dispose();
});
test('moveEditor with context (across groups)', async () => {
@ -1480,15 +1489,15 @@ suite('EditorGroupsService', () => {
});
let leftFiredCountFromGroup = 0;
const leftGroupListener = group.onDidGroupChange(e => {
if (e.kind === GroupChangeKind.GROUP_LOCKED) {
const leftGroupListener = group.onDidModelChange(e => {
if (e.kind === GroupModelChangeKind.GROUP_LOCKED) {
leftFiredCountFromGroup++;
}
});
let rightFiredCountFromGroup = 0;
const rightGroupListener = rightGroup.onDidGroupChange(e => {
if (e.kind === GroupChangeKind.GROUP_LOCKED) {
const rightGroupListener = rightGroup.onDidModelChange(e => {
if (e.kind === GroupModelChangeKind.GROUP_LOCKED) {
rightFiredCountFromGroup++;
}
});

View file

@ -9,7 +9,7 @@ import { IProgressRunner, IProgressIndicator, emptyProgressRunner } from 'vs/pla
import { IEditorGroupView } from 'vs/workbench/browser/parts/editor/editor';
import { IViewsService } from 'vs/workbench/common/views';
import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/browser/panecomposite';
import { GroupChangeKind } from 'vs/workbench/common/editor';
import { GroupModelChangeKind } from 'vs/workbench/common/editor';
class ProgressBarIndicator extends Disposable implements IProgressIndicator {
@ -77,8 +77,8 @@ export class EditorProgressIndicator extends ProgressBarIndicator {
// track active editor progress and replay it later (yet).
this._register(this.group.onDidModelChange(e => {
if (
e.kind === GroupChangeKind.EDITOR_ACTIVE ||
(e.kind === GroupChangeKind.EDITOR_CLOSE && this.group.isEmpty)
e.kind === GroupModelChangeKind.EDITOR_ACTIVE ||
(e.kind === GroupModelChangeKind.EDITOR_CLOSE && this.group.isEmpty)
) {
this.progressbar.stop().hide();
}

View file

@ -5,7 +5,7 @@
import * as assert from 'assert';
import { EditorGroupModel, ISerializedEditorGroupModel, isGroupEditorCloseEvent, isGroupEditorMoveEvent, isGroupEditorOpenEvent } from 'vs/workbench/common/editor/editorGroupModel';
import { EditorExtensions, IEditorFactoryRegistry, IFileEditorInput, IEditorSerializer, CloseDirection, EditorsOrder, IResourceDiffEditorInput, IResourceSideBySideEditorInput, SideBySideEditor, EditorCloseContext, IEditorCloseEvent, IEditorOpenEvent, IEditorMoveEvent, GroupChangeKind } from 'vs/workbench/common/editor';
import { EditorExtensions, IEditorFactoryRegistry, IFileEditorInput, IEditorSerializer, CloseDirection, EditorsOrder, IResourceDiffEditorInput, IResourceSideBySideEditorInput, SideBySideEditor, EditorCloseContext, IEditorCloseEvent, IEditorOpenEvent, IEditorMoveEvent, GroupModelChangeKind } from 'vs/workbench/common/editor';
import { URI } from 'vs/base/common/uri';
import { TestLifecycleService, workbenchInstantiationService } from 'vs/workbench/test/browser/workbenchTestServices';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
@ -80,6 +80,8 @@ suite('EditorGroupModel', () => {
interface GroupEvents {
locked: number[],
active: number[],
index: number[],
opened: IEditorOpenEvent[];
activated: EditorInput[];
closed: IEditorCloseEvent[];
@ -93,6 +95,8 @@ suite('EditorGroupModel', () => {
function groupListener(group: EditorGroupModel): GroupEvents {
const groupEvents: GroupEvents = {
active: [],
index: [],
locked: [],
opened: [],
closed: [],
@ -106,39 +110,45 @@ suite('EditorGroupModel', () => {
};
group.onDidModelChange(e => {
if (e.kind === GroupChangeKind.GROUP_LOCKED) {
if (e.kind === GroupModelChangeKind.GROUP_LOCKED) {
groupEvents.locked.push(group.id);
return;
} else if (e.kind === GroupModelChangeKind.GROUP_ACTIVE) {
groupEvents.active.push(group.id);
return;
} else if (e.kind === GroupModelChangeKind.GROUP_INDEX) {
groupEvents.index.push(group.id);
return;
}
if (!e.editor) {
return;
}
switch (e.kind) {
case GroupChangeKind.EDITOR_OPEN:
case GroupModelChangeKind.EDITOR_OPEN:
if (isGroupEditorOpenEvent(e)) {
groupEvents.opened.push({ editor: e.editor, index: e.editorIndex, groupId: group.id });
}
break;
case GroupChangeKind.EDITOR_CLOSE:
case GroupModelChangeKind.EDITOR_CLOSE:
if (isGroupEditorCloseEvent(e)) {
groupEvents.closed.push({ editor: e.editor, index: e.editorIndex, groupId: group.id, context: e.context, sticky: e.sticky });
}
break;
case GroupChangeKind.EDITOR_ACTIVE:
case GroupModelChangeKind.EDITOR_ACTIVE:
groupEvents.activated.push(e.editor);
break;
case GroupChangeKind.EDITOR_PIN:
case GroupModelChangeKind.EDITOR_PIN:
group.isPinned(e.editor) ? groupEvents.pinned.push(e.editor) : groupEvents.unpinned.push(e.editor);
break;
case GroupChangeKind.EDITOR_STICKY:
case GroupModelChangeKind.EDITOR_STICKY:
group.isSticky(e.editor) ? groupEvents.sticky.push(e.editor) : groupEvents.unsticky.push(e.editor);
break;
case GroupChangeKind.EDITOR_MOVE:
case GroupModelChangeKind.EDITOR_MOVE:
if (isGroupEditorMoveEvent(e)) {
groupEvents.moved.push({ editor: e.editor, index: e.oldEditorIndex, newIndex: e.editorIndex, target: group.id, groupId: group.id });
}
break;
case GroupChangeKind.EDITOR_WILL_DISPOSE:
case GroupModelChangeKind.EDITOR_WILL_DISPOSE:
groupEvents.disposed.push(e.editor);
break;
}
@ -309,7 +319,7 @@ suite('EditorGroupModel', () => {
let didEditorLabelChange = false;
const toDispose = clone.onDidModelChange((e) => {
if (e.kind === GroupChangeKind.EDITOR_LABEL) {
if (e.kind === GroupModelChangeKind.EDITOR_LABEL) {
didEditorLabelChange = true;
}
});
@ -728,7 +738,6 @@ suite('EditorGroupModel', () => {
test('group serialization (locked group)', function () {
const group = createEditorGroupModel();
const events = groupListener(group);
assert.strictEqual(events.locked.length, 0);
@ -760,6 +769,28 @@ suite('EditorGroupModel', () => {
assert.strictEqual(deserialized.isLocked, false);
});
test('index', function () {
const group = createEditorGroupModel();
const events = groupListener(group);
assert.strictEqual(events.index.length, 0);
group.setIndex(4);
assert.strictEqual(events.index.length, 1);
});
test('active', function () {
const group = createEditorGroupModel();
const events = groupListener(group);
assert.strictEqual(events.active.length, 0);
group.setActive(undefined);
assert.strictEqual(events.active.length, 1);
});
test('One Editor', function () {
const group = createEditorGroupModel();
const events = groupListener(group);
@ -1860,28 +1891,28 @@ suite('EditorGroupModel', () => {
let dirty1Counter = 0;
group1.onDidModelChange((e) => {
if (e.kind === GroupChangeKind.EDITOR_DIRTY) {
if (e.kind === GroupModelChangeKind.EDITOR_DIRTY) {
dirty1Counter++;
}
});
let dirty2Counter = 0;
group2.onDidModelChange((e) => {
if (e.kind === GroupChangeKind.EDITOR_DIRTY) {
if (e.kind === GroupModelChangeKind.EDITOR_DIRTY) {
dirty2Counter++;
}
});
let label1ChangeCounter = 0;
group1.onDidModelChange((e) => {
if (e.kind === GroupChangeKind.EDITOR_LABEL) {
if (e.kind === GroupModelChangeKind.EDITOR_LABEL) {
label1ChangeCounter++;
}
});
let label2ChangeCounter = 0;
group2.onDidModelChange((e) => {
if (e.kind === GroupChangeKind.EDITOR_LABEL) {
if (e.kind === GroupModelChangeKind.EDITOR_LABEL) {
label2ChangeCounter++;
}
});

View file

@ -10,7 +10,7 @@ import { URI } from 'vs/base/common/uri';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { EditorInputWithOptions, IEditorIdentifier, IUntitledTextResourceEditorInput, IResourceDiffEditorInput, IEditorPane, IEditorCloseEvent, IEditorPartOptions, IRevertOptions, GroupIdentifier, EditorsOrder, IFileEditorInput, IEditorFactoryRegistry, IEditorSerializer, EditorExtensions, ISaveOptions, IMoveResult, ITextDiffEditorPane, IVisibleEditorPane, IEditorOpenContext, EditorExtensions as Extensions, EditorInputCapabilities, IUntypedEditorInput, IEditorWillMoveEvent, IEditorWillOpenEvent } from 'vs/workbench/common/editor';
import { EditorInputWithOptions, IEditorIdentifier, IUntitledTextResourceEditorInput, IResourceDiffEditorInput, IEditorPane, IEditorCloseEvent, IEditorPartOptions, IRevertOptions, GroupIdentifier, EditorsOrder, IFileEditorInput, IEditorFactoryRegistry, IEditorSerializer, EditorExtensions, ISaveOptions, IMoveResult, ITextDiffEditorPane, IVisibleEditorPane, IEditorOpenContext, EditorExtensions as Extensions, EditorInputCapabilities, IUntypedEditorInput, IEditorWillMoveEvent, IEditorWillOpenEvent, IActiveEditorChangeEvent } from 'vs/workbench/common/editor';
import { EditorServiceImpl, IEditorGroupView, IEditorGroupsAccessor, IEditorGroupTitleHeight } from 'vs/workbench/browser/parts/editor/editor';
import { Event, Emitter } from 'vs/base/common/event';
import { IResolvedWorkingCopyBackup, IWorkingCopyBackupService } from 'vs/workbench/services/workingCopy/common/workingCopyBackup';
@ -144,7 +144,7 @@ import { TestLanguageConfigurationService } from 'vs/editor/test/common/modes/te
import { FindReplaceState } from 'vs/editor/contrib/find/findState';
import { TerminalEditorInput } from 'vs/workbench/contrib/terminal/browser/terminalEditorInput';
import { DeserializedTerminalEditorInput } from 'vs/workbench/contrib/terminal/browser/terminalEditorSerializer';
import { IGroupChangeEvent } from 'vs/workbench/common/editor/editorGroupModel';
import { IGroupModelChangeEvent } from 'vs/workbench/common/editor/editorGroupModel';
import { env } from 'vs/base/common/process';
export function createFileEditorInput(instantiationService: IInstantiationService, resource: URI): FileEditorInput {
@ -817,8 +817,7 @@ export class TestEditorGroupView implements IEditorGroupView {
isMinimized = false;
onWillDispose: Event<void> = Event.None;
onDidGroupChange: Event<IGroupChangeEvent> = Event.None;
onDidModelChange: Event<IGroupChangeEvent> = Event.None;
onDidModelChange: Event<IGroupModelChangeEvent> = Event.None;
onWillCloseEditor: Event<IEditorCloseEvent> = Event.None;
onDidCloseEditor: Event<IEditorCloseEvent> = Event.None;
onDidOpenEditorFail: Event<EditorInput> = Event.None;
@ -826,6 +825,7 @@ export class TestEditorGroupView implements IEditorGroupView {
onDidChange: Event<{ width: number; height: number; }> = Event.None;
onWillMoveEditor: Event<IEditorWillMoveEvent> = Event.None;
onWillOpenEditor: Event<IEditorWillOpenEvent> = Event.None;
onDidActiveEditorChange: Event<IActiveEditorChangeEvent> = Event.None;
getEditors(_order?: EditorsOrder): readonly EditorInput[] { return []; }
findEditors(_resource: URI): readonly EditorInput[] { return []; }