-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
Conversation
I have the feeling that this would be a lot more simple if that is implemented in the |
af5ddc3
to
14973d6
Compare
@jrieken I've re-worked this completely to move it down to hopefully the lowest level. So as per @bpasero comments, if you pass |
@eamodio this is a bad change as it can result in editors showing up as preview even though I think what Joh meant is to implement this behaviour only in the |
@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 If that isn't the case and |
@bpasero Updated to honor |
Not sure how this should work @bpasero? Now |
I do not really understand the need for introducing 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. |
When I wasn't honoring Although honestly, I'd rather leave |
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.
-1 for using undefined everywhere. +1 for not setting preview from extensions unless explicitly set.
@bpasero do you want me to make the changes to take out |
@eamodio yes, thanks |
00f4293
to
c01e0ce
Compare
@bpasero I (hopefully) removed all the |
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.
@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; |
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.
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.
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 allows pinned: false
to be honored explicitly rather than it falling through as a default.
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.
@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.
src/vs/workbench/common/editor.ts
Outdated
@@ -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') { |
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.
Why are changes in this file needed, I suggest to leave it as it was?
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 allows pinned: false
to be honored explicitly rather than it falling through as a default.
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.
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 |
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.
Remove pinned: undefined
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.
Will do
src/vs/workbench/common/editor.ts
Outdated
@@ -614,8 +614,8 @@ export class TextEditorOptions extends EditorOptions { | |||
options.preserveFocus = true; | |||
} | |||
|
|||
if (input.options.pinned) { | |||
options.pinned = true; | |||
if (input.options.pinned !== undefined) { |
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.
Leave as it was?
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.
Same as above
@bpasero Any thoughts on the above? |
let editorOptions: IEditorOptions; | ||
if (options) { | ||
editorOptions = { | ||
pinned: !options.preview, | ||
pinned: options.preview === undefined ? undefined : !options.preview, |
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 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 |
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 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; |
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.
@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.
src/vs/workbench/common/editor.ts
Outdated
@@ -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') { |
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.
Again, forcing pinned: false
is not possible currently.
@eamodio what is the use case for forcing an editor to be not-pinned (= previewed)? Can you give me an example? |
@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 |
@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: |
@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. |
Uses the configuration setting
workbench.editor.enablePreview
to provide a default ofpinned
if not explicitly passed. See #26184 (comment)Hopefully this is decent way of implementing this :)
/cc @jrieken @bpasero