Skip to content

Addresses #26184 - use configuration for pinned default - #27357

Merged
Benjamin Pasero (bpasero) merged 6 commits into
microsoft:masterfrom
eamodio:feature-pinned-default
Jul 6, 2017
Merged

Benjamin Pasero (bpasero) merged 6 commits into
microsoft:masterfrom
eamodio:feature-pinned-default

Conversation

@eamodio

Copy link
Copy Markdown
Contributor

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 Johannes Rieken (@jrieken) Benjamin Pasero (@bpasero)

@mention-bot

Copy link
Copy Markdown

Eric Amodio (@eamodio), thanks for your PR! By analyzing the history of the files in this pull request, we identified Johannes Rieken (@jrieken) and Erich Gamma (@egamma) to be potential reviewers.

@jrieken

Copy link
Copy Markdown
Contributor

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

@eamodio

Copy link
Copy Markdown
Contributor Author

Johannes Rieken (@jrieken) I've re-worked this completely to move it down to hopefully the lowest level. So as per Benjamin Pasero (@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
Copy Markdown
Contributor

Eric Amodio (@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
Copy Markdown
Contributor Author

Benjamin Pasero (@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
Copy Markdown
Contributor Author

Benjamin Pasero (@bpasero) Updated to honor workbench.editor.enablePreview above all else

@jrieken

Copy link
Copy Markdown
Contributor

Not sure how this should work Benjamin Pasero (@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
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

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.

@bpasero Benjamin Pasero (bpasero) left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

Benjamin Pasero (@bpasero) do you want me to make the changes to take out undefined?

@bpasero

Copy link
Copy Markdown
Contributor

Eric Amodio (@eamodio) yes, thanks

@eamodio

Copy link
Copy Markdown
Contributor Author

Benjamin Pasero (@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.

@bpasero Benjamin Pasero (bpasero) left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Eric Amodio (@eamodio) Thanks, I think we can still reduce the number of changes.

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
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Eric Amodio (@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.

Comment thread src/vs/workbench/common/editor.ts Outdated
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
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor

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.

options = {
preserveFocus: false,
pinned: true
pinned: undefined

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will do

Comment thread src/vs/workbench/common/editor.ts Outdated

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

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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

@eamodio

Copy link
Copy Markdown
Contributor Author

Benjamin Pasero (@bpasero) Any thoughts on the above?

if (options) {
editorOptions = {
pinned: !options.preview,
pinned: options.preview === undefined ? undefined : !options.preview,

Copy link
Copy Markdown
Contributor

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

position: TypeConverters.fromViewColumn(columnOrOptions.viewColumn),
preserveFocus: columnOrOptions.preserveFocus,
pinned: columnOrOptions.preview === undefined ? true : !columnOrOptions.preview
pinned: columnOrOptions.preview === undefined ? undefined : !columnOrOptions.preview

Copy link
Copy Markdown
Contributor

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

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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Eric Amodio (@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.

Comment thread src/vs/workbench/common/editor.ts Outdated
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
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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

@bpasero

Copy link
Copy Markdown
Contributor

Eric Amodio (@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
Copy Markdown
Contributor Author

Benjamin Pasero (@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
Benjamin Pasero (bpasero) merged commit 4f50b29 into microsoft:master Jul 6, 2017
@bpasero

Copy link
Copy Markdown
Contributor

Eric Amodio (@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.

6 participants