Skip to content

Fix Cmd+R keybinding conflict in pull request webview #7119

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- Fails to open PR's description in some repos on GitHub Enterprise. https://github.com/microsoft/vscode-pull-request-github/issues/6736
- Support closing an issue. https://github.com/microsoft/vscode-pull-request-github/issues/6864
- Pull request diff shows outdated diff. https://github.com/microsoft/vscode-pull-request-github/issues/6889
- Fixed conflict with customized Cmd+R/Ctrl+R keybindings in pull request webview. The refresh functionality now works exclusively through VSCode keybindings, allowing users to customize the shortcut without conflicts.

**_Thank You_**

Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1785,6 +1785,12 @@
"mac": "cmd+k m",
"command": "pr.makeSuggestion",
"when": "commentEditorFocused"
},
{
"key": "ctrl+r",
"mac": "cmd+r",
"command": "pr.refreshDescription",
"when": "github:pullRequestDescriptionVisible"
}
],
"menus": {
Expand Down
5 changes: 5 additions & 0 deletions webviews/editorWebview/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export function Root({ children }) {
ctx.onchange = setPR;
setPR(ctx.pr);
}, []);

// Removed keyboard handling for Cmd+R refresh to avoid conflicts with VSCode keybindings
// The refresh functionality is now handled exclusively through the VSCode keybinding:
// "pr.refreshDescription" command with "when": "github:pullRequestDescriptionVisible"

window.onscroll = debounce(() => {
ctx.postMessage({
command: 'scroll',
Expand Down
34 changes: 34 additions & 0 deletions webviews/editorWebview/test/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,38 @@ describe('Root', function () {

assert(children.calledWith(pr));
});

it('does not handle Cmd+R keyboard events to avoid conflicts with VSCode keybindings', function () {
const pr = new PullRequestBuilder().build();
const context = new PRContext(pr);
const refreshSpy = sinon.spy(context, 'refresh');
const children = sinon.stub().returns(<div />);

render(
<PullRequestContext.Provider value={context}>
<Root>{children}</Root>
</PullRequestContext.Provider>,
);

// Simulate Cmd+R key press
const keyDownEvent = new KeyboardEvent('keydown', {
key: 'r',
metaKey: true, // Cmd key on Mac
bubbles: true,
});

document.dispatchEvent(keyDownEvent);

// Simulate Ctrl+R key press
const ctrlKeyDownEvent = new KeyboardEvent('keydown', {
key: 'r',
ctrlKey: true, // Ctrl key on Windows/Linux
bubbles: true,
});

document.dispatchEvent(ctrlKeyDownEvent);

// Verify that the webview does not handle these keyboard events
assert(!refreshSpy.called, 'refresh should not be called by webview keyboard handling');
});
});
Loading