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

Handling/Disabling Diff Views in Custom Text Editors #97683

Closed
hediet opened this issue May 13, 2020 · 7 comments
Closed

Handling/Disabling Diff Views in Custom Text Editors #97683

hediet opened this issue May 13, 2020 · 7 comments
Assignees
Labels
custom-editors Custom editor API (webview based editors) *question Issue represents a question, should be posted to StackOverflow (VS Code)

Comments

@hediet
Copy link
Member

hediet commented May 13, 2020

My drawio custom text editor cannot handle diff views, neither conceptually nor technically.
Currently, this seems to happen, when a diff is viewed:

Diff views don't seem to be covered by the custom text editor API, yet custom text editors are used to display them.

It would be great if I could disable that my extension handles diff views, so that VS Code falls back to the default text editor for displaying the diff. In my case, the underlying document is XML, and viewing XML diffs with the default text editor provides a much better experience than the current behavior.

@mjbvz
Copy link
Collaborator

mjbvz commented May 13, 2020

Custom editors implicitly support diff views without a special API. Here's the builtin image preview for example showing in a diff view:

Screen Shot 2020-05-13 at 11 59 38 AM

Keep in mind that editors in diff views are often readonly so if you are building an editable custom editor, you should disable user interface and operations related to editing.

You can detect if you are in a diff view by looking at the resource uri passed to your custom editor. Git for example uses uris such as:

"git:/Users/matb/projects/vscode/extensions/image-preview/icon.png?%7B%22path%22%3A%22%2FUsers%2Fmatb%2Fprojects%2Fvscode%2Fextensions%2Fimage-preview%2Ficon.png%22%2C%22ref%22%3A%22~%22%7D"

VS Code's file system provider can read these uris.

@mjbvz mjbvz closed this as completed May 13, 2020
@mjbvz mjbvz added the *question Issue represents a question, should be posted to StackOverflow (VS Code) label May 13, 2020
@mjbvz
Copy link
Collaborator

mjbvz commented May 13, 2020

This is probably worth documenting more as well in the custom editor docs

@mjbvz mjbvz added the custom-editors Custom editor API (webview based editors) label May 13, 2020
@rdeline
Copy link
Contributor

rdeline commented May 15, 2020

I'm not sure the answer above is complete. In a diff, the left-hand side is read-only and its URI scheme is 'git', as @mattbierner said. However, the right-hand side is not read-only and its URI scheme is 'file'. So if a custom text editor wants to do something special for diffs, I don't see how to detect the right-hand side.

Also, for custom text editors that want to show the diff highlighting, is there a way to do that? I agree with @hediet that for many use cases (including mine), the easiest thing would be to let the normal text editor handle diffs.

@mjbvz
Copy link
Collaborator

mjbvz commented May 15, 2020

In many cases—such as previews—you don't really need to highlighting the diffs themselves since the preview visually shows users what has changed. If your editor can support highlighting diffs though, try track active custom editors to determine if the right hand side is for a diff or not. If this isn't sufficient, we could explore adding a property that indicates if you are in a diff or not

Showing a diff of the text content is not going to be a good user experience in most cases so we do not what want extensions to fallback to that behavior. You can provide a fairly good user experience just by making sure your custom editor supports being opened on git: resource. The right hand side then will either be another git: resource or an editable resource from the workspace

@rdeline
Copy link
Contributor

rdeline commented May 15, 2020

I'm not sure what "track active custom editors" means exactly. Do you mean something like the next editor opened after a 'git' editor is also part of a diff?

Also, in terms of showing text diffs, my use case is similar to Jupyter Notebooks (that is, it's text plus other stuff). To use Jupyter Notebooks as a use case, it would be desirable to show text differences in the cells, even though we can't really show "diffs" of the plots.

@hediet
Copy link
Member Author

hediet commented May 15, 2020

I still think that text diffs actually do provide the better user experience in my case. This might also be the case for the wysiwyg markdown editor someone I know is working on.

Editors are not necessarily a good preview. In a text diff, changes are highlighted and you get an inline diff mode. You don't get these things for a wysiwyg markdown editor or a drawio diagram where a single label has been changed.

@hediet
Copy link
Member Author

hediet commented May 30, 2020

@mjbvz a similar view is shown for conflict resolution (conflictResolution schema).
Is there a generic way to identify those views?
Can I somehow detect whether a TextDocument is readonly?

@github-actions github-actions bot locked and limited conversation to collaborators Jun 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
custom-editors Custom editor API (webview based editors) *question Issue represents a question, should be posted to StackOverflow (VS Code)
Projects
None yet
Development

No branches or pull requests

3 participants