Skip to content

Implement join editors command #22389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 13, 2017

Conversation

initialshl
Copy link
Contributor

@initialshl initialshl commented Mar 10, 2017

Fixes #20279

This command joins the editor group with the previous group (except for the first group which joins with the next group).

The order of editors in the joining group is preserved when joining with the target group.

If an editor is opened in both the joining and target group, only one will be kept, in the same position as in the joining group.

vscode-join-editors

@mention-bot
Copy link

@initialshl, thanks for your PR! By analyzing the history of the files in this pull request, we identified @egamma and @bpasero to be potential reviewers.

@msftclas
Copy link

@initialshl,
Thanks for having already signed the Contribution License Agreement. Your agreement was validated by Microsoft. We will now review your pull request.
Thanks,
Microsoft Pull Request Bot

Copy link
Member

@bpasero bpasero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start, added some feedback.

This makes me think: do we want more commands that allow to "Split Editors"? Like the inverse operation of "Join Editors" which would basically mean to start a new group starting with the current active editor and move all editors to the right to a new group. Would be pretty cool :)

@@ -331,6 +331,7 @@ registry.registerWorkbenchAction(new SyncActionDescriptor(CloseEditorsInGroupAct
registry.registerWorkbenchAction(new SyncActionDescriptor(CloseOtherEditorsInGroupAction, CloseOtherEditorsInGroupAction.ID, CloseOtherEditorsInGroupAction.LABEL, { primary: null, mac: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KEY_T } }), 'View: Close Other Editors', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(CloseEditorsInOtherGroupsAction, CloseEditorsInOtherGroupsAction.ID, CloseEditorsInOtherGroupsAction.LABEL), 'View: Close Editors in Other Groups', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(SplitEditorAction, SplitEditorAction.ID, SplitEditorAction.LABEL, { primary: KeyMod.CtrlCmd | KeyCode.US_BACKSLASH }), 'View: Split Editor', category);
registry.registerWorkbenchAction(new SyncActionDescriptor(JoinEditorsAction, JoinEditorsAction.ID, JoinEditorsAction.LABEL), 'View: Join Editors', category);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this maybe be more descriptive to what it actually does? Join Editors of two Groups?

@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IEditorGroupService private editorGroupService: IEditorGroupService
) {
super(id, label, 'join-editors-action');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not need the CSS class here unless it would show up as icon, so I suggest to remove it.

}

public run(context?: IEditorContext): TPromise<any> {
let editorToJoin: IEditor;
Copy link
Member

@bpasero bpasero Mar 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you only need position and input from the IEditor. If so, I suggest to completley bypass the editorService API and do all of this from the stacks model that provides all you need (inputs, groups, a way to convert from a group to a position) from editor group service (there is a bit of overlap for historic reasons).

The stacks model is really the truth of what is going up in the 1-3 editor groups and you should be able to do everything with it. The more heavy IEditor is the actual instance of control that hosts inputs.


// If an editor exists in joining group and target group, only the editor in the joining group is kept.
if (targetPosition < toJoinPosition) {
toJoinEditors.forEach(e => this.editorGroupService.moveEditor(e, toJoinPosition, targetPosition, targetGroup.count));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit crazy to do because for each editor that gets moved it will be opened in the target group causing an editor switch. It would be much smoother if the move would happen with the editors opening inactive on the target group and only the last one would actually be active. There is an option that can be set when opening an editor called inactive that I think we should wire into the moveEditor call so that we can optimize for this (for the openEditor call here).

@initialshl
Copy link
Contributor Author

@bpasero Thanks for the review!
I have refactored some parts and also used the inactive option, and added the new gif in the description of this PR.

do we want more commands that allow to "Split Editors"?

Indeed, Split Editors would be a useful and convenient command, I can see myself using it a lot!

Copy link
Member

@bpasero bpasero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, just a minor comment left.

public moveEditor(input: EditorInput, from: EditorGroup, to: EditorGroup, index?: number): void;
public moveEditor(input: EditorInput, from: Position, to: Position, index?: number): void;
public moveEditor(input: EditorInput, arg2: any, arg3: any, index?: number): void {
public moveEditor(input: EditorInput, from: EditorGroup, to: EditorGroup, index?: number, inactive?: boolean): void;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to put index and inactive into a new optional options bag (IMoveOptions).

*/
moveEditor(input: IEditorInput, from: IEditorGroup, to: IEditorGroup, index?: number): void;
moveEditor(input: IEditorInput, from: Position, to: Position, index?: number): void;
moveEditor(input: IEditorInput, from: IEditorGroup, to: IEditorGroup, index?: number, inactive?: boolean): void;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMoveOptions

@bpasero bpasero added this to the March 2017 milestone Mar 11, 2017
Copy link
Member

@bpasero bpasero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more feedback, almost there 👍

const fromGroupTotalCount = fromGroupEditors.length;

// If an editor exists in both groups, only the editor in the joining group is kept
if (toPosition < fromPosition) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need to improve this: Now we start to move editors from the group to another group starting with the first editor of that group, going to the last. This is bad when the first editor of the group is also the active editor because after each editor is moved, the group will show the next editor as active.

As such, please first move all the inactive editors of the group and only at last the active editor. This will again prevent many unwanted editor change events being fired.

@initialshl
Copy link
Contributor Author

initialshl commented Mar 12, 2017

@bpasero Thanks for the feedbacks. I overlooked the inactive option which can be used to control the switching of the active editor. It appears that the preserveFocus option has to be set too, so that the toGroup is activated only after the active editor has moved.

And regarding the possibility of adding a new command SplitEditors, I would be happy to contribute another PR for that if it is good 👍

@bpasero
Copy link
Member

bpasero commented Mar 12, 2017

@initialshl yes, something like "View: Split Editors into Two Groups" 👍 . Ideally we could have a common base class of both actions to share some logic for both.

This PR looks nice now, thanks. I will merge it in tomorrow.

@bpasero bpasero merged commit dd197f1 into microsoft:master Mar 13, 2017
@kounelios13
Copy link

is there any key combination available?

@bpasero
Copy link
Member

bpasero commented Jan 21, 2018

@kounelios13 just assign it via keybindings settings:

image

@kounelios13
Copy link

Hello.I've noticed something.If I have more than 2 editors open when I execute this command it won't join all of them.Is there any way to achieve this behavior?

@bpasero
Copy link
Member

bpasero commented Jan 21, 2018

Works for me, even with 3 editor groups open.

@kounelios13
Copy link

@bpasero If I have 3 editors open it will merge two of them and then it leaves me with 2 editors open

@bpasero
Copy link
Member

bpasero commented Jan 21, 2018

@kounelios13 what would you expect to happen?

@kounelios13
Copy link

@bpasero I would expect that if I have let's say 5 editors open after executing the join command it would merge them all into 1.

Isn't that the purpose of this command or have I misunderstood it?

@bpasero
Copy link
Member

bpasero commented Jan 21, 2018

@kounelios13 as the name of that action implies, it will only merge the editors of 2 groups, not all groups.

@kounelios13
Copy link

Sorry my mistake.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to unsplit editors of 2 editor groups
5 participants