-
Notifications
You must be signed in to change notification settings - Fork 29.3k
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
Comments
Custom editors implicitly support diff views without a special API. Here's the builtin image preview for example showing in a diff view: 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:
VS Code's file system provider can read these uris. |
This is probably worth documenting more as well in the custom editor docs |
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. |
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 |
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. |
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. |
@mjbvz a similar view is shown for conflict resolution ( |
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.
The text was updated successfully, but these errors were encountered: