Skip to content

Commit 2064368

Browse files
authored
Merge pull request #285416 from microsoft/dev/dmitriv/diff-peek-focus-toggle
Enable `togglePeekWidgetFocus` command for quick diff pick view
2 parents 36798b8 + 8046927 commit 2064368

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/vs/workbench/contrib/scm/browser/quickDiffWidget.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import { ThemeIcon } from '../../../../base/common/themables.js';
4747
import { gotoNextLocation, gotoPreviousLocation } from '../../../../platform/theme/common/iconRegistry.js';
4848
import { Codicon } from '../../../../base/common/codicons.js';
4949
import { Color } from '../../../../base/common/color.js';
50-
import { KeyCode, KeyMod } from '../../../../base/common/keyCodes.js';
50+
import { KeyChord, KeyCode, KeyMod } from '../../../../base/common/keyCodes.js';
5151
import { getOuterEditor } from '../../../../editor/browser/widget/codeEditor/embeddedCodeEditorWidget.js';
5252
import { quickDiffDecorationCount } from './quickDiffDecorator.js';
5353
import { hasNativeContextMenu } from '../../../../platform/window/common/window.js';
@@ -464,6 +464,14 @@ class QuickDiffWidget extends PeekViewWidget {
464464
return this.diffEditor.hasTextFocus();
465465
}
466466

467+
toggleFocus(): void {
468+
if (this.diffEditor.hasTextFocus()) {
469+
this.editor.focus();
470+
} else {
471+
this.diffEditor.focus();
472+
}
473+
}
474+
467475
override dispose() {
468476
this.dropdown?.dispose();
469477
this.menu?.dispose();
@@ -547,6 +555,12 @@ export class QuickDiffEditorController extends Disposable implements IEditorCont
547555
this.widget?.showChange(this.widget.index, false);
548556
}
549557

558+
toggleFocus(): void {
559+
if (this.widget) {
560+
this.widget.toggleFocus();
561+
}
562+
}
563+
550564
next(lineNumber?: number): void {
551565
if (!this.assertWidget()) {
552566
return;
@@ -940,6 +954,26 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
940954
}
941955
});
942956

957+
KeybindingsRegistry.registerCommandAndKeybindingRule({
958+
id: 'togglePeekWidgetFocus',
959+
weight: KeybindingWeight.EditorContrib,
960+
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyCode.F2),
961+
when: isQuickDiffVisible,
962+
handler: (accessor: ServicesAccessor) => {
963+
const outerEditor = getOuterEditorFromDiffEditor(accessor);
964+
if (!outerEditor) {
965+
return;
966+
}
967+
968+
const controller = QuickDiffEditorController.get(outerEditor);
969+
if (!controller) {
970+
return;
971+
}
972+
973+
controller.toggleFocus();
974+
}
975+
});
976+
943977
function setPositionAndSelection(change: IChange, editor: ICodeEditor, accessibilityService: IAccessibilityService, codeEditorService: ICodeEditorService) {
944978
const position = new Position(change.modifiedStartLineNumber, 1);
945979
editor.setPosition(position);

0 commit comments

Comments
 (0)