Skip to content
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

Addresses #26184 - use configuration for pinned default #27357

Merged
merged 6 commits into from
Jul 6, 2017

Conversation

eamodio
Copy link
Contributor

@eamodio eamodio commented May 27, 2017

Uses the configuration setting workbench.editor.enablePreview to provide a default of pinned if not explicitly passed. See #26184 (comment)

Hopefully this is decent way of implementing this :)

/cc @jrieken @bpasero

@mention-bot
Copy link

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

@jrieken
Copy link
Member

jrieken commented May 28, 2017

I have the feeling that this would be a lot more simple if that is implemented in the _workbench.diff-command with some true, false, and undefined values for pinned set from the API

@bpasero bpasero assigned jrieken and unassigned bpasero May 28, 2017
@eamodio eamodio force-pushed the feature-pinned-default branch 2 times, most recently from af5ddc3 to 14973d6 Compare May 28, 2017 17:20
@eamodio
Copy link
Contributor Author

eamodio commented May 28, 2017

@jrieken I've re-worked this completely to move it down to hopefully the lowest level. So as per @bpasero comments, if you pass true / false for pinned it will be honored, but undefined will enact the default behavior which is controlled first by workbench.editor.enablePreview and then the existing other checks

@bpasero
Copy link
Member

bpasero commented May 29, 2017

@eamodio this is a bad change as it can result in editors showing up as preview even though "workbench.editor.enablePreview": is set to false as soon as a client of openEditor is setting pinned: false.

I think what Joh meant is to implement this behaviour only in the _workbench.diff command but not throughout all users in the workbench?

@eamodio
Copy link
Contributor Author

eamodio commented May 29, 2017

@bpasero I guess I misunderstood your original comments. I thought the desire was to allow extensions to be able to fully control the pinned state regardless of workbench.editor.enablePreview, but if the extension passed undefined then the default would be based upon the current default rules including the check of workbench.editor.enablePreview.

If that isn't the case and workbench.editor.enablePreview should rule regardless I can just tweak that back here to make the this.tabOptions.previewEditors always win

@eamodio
Copy link
Contributor Author

eamodio commented May 29, 2017

@bpasero Updated to honor workbench.editor.enablePreview above all else

@jrieken
Copy link
Member

jrieken commented Jun 9, 2017

Not sure how this should work @bpasero? Now pinned is more or less removed in most placed which makes sense if we have a reasonable and configurable default but I don't know why folks have done it like that in the first place

@bpasero
Copy link
Member

bpasero commented Jun 9, 2017

I do not really understand the need for introducing undefined for this. I agree that we should not set pinning hard coded from anywhere unless we know that the action that triggers the opening wants to pin or not pin. One example is double clicking on an entry in a tree or making something dirty.

If we simply do not set pinning state when opening things, the default will be to open as preview unless this is disabled via user settings.

In other words, I would let extensions opt-in to pinning (with the API we have today) but not set it by default. This should give the correct experience.

Btw for webviews we should probably enforce pinning simply because the UI state in there is not preserved and it would be odd to loose the content so quickly.

@eamodio
Copy link
Contributor Author

eamodio commented Jun 9, 2017

When I wasn't honoring workbench.editor.enablePreview, undefined was required as there wasn't a way to say I want the "default" behavior, its either pinned or not. But now that we are again always honoring workbench.editor.enablePreview I guess pinned === false is the equivalent of use the "default".

Although honestly, I'd rather leave undefined in there because it is a clear indicator of not specifying the behavior and that the default behavior should be used. That way if down the line something there changes you know the difference between something not caring about pinned/unpinned vs explicit intent.

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.

-1 for using undefined everywhere. +1 for not setting preview from extensions unless explicitly set.

@eamodio
Copy link
Contributor Author

eamodio commented Jun 13, 2017

@bpasero do you want me to make the changes to take out undefined?

@bpasero
Copy link
Member

bpasero commented Jun 13, 2017

@eamodio yes, thanks

@eamodio
Copy link
Contributor Author

eamodio commented Jun 20, 2017

@bpasero I (hopefully) removed all the undefined's from the internal calls -- though I left it from calls from extensions. I also rebased this branch to master as well. Let me know if you want me to make any other changes.

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.

@eamodio Thanks, I think we can still reduce the number of changes.

@@ -319,7 +319,14 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
// while the UI is not yet ready. Clients have to deal with this fact and we have to make sure that the
// stacks model gets updated if any of the UI updating fails with an error.
const group = this.ensureGroup(position, !options || !options.preserveFocus);
const pinned = !this.tabOptions.previewEditors || (options && (options.pinned || typeof options.index === 'number')) || input.isDirty();

let pinned = !this.tabOptions.previewEditors;
Copy link
Member

Choose a reason for hiding this comment

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

Can we leave this as:

const pinned = !this.tabOptions.previewEditors || (options && (options.pinned || typeof options.index === 'number')) || input.isDirty();

I see now reason to change it and find the new code unreadable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This allows pinned: false to be honored explicitly rather than it falling through as a default.

Copy link
Member

Choose a reason for hiding this comment

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

@eamodio I am not sure we can do that, e.g. some code relies on the fact that dirty and untitled files open as pinned and never as preview which would replace them once another preview opens.

@@ -589,7 +589,7 @@ export class TextEditorOptions extends EditorOptions {
public static from(input: IBaseResourceInput): TextEditorOptions {
let options: TextEditorOptions = null;
if (input && input.options) {
if (input.options.selection || input.options.viewState || input.options.forceOpen || input.options.revealIfVisible || input.options.revealIfOpened || input.options.preserveFocus || input.options.pinned || input.options.inactive || typeof input.options.index === 'number') {
if (input.options.selection || input.options.viewState || input.options.forceOpen || input.options.revealIfVisible || input.options.revealIfOpened || input.options.preserveFocus || input.options.pinned !== undefined || input.options.inactive || typeof input.options.index === 'number') {
Copy link
Member

Choose a reason for hiding this comment

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

Why are changes in this file needed, I suggest to leave it as it was?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This allows pinned: false to be honored explicitly rather than it falling through as a default.

Copy link
Member

Choose a reason for hiding this comment

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

Again, forcing pinned: false is not possible currently.

@@ -401,7 +401,7 @@ export function registerCommands(): void {
if (!options || typeof options !== 'object') {
options = {
preserveFocus: false,
pinned: true
pinned: undefined
Copy link
Member

Choose a reason for hiding this comment

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

Remove pinned: undefined

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do

@@ -614,8 +614,8 @@ export class TextEditorOptions extends EditorOptions {
options.preserveFocus = true;
}

if (input.options.pinned) {
options.pinned = true;
if (input.options.pinned !== undefined) {
Copy link
Member

Choose a reason for hiding this comment

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

Leave as it was?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above

@bpasero bpasero modified the milestones: On Deck, June 2017 Jun 20, 2017
@eamodio
Copy link
Contributor Author

eamodio commented Jun 27, 2017

@bpasero Any thoughts on the above?

let editorOptions: IEditorOptions;
if (options) {
editorOptions = {
pinned: !options.preview,
pinned: options.preview === undefined ? undefined : !options.preview,
Copy link
Member

Choose a reason for hiding this comment

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

I better like: typeof options.preview === 'boolean' ? !options.preview : undefined

};
} else if (typeof columnOrOptions === 'object') {
options = {
position: TypeConverters.fromViewColumn(columnOrOptions.viewColumn),
preserveFocus: columnOrOptions.preserveFocus,
pinned: columnOrOptions.preview === undefined ? true : !columnOrOptions.preview
pinned: columnOrOptions.preview === undefined ? undefined : !columnOrOptions.preview
Copy link
Member

Choose a reason for hiding this comment

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

I better like: typeof columnOrOptions.preview === 'boolean' ? ! columnOrOptions.preview : undefined

@@ -319,7 +319,14 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
// while the UI is not yet ready. Clients have to deal with this fact and we have to make sure that the
// stacks model gets updated if any of the UI updating fails with an error.
const group = this.ensureGroup(position, !options || !options.preserveFocus);
const pinned = !this.tabOptions.previewEditors || (options && (options.pinned || typeof options.index === 'number')) || input.isDirty();

let pinned = !this.tabOptions.previewEditors;
Copy link
Member

Choose a reason for hiding this comment

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

@eamodio I am not sure we can do that, e.g. some code relies on the fact that dirty and untitled files open as pinned and never as preview which would replace them once another preview opens.

@@ -589,7 +589,7 @@ export class TextEditorOptions extends EditorOptions {
public static from(input: IBaseResourceInput): TextEditorOptions {
let options: TextEditorOptions = null;
if (input && input.options) {
if (input.options.selection || input.options.viewState || input.options.forceOpen || input.options.revealIfVisible || input.options.revealIfOpened || input.options.preserveFocus || input.options.pinned || input.options.inactive || typeof input.options.index === 'number') {
if (input.options.selection || input.options.viewState || input.options.forceOpen || input.options.revealIfVisible || input.options.revealIfOpened || input.options.preserveFocus || input.options.pinned !== undefined || input.options.inactive || typeof input.options.index === 'number') {
Copy link
Member

Choose a reason for hiding this comment

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

Again, forcing pinned: false is not possible currently.

@bpasero
Copy link
Member

bpasero commented Jun 28, 2017

@eamodio what is the use case for forcing an editor to be not-pinned (= previewed)? Can you give me an example?

@bpasero
Copy link
Member

bpasero commented Jul 5, 2017

@eamodio in your demo today at lunch, you indicated that you wanted to open diff editors from the picker as preview and not pinned. But is that really an issue still if we do not set the pinned state by default from extensions? It seems to me the original request for pinned: false only existed because we used to set pinned: true by default. If you would just not set the pinned attribute at all, any editor you open should show up as preview editor unless the user has disabled this feature.

@eamodio
Copy link
Contributor Author

eamodio commented Jul 5, 2017

@bpasero Yeah, just being able to control it is enough. Though the main reason I wanted to plumb it all the way through was so that the final code could know the expressed desire of the extension, because it was passed as false, not left undefined. The only actual difference this would have is if this condition is met: (options && typeof options.index === 'number') || input.isDirty(), because those cases could end up changing pinned to true, even though false was passed. While this is true of the overall "preview editors" setting -- that feels different. IMO at least ;)

@bpasero bpasero merged commit 4f50b29 into microsoft:master Jul 6, 2017
@bpasero bpasero modified the milestones: July 2017, On Deck Jul 6, 2017
@bpasero
Copy link
Member

bpasero commented Jul 6, 2017

@eamodio thanks. I made some changes on top of yours. My argument is still that the pinned state cannot be overridden by the user if explicitly defined. Lots of stuff in the editor world depends on a dirty file being pinned for example (you cannot have a dirty file that shows up as preview).

I went ahead and merged the PR because the original request seems addressed.

@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.

None yet

6 participants