Skip to content

Add optional parameter to showOptions called newEditorGroup#107555

Closed
tomerstav wants to merge 4 commits intomicrosoft:masterfrom
tomerstav:view-col-assignment
Closed

Add optional parameter to showOptions called newEditorGroup#107555
tomerstav wants to merge 4 commits intomicrosoft:masterfrom
tomerstav:view-col-assignment

Conversation

@tomerstav
Copy link
Contributor

@tomerstav tomerstav commented Sep 27, 2020

The issue was that when a position for a view column that does not exist was converted into editor group it would be marked as side group. Side groups create a new column based on the neighbour of the active group you are on. If it does not exist it will create a new group. So for example if you had two view columns open and you clicked the first one then the first view column is the active group. The second view column is the neighbour of the active group. And the new column would open inside the second view column. But if you clicked the second view column. The active group is the second view column. The neighbour doesn't exist. So the new view column will be a new third group.

My implementation adds an optional parameter to showOptions called newEditorGroup. When set to true, a new view column is created in a new editor group at the position specified.

Examples:

  1. Two view columns open in their own editor groups. The command below will create a new view column with a new editor group at position 1 resulting in three editor groups.

const panel = vscode.window.createWebviewPanel("", "", {viewColumn:1, newEditorGroup: true});

  1. Two view columns open in their own editor groups. The command below will create a new view column with a new editor group at position 3 resulting in three editor groups.

const panel = vscode.window.createWebviewPanel("", "", {viewColumn:3, newEditorGroup: true});

  • If view column does not exist, a new editor group is created after the last view column. Which happens in the second example.

This PR fixes #106973

@ghost
Copy link

ghost commented Sep 27, 2020

CLA assistant check
All CLA requirements met.

@kieferrm kieferrm requested a review from mjbvz September 28, 2020 14:11
@mjbvz mjbvz added this to the October 2020 milestone Sep 28, 2020
@mjbvz mjbvz requested a review from bpasero September 28, 2020 17:28
@bpasero bpasero requested review from jrieken and removed request for bpasero September 28, 2020 17:29
@mjbvz
Copy link
Collaborator

mjbvz commented Sep 28, 2020

I suspect this is not the correct fix.

vscode.ViewColumn.ONE === 1 but I believe the internal EditorViewColumn type is zero based (so the first column === 0)

Copy link
Member

@jrieken jrieken left a comment

Choose a reason for hiding this comment

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

This seems wrong, please explain those changes

@tomerstav
Copy link
Contributor Author

This seems wrong, please explain those changes

I misunderstood how the code was working. I initially thought that the implementation for adding a new view col was expecting non zero based indexing as explained in the docs. https://code.visualstudio.com/api/references/vscode-api#ViewColumn

My changes fixed the issue but I can see from the failed integration testing and comments that this isn't the right solution. I will convert this pr into a draft and attempt this again.

@tomerstav tomerstav marked this pull request as draft September 29, 2020 21:18
@tomerstav tomerstav force-pushed the view-col-assignment branch from 5ff2599 to cd69b98 Compare October 4, 2020 22:44
@tomerstav tomerstav force-pushed the view-col-assignment branch from cd69b98 to 9b35b0e Compare October 5, 2020 01:44
@tomerstav tomerstav changed the title Removed zero based indexing for view col New group for positions outside group range by 1 Oct 5, 2020
@tomerstav
Copy link
Contributor Author

I have updated the description of the PR. Please read and let me know if you have any questions. @jrieken @mjbvz

@tomerstav tomerstav marked this pull request as ready for review October 5, 2020 02:25
@bpasero bpasero self-requested a review October 5, 2020 05:28
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.

Overall I think this can break existing extensions because we used to return SIDE_GROUP which is defined as opening to the side of the currently active group and NEW_GROUP is entirely different, opening a new group after the last group by appearance.


private newSideRightGroup(): IEditorGroup {
const lastGroupIndex = this.editorGroupService.groups.length - 1;
return this.editorGroupService.addGroup(this.editorGroupService.groups[lastGroupIndex], GroupDirection.RIGHT);
Copy link
Member

Choose a reason for hiding this comment

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

The group direction should not be hardcoded but taken from user settings via:

const direction = preferredSideBySideGroupDirection(this.configurationService);

}

private newSideRightGroup(): IEditorGroup {
const lastGroupIndex = this.editorGroupService.groups.length - 1;
Copy link
Member

Choose a reason for hiding this comment

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

That is not a safe way to find the last group, I think you want:

this.editorGroupService.getGroups(GroupsOrder.GRID_APPEARANCE)

return neighbourGroup;
}

private newSideRightGroup(): IEditorGroup {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
private newSideRightGroup(): IEditorGroup {
private newSideGroup(): IEditorGroup {

Copy link
Contributor Author

@tomerstav tomerstav Oct 6, 2020

Choose a reason for hiding this comment

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

Not applicable anymore. New approach.


// Group: New group
else if (group === NEW_GROUP) {
targetGroup = this.newSideRightGroup();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
targetGroup = this.newSideRightGroup();
targetGroup = this.newSideGroup();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See comment above


type CachedEditorInput = ResourceEditorInput | IFileEditorInput | UntitledTextEditorInput;
type OpenInEditorGroup = IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE;
type OpenInEditorGroup = IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE | NEW_GROUP_TYPE;
Copy link
Member

Choose a reason for hiding this comment

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

I find NEW_GROUP_TYPE is not fully expressing what it does. Based on the implementation it seems to create a new group after the last group by appearance. If so I think the name should reflect that, because as a user of the API one might think that it opens a new group from the currently active group and not the last group.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will remove this with new approach.

@tomerstav tomerstav changed the title New group for positions outside group range by 1 Add optional parameter to showOptions called newEditorGroup Oct 12, 2020
@bpasero bpasero self-requested a review October 12, 2020 08:39
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.

Why is newEditorGroup a boolean and not another type similar to SIDE_GROUP_TYPE? I would rather introduce something like NEW_GROUP_TYPE.

@tomerstav
Copy link
Contributor Author

tomerstav commented Oct 12, 2020

Why is newEditorGroup a boolean and not another type similar to SIDE_GROUP_TYPE? I would rather introduce something like NEW_GROUP_TYPE.

We need to keep track of the view column number. Groups internally was keeping track of that number. I have created a NEW_GROUP_TYPE and converted newEditorGroup internally to keep track of the view column number instead.

@bpasero bpasero requested review from bpasero and removed request for bpasero October 12, 2020 17:10
@bpasero
Copy link
Member

bpasero commented Oct 13, 2020

It looks like #106973 is now closed with a workaround and I am not happy with the change in this PR to be honest. I would suggest to not push this forward.

@bpasero bpasero self-requested a review October 13, 2020 07:35
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.

Rejected as per #107555 (comment)

@tomerstav
Copy link
Contributor Author

It looks like #106973 is now closed with a workaround and I am not happy with the change in this PR to be honest. I would suggest to not push this forward.

Could you explain why you are not happy with this PR? I would like to learn from this.

@bpasero
Copy link
Member

bpasero commented Oct 14, 2020

I actually started to review this PR but then ended up changing a lot of the code myself, almost rewriting it. In principle I am not opposed to the idea of having a new group type in editor land, but it touched too many areas in the end and I am not convinced we actually still need this?

@tomerstav
Copy link
Contributor Author

I actually started to review this PR but then ended up changing a lot of the code myself, almost rewriting it. In principle I am not opposed to the idea of having a new group type in editor land, but it touched too many areas in the end and I am not convinced we actually still need this?

I think the work around is not a good long term solution. But fair enough I will close the PR.

@tomerstav tomerstav closed this Oct 14, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Dec 4, 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.

viewColumn assignment won't open in rightmost position

4 participants