Do not leave an editor behind when the unified diff falls back - #2853
Merged
vogella merged 1 commit intoAug 7, 2026
Merged
Conversation
Opening the unified diff opens the text editor first and only then finds out whether the diff can be applied at all: the editor registered for the file may not be a text editor, or applying the diff may fail. In those cases the classic compare editor takes over, but the editor opened a moment earlier stayed open, so the user ended up with two editors on the same file, one of them without any comparison in it. That is what happens for file types whose default editor is not a text editor. An editor opened by this code is now closed again before falling back. One that was already open is left alone, and it is recognized by comparing the part openEditor returns with the one found beforehand, rather than by asking twice whether an editor exists. On the fallback path the editor briefly becomes visible before it closes again. Avoiding that would mean knowing the part type without opening it.
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Opening the unified diff opens the text editor first and only then finds out whether the diff can be applied at all: the editor registered for the file may not be a text editor, or applying the diff may fail. In those cases the classic compare editor takes over, but the editor opened a moment earlier stayed open, so the user ended up with two editors on the same file, one of them without any comparison in it.
An editor opened by this code is now closed again before falling back, while one that was already open is left alone. The two are told apart by comparing the part
openEditorreturns with the one found beforehand, rather than by asking twice whether an editor exists. On the fallback path the editor briefly becomes visible before it closes again; avoiding that would mean knowing the part type without opening it.The regression test registers a deliberately non-text editor for a test-only file extension, so the fallback is reproducible without depending on which editors happen to be in the target platform. A second test covers the other direction, that an editor the user already had open survives.
Contributes to #2795