提交 791341b3 编写于 作者: I initialshl

Prevent unnecessary switchings of active editor or group in JoinTwoGroupsAction

上级 cc3d7374
......@@ -125,7 +125,7 @@ export class JoinTwoGroupsAction extends Action {
const editorStacksModel = this.editorGroupService.getStacksModel();
// Return if has no other group to join to
if (editorStacksModel.groups.length <= 1) {
if (editorStacksModel.groups.length < 2) {
return TPromise.as(true);
}
......@@ -151,17 +151,21 @@ export class JoinTwoGroupsAction extends Action {
const activeEditor = fromGroup.activeEditor;
const fromGroupEditors = fromGroup.getEditors();
const fromGroupTotalCount = fromGroupEditors.length;
// If an editor exists in both groups, only the editor in the joining group is kept
if (toPosition < fromPosition) {
fromGroupEditors.forEach(e => this.editorGroupService.moveEditor(e, fromPosition, toPosition, { index: toGroup.count, inactive: true }));
} else {
fromGroupEditors.forEach(e => this.editorGroupService.moveEditor(e, fromPosition, toPosition, { index: fromGroupTotalCount - fromGroup.count, inactive: true }));
}
// Insert the editors to the start if moving to the next group, otherwise insert to the end
// If an editor exists in both groups, its index is respected as in the joining group
const movingToNextGroup = fromPosition < toPosition;
let index = movingToNextGroup ? 0 : toGroup.count;
// Inactive and preserve focus options are used to prevent unnecessary switchings of active editor or group
fromGroupEditors.forEach(e => {
const inactive = e !== activeEditor;
this.editorGroupService.moveEditor(e, fromPosition, toPosition, { index, inactive, preserveFocus: inactive });
index = movingToNextGroup ? index + 1 : toGroup.count;
});
// Regain focus on the active editor
this.editorService.openEditor(activeEditor);
// Focus may be lost when the joining group is closed, regain focus on the target group
this.editorGroupService.focusGroup(toGroup);
return TPromise.as(true);
}
......
......@@ -856,14 +856,15 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
const index = moveOptions && moveOptions.index;
const inactive = moveOptions && moveOptions.inactive;
const preserveFocus = moveOptions && moveOptions.preserveFocus;
// When moving an editor, try to preserve as much view state as possible by checking
// for the editor to be a text editor and creating the options accordingly if so
let options = EditorOptions.create({ pinned: true, index, inactive });
let options = EditorOptions.create({ pinned: true, index, inactive, preserveFocus });
const activeEditor = this.getActiveEditor();
const codeEditor = getCodeEditor(activeEditor);
if (codeEditor && activeEditor.position === this.stacks.positionOfGroup(fromGroup) && input.matches(activeEditor.input)) {
options = TextEditorOptions.create({ pinned: true, index, inactive });
options = TextEditorOptions.create({ pinned: true, index, inactive, preserveFocus });
(<TextEditorOptions>options).fromEditor(codeEditor);
}
......
......@@ -29,6 +29,7 @@ export interface ITabOptions {
export interface IMoveOptions {
index?: number;
inactive?: boolean;
preserveFocus?: boolean;
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册