Skip to content

Make default text editor replace existing editors for resource - #112848

Merged
Matt Bierner (mjbvz) merged 4 commits into
microsoft:masterfrom
mjbvz:open-with-replace
Jan 13, 2021
Merged

Matt Bierner (mjbvz) merged 4 commits into
microsoft:masterfrom
mjbvz:open-with-replace

Conversation

@mjbvz

Copy link
Copy Markdown
Contributor

Fixes #111474

This ports the logic that we previously had for custom editors to the generic open with flow:

const existingEditors = targetGroup.editors.filter(editor => editor.resource && isEqual(editor.resource, resource));

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

I am not entirely sure the purpose: is it to have a first entry in the "Open With..." picker to open as text? And then if the editor is already opened we replace the editor instead of opening a new one? What happens if you do not replace, do we open another editor and the original one is also there?

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.

Instead of looping over all editors in the group, I would do a quick first this.isOpen({ resource }) to see if the editor is open after all. This is a very fast Set lookup without loops and can be used to return quickly.

@mjbvz

Copy link
Copy Markdown
Contributor Author

Thanks Benjamin Pasero (@bpasero)! Just pushed the suggested 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.

Matt Bierner (@mjbvz) one thing I forgot to ask for: is it possible to add a unit test for this new method?

Matt Bierner added 3 commits January 13, 2021 12:53
This adds a `IEditorService.getEditorsForResource` method that returns all editors associated with a given resource. I've adopted this for custom editors and notebooks
@mjbvz
Matt Bierner (mjbvz) merged commit 6c4a00c into microsoft:master Jan 13, 2021
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 27, 2021
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.

"Toggle Editor Type" creates corrupted new view that cannot be opened

2 participants