提交 00bdc456 编写于 作者: B Benjamin Pasero

grid - reduce active change events when closing last editor in group

上级 0f8ef8cb
......@@ -91,6 +91,7 @@ export interface IEditorGroupsAccessor {
getGroup(identifier: GroupIdentifier): IEditorGroupView;
activateGroup(identifier: IEditorGroupView | GroupIdentifier): IEditorGroupView;
activatePreviousActiveGroup();
addGroup(location: IEditorGroupView | GroupIdentifier, direction: GroupDirection, options?: IAddGroupOptions): IEditorGroupView;
mergeGroup(group: IEditorGroupView | GroupIdentifier, target: IEditorGroupView | GroupIdentifier, options?: IMergeGroupOptions): IEditorGroupView;
......
......@@ -884,6 +884,18 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
const editorToClose = this.activeEditor;
const editorHasFocus = isAncestor(document.activeElement, this.element);
// Optimization: if we are about to close the last editor in this group and settings
// are configured to close the group since it will be empty, we first set the last
// active group as empty before closing the editor. This reduces the amount of editor
// change events that this operation emits and will reduce flicker. Without this
// optimization, this group (if active) would first trigger a active editor change
// event because it became empty, only to then trigger another one when the next
// group gets active.
const closeEmptyGroup = this.accessor.partOptions.closeEmptyGroups;
if (closeEmptyGroup && this.active && this._group.count === 1) {
this.accessor.activatePreviousActiveGroup();
}
// Update model
this._group.closeEditor(editorToClose);
......@@ -906,23 +918,22 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
});
}
// Otherwise clear from editor control and send event
// Otherwise we are empty, so clear from editor control and send event
else {
// Forward to editor control
this.editorControl.closeEditor(editorToClose);
// Restore focus to group container as needed
if (editorHasFocus) {
// Restore focus to group container as needed unless group gets closed
if (editorHasFocus && !closeEmptyGroup) {
this.focus();
}
// Events
this._onDidGroupChange.fire({ kind: GroupChangeKind.EDITOR_ACTIVE });
// Check if group gets closed now
const closeGroup = this.isEmpty() && this.accessor.partOptions.closeEmptyGroups;
if (closeGroup) {
// Remove empty group if we should
if (closeEmptyGroup) {
this.accessor.removeGroup(this);
}
}
......
......@@ -111,7 +111,7 @@ export class EditorPart extends Part implements IEditorGroupsService, IEditorGro
this.registerListeners();
}
//#region IEditorPartOptions
//#region IEditorGroupsAccessor
private enforcedPartOptions: IEditorPartOptions[] = [];
......@@ -155,6 +155,14 @@ export class EditorPart extends Part implements IEditorGroupsService, IEditorGro
});
}
activatePreviousActiveGroup(): void {
const mostRecentlyActiveGroups = this.getGroups(GroupsOrder.MOST_RECENTLY_ACTIVE);
const previousActiveGroup = mostRecentlyActiveGroups[1];
if (previousActiveGroup) {
this.activateGroup(previousActiveGroup);
}
}
//#endregion
//#region IEditorGroupsService
......@@ -478,9 +486,7 @@ export class EditorPart extends Part implements IEditorGroupsService, IEditorGro
// Activate next group if the removed one was active
if (this._activeGroup === groupView) {
const mostRecentlyActiveGroups = this.getGroups(GroupsOrder.MOST_RECENTLY_ACTIVE);
const nextActiveGroup = mostRecentlyActiveGroups[1]; // [0] will be the current group we are about to dispose
this.activateGroup(nextActiveGroup);
this.activatePreviousActiveGroup();
}
// Remove from grid widget & dispose
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册