-
Notifications
You must be signed in to change notification settings - Fork 30k
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
added Center Mode (#15684) #40757
added Center Mode (#15684) #40757
Conversation
It says that
edit: I fixed it... but only by nearly going line by line to find the formating problem... is there a better way? for next time |
@SrTobi thanks a lot for your PR. This functionality is needed and I really appreciated that you submited a PR. However it is usually best to first provide an empty PR where we can discuss on how to potentially solve this - just so you know for the future. For now I did a quick review, and the issue that I see is that the layouting magic is happenig in the As for the settings and options they are fine overall, I would just polish them a bit, but let's first get the layouting correct. |
@isidorn I was aware that the layouting happens in editorGroupsControl but I specifically wanted the tab bar taking the full space and not being centered as well (which would be the case if I had centered the whole editorGroupsControl). That's why I had to move it into editorGroupsControl. That was simply a design decision and could be done either way. This becomes even more important with the new idea to also make the centered mode available in tho non-zen-mode (which we discussed in #15684). The settings we worked out there are more fitting for the use cases of most users, I think. |
@@ -86,6 +89,23 @@ export interface IEditorGroupsControl { | |||
dispose(): void; | |||
} | |||
|
|||
function toSize(sizeStr: string, maxSize: number, defaultSize: number): number { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SrTobi Any reason why this method is not a private method within the EditorGroupsControl
close to where it is being used?
I think the approach is fine to have it inside a) from what other people seem to say they want to center the editor independently from zen mode and I think it is fine to allow this independent from it b) some seem to want a setting of the size based on character count and not relative percentages. I also wonder if maybe as a user you should be able to resize the editor using sashes to the left and right to configure the right size without having to manually edit this in settings |
'default': false, | ||
'description': nls.localize('zenMode.centerEditor', "Controls if a single editor is centered when in zen mode.") | ||
}, | ||
'zenMode.centerEditorSize': { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm in favor of a simpler approach where the max centered editor size is based on columns, as with editor.wordWrapColumn
@bpasero I like the idea with the sashes, but then the question when to activate the center mode becomes even harder, or not? Maybe combine both ideas:
Then two questions remain:
And then one technical question:
|
Ok, I changed the PR and streamlined the settings a lot. The Center Mode is now independent from the zen mode. The settings are now as follows:
|
@SrTobi I would try to reduce the settings to begin with and make this feature simple. For that I think its good that it is decoupled from zen mode now. Settings to drop or question:
|
@SrTobi great work.
Edit: now I see some ideas on automatic triggering based on width. Imho this is too complex for users and should behave based on number of open editor groups. |
@bpasero The idea behind @isidorn The moment a second silo is opened, the centering is prevented. So no centering, but no settings or internal state changes either. That means, if one of the two silos is closed, the remaining silo will be centered again.
When we use sashes, then there are two more questions:
What do you think? Otherwise I would start implementing the following changes sometime in the next days:
|
@SrTobi thanks for your comments.
Since we already auto exit this mode when more than 1 editor is open I would vote for option 2. To give more flexibility to those huge montiors and to let the users have their editor really centerd when explorer is open. Also with this adoptRight is not needed and we get rid of complex settings. Feature which we will add on top when the users complain about pixel perfection. Double click on sash brings them both into default position (we have this in other pars of our ux), double click again takes 2/3 of the width, double click again 3/4 double click again the default. Let's see what @bpasero thinks before you start the implementation. |
Yeah that sounds good, though I would also add double clicking on a sash and then dragging brings it into the coupled mode... so we can have all the features :D and it would be somewhat natural (may I add that that is exactly what my usecase would be). And don't tell me about hidden features... I didn't knew about the double clicking until you mentioned it 😄 (good to know by the way 👍) |
|
||
if (tryCentering) { | ||
const size = Math.max(100, this.configurationService.getValue<number>('centerMode.size')); | ||
const adoptRight = this.configurationService.getValue<string>('centerMode.adoptRight'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line should be getValue<boolean>
const centerOnlyEditors = this.configurationService.getValue<string>('centerMode.onlyEditors'); | ||
const availableWidth = this.dimension.width; | ||
|
||
const isTextEditor = editor instanceof TextResourceEditor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instanceof
is not a good design... in fact it doesn't even work correct. Markdown editors and normal text editors seem to be of class type TextFileEditor
(which I was not able to import because linter import rules).
Best option is to add another abstract method like allowsCentering(): boolean
or something to BaseEditor
and let the implementation decide whether it itself should be centered or not
I like the idea of replacing the now complicated Avoiding the remaining settings and having 2 sashes left and right to the editor seems like a good thing to play around with: not sure about the coupling to be honest (we do not have that anywhere else in our UI). Maybe we could say that Ctrl+click moves both or double click does something special but imho we can also look at that later. We could also introduce 2 more sashes top and bottom of the editor so that people could size the editor area anyway they want (some people seem to want a margin to the top of the editor). Bottom line is that we should have some good defaults out of the box that make the "centered editor" mode useful without configuration. I would probably expect that default to work in any resolution (e.g. not hardcoded to a specific number but relative to the window size). E.g. with the current 1200 value I was not even seeing the editor centering when I was working on my normal laptop screen and thought the feature was broken. Last, we need to figure out where to store the user configured sash positions. I guess it would make sense to store this via storage service in the GLOBAL scope and not workspace so that the user can tweak it once and have it in all workspaces? |
@bpasero yeah, I think GLOBAL scope is fine. @bpasero you're right: defaults are important. If the user activates the centered layout, he must be able to see the effect immediately. Another problem with the sashes: are they proportional or absolute? That's very important when changing the window size. I think most reasonable would be to make the size of the editor (between the two sashes) absolute — so the editor size doesn't change on resize — and let the left/right margin grow/shrink proportional. That would also provide a smooth transition to the non centered layout when shrinking the window too much. In the store we would have to save the size of the editor in pixels and the proportion of the right/left margin. On the other Hand, it does create problems with any default size which depends on the window size because different windows sizes — when the centered layout is initially activated — would yield different permanently saved editor sizes. Though I think the feature would mostly be used in zen mode and so I think it's somewhat reasonable to ignore the former mentioned problem and just set it to 50% of the window size (after zen mode is activated). After all the most important point in the default size is that the user recognizes the feature and is able to modify the size with the sashes himself. |
Seems like @bpasero and me are in agreement and you have something to start with. Top and bottom sashes are step2, so not for now. @SrTobi as for the propritaonal vs absolute, the sashes are absolute and they will not change when the window resizes. And that is fine for this PR. @michaeljcalkins thanks for the suggestion, we can add that nice feature later. Bottom line, let's try to get the basic funcionality in and not worry about fancy features on top. We will nicely polish this once we have the inital pr in. Thanks a lot |
Ok, I fixed your suggestions and added the storing of the position and the location. Things left to do:
|
@SrTobi there seem to be warnings in the toggle action. And then, when I try this out and select the center mode from the menu, the editor does not change, is that a bug? |
/** | ||
* Helper class to manage multiple side by side editors for the editor part. | ||
*/ | ||
export class EditorGroupsControl extends Themable implements IEditorGroupsControl, IVerticalSashLayoutProvider, IHorizontalSashLayoutProvider { | ||
|
||
private static readonly CENTERED_LAYOUT_DATA_STORAGE_KEY = 'centeredLayoutData'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefix the value of this key with 'workbench' to be aligned with similar storage keys
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
@@ -969,6 +1015,31 @@ export class EditorGroupsControl extends Themable implements IEditorGroupsContro | |||
// Silo Three | |||
this.silos[Position.THREE] = $(this.parent).div({ class: 'one-editor-silo editor-three' }); | |||
|
|||
// Center Layout stuff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor. Feels like code duplication, we do the creation and listeners twice. Can't we have a helper method that just takes a centered sash and nicely initilizes it. For that the DragStart and Drag methods would have to take sashes as parameters and based on Sash do different things.
Which might not be too bad, currently I feel like there are too many methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that's a good idea... that would make the individual method body larger... and break the coding style for sashes... I mean the class is pretty big but that would require an additional PR that really breaks the class apart. I think it's much more clean the way it is... what we could do is outfactor the initialization for the sashes. I did that in this commit SrTobi-Forks@abccb77 (it's not part of this PR at the moment) but I am not really sure if that makes the code more structured (in fact, it adds one more method 😄 ).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, makes sense
this.setCenteredEditorPositionAndSize(size < this.minSize ? pos + (size - this.minSize) : pos, size); | ||
} | ||
|
||
private saveCenterdLayoutData(): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably call this storeCenteredLayoutData
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
this.layoutVertically && | ||
this.editorGroupService.getStacksModel().groups.length === 1 && | ||
this.partService.isLayoutCentered() && | ||
this.visibleEditors[Position.ONE] instanceof TextResourceEditor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah definetely remove this instanceof check, since the feature does not behave like it should with it. @bpasero was unable to try it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
@SrTobi great, I added a bit more comments. @bpasero will also review that file later today I believe. Thanks a lot for your great work! |
@isidorn I fixed your remarks. I still think we should have something that prevents the diff editor from being centered... it really needs all the space it can get I played a little bit around with the border for the sashes but I'm not sure on how to do it correctly... I think I would prefer a thin one pixel border with the same color the scrollbar border has ( Here is a screenshot: I added a commit for this but it seems somewhat messy (on the other hand: it is css 😄 ). Maybe you could enhance that further. With my solution, there also seems to be a gap between the actual scrollbar (not only the container) and the right border (it's not visible on the screenshot because the scrollbar is hidden). |
@SrTobi great for addressing everything. That last commit is a total mess so I suggest to revert it 😊 So when that is reverted all is good from my side, let's just wait for @bpasero before merging As for the DiffEditor, same as when 2 groups get opened we should get out of CeneterdMode temporarly while a DiffEditor is open, however we have a helper function to check if something is a DiffEditor. You would also have to react on editors being opened if you are not already. If you feel like it give this a try, if not I can also cover it once we merge. |
This reverts commit caf6e5e.
@isidorn ok, I reverted the commit :D When this is merged I would maybe work on the auto activation of the centered layout in zen mode. That's a feature that I would like to see very much. |
@SrTobi sounds great. Let's wait for the merge and once that is done you can look into zen mode setting which should not be complicated. |
@isidorn ok, let's do it that way |
LGTM, I moved the sashes into the editor container instead of the parent because I think they belong there. |
@bpasero awesome, thanks for merging this in. Code pointers |
@SrTobi I have pushed the border color and not to go into center mode for diff editors. Apart from zenMode setting I would not add any other features on top until we get some user feedback. |
@SrTobi the presentation in the meeting went great. Only one suggestion came: by default the sashes should be paired, but the user can press |
@isidorn good idea. I really like that 👍 |
Of the three languages I use VSCode for, only one of them enters center mode properly. I want to open an issue, but I'm not sure where – is this a VSCode problem, or a problem with respective extensions the two languages that aren't working for me? (F# is working, C++ and Rust aren't.) I know this question is very light on details, but I'm not sure what information would be helpful, or whether I'm posting in the right place... |
@dodheim open a new issue with exact reproducable steps and we can investigate further. Thanks |
As described in #15684 this adds editor centering for the zen mode. I added two options:
zenMode.centerEditor
controls if the centering should be usedzenMode.centerEditorSize
controls the size of the centered editor. you can either specify the size using a size string (e.g."60%"
or"600px"
) or you can specify the size of the two halfs of the editor (seen from the center)With this the editor would occupy 30% of the left side of the window and 100% of the right side.