Git - resolve the active notebook for Open Changes / Open File#326468
Open
soreavis wants to merge 1 commit into
Open
Git - resolve the active notebook for Open Changes / Open File#326468soreavis wants to merge 1 commit into
soreavis wants to merge 1 commit into
Conversation
The keybinding path of git.openChange, git.openFile and git.openHEADFile resolves the target through getSCMResource, which only considered window.activeTextEditor. That is undefined when a notebook editor is active, so the commands silently did nothing for notebooks while the editor-title buttons and SCM context menu (which pass the resource) kept working. Resolve the notebook uri from window.activeNotebookEditor first, and fall back to a notebook diff editor's modified resource so Open File can toggle back from an open notebook diff, matching the text-editor behavior. Fixes microsoft#176401
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @lszomoruMatched files:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes Git commands failing to resolve active notebook resources.
Changes:
- Resolves active notebooks and notebook diffs in
getSCMResource. - Adds smoke coverage for opening notebook changes and returning to the file.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
extensions/git/src/commands.ts |
Adds notebook-aware SCM resource resolution. |
extensions/git/src/test/smoke.test.ts |
Tests notebook diff round-tripping. |
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.
Fixes #176401
Problem
Git: Open Changes,Git: Open FileandGit: Open File (HEAD)do nothing for notebooks when invoked from a keybinding (or the command palette), even though the editor-title buttons and the SCM context menu work.git.openChangelogsInvoking command git.openChangeand then silently returns.Cause
The keybinding path of these commands resolves the target through
getSCMResource, whose fallback only looked atwindow.activeTextEditor. That isundefinedwhen a notebook editor is active (and a focused cell is avscode-notebook-celleditor, which thefile-scheme check rejects), so no resource is found and the command returns. The buttons/menu work because they pass the resource explicitly.Fix
In
getSCMResource, resolvewindow.activeNotebookEditor?.notebook.uribefore falling back to the active text editor, and — since a notebook diff editor is neither the active text nor notebook editor — fall back to the activeTabInputNotebookDiff'smodifiedresource soOpen Filecan toggle back from an open notebook diff. This gives notebooks the same round-trip behavior text files already have.Validation
Verified in a dev build with
alt+d→git.openChange,alt+f→git.openFile:Added a git smoke test covering both directions (active notebook → Open Changes, then Open File back from the notebook diff). Full git integration suite green.
getSCMResourceis shared, sogit.stage/git.unstage/git.cleaninvoked via keybinding while a notebook is active now resolve the notebook file too, consistent with how they already work for text files.