Skip to content
Merged
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
24 changes: 14 additions & 10 deletions docs/users/reference/keyboard-shortcuts.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ This document lists the available keyboard shortcuts in Qwen Code.
| `Tab` | Autocomplete the current suggestion if one exists. |
| `Up Arrow` | Row up, then snap to start, then history prev. |
| `Ctrl+A` / `Home` | Move the cursor to the beginning of the line. |
| `Ctrl+B` / `Left Arrow` | Move the cursor one character to the left. |
| `Ctrl+B` / `Left Arrow` | Move the cursor one character to the left. While the `@` completion menu shows category tabs, use `Ctrl+B` (the arrow switches tabs). |
| `Ctrl+C` | Clear the input prompt |
| `Esc` (double press) | Clear the input prompt. |
| `Ctrl+D` / `Delete` | Delete the character to the right of the cursor. |
| `Ctrl+E` / `End` | Move the cursor to the end of the line. |
| `Ctrl+F` / `Right Arrow` | Move the cursor one character to the right. |
| `Ctrl+F` / `Right Arrow` | Move the cursor one character to the right. While the `@` completion menu shows category tabs, use `Ctrl+F` (the arrow switches tabs). |
| `Ctrl+H` / `Backspace` | Delete the character to the left of the cursor. |
| `Ctrl+K` | Delete from the cursor to the end of the line. |
| `Ctrl+Left Arrow` / `Meta+Left Arrow` / `Meta+B` | Move the cursor one word to the left. |
Expand Down Expand Up @@ -81,14 +81,18 @@ Focus the Background tasks pill in the footer (use `Down Arrow` from an empty co

## Suggestions

| Shortcut | Description |
| ------------------------------------ | ------------------------------------------------------------------------ |
| `Down Arrow` / `Ctrl+N` | Navigate down through the suggestions. |
| `Tab` / `Enter` | Accept the selected suggestion. |
| `Up Arrow` / `Ctrl+P` | Navigate up through the suggestions. |
| `Right Arrow` | Accept a ghost-text suggestion when the prompt is empty. |
| `Ctrl+Tab` / `Ctrl+Right Arrow` | Switch to the next completion category when category tabs are shown. |
| `Ctrl+Shift+Tab` / `Ctrl+Left Arrow` | Switch to the previous completion category when category tabs are shown. |
| Shortcut | Description |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| `Down Arrow` / `Ctrl+N` | Navigate down through the suggestions. |
| `Tab` / `Enter` | Accept the selected suggestion. |
| `Up Arrow` / `Ctrl+P` | Navigate up through the suggestions. |
| `Right Arrow` | Switch to the next completion category when category tabs are shown. Also accepts a ghost-text suggestion when the prompt is empty. |
| `Left Arrow` | Switch to the previous completion category when category tabs are shown. |

> Note: while the `@` completion menu is showing category tabs, `Left Arrow` and
> `Right Arrow` switch categories instead of moving the cursor. Press `Esc` to
> dismiss the menu first if you need to move the cursor. `Alt/Option+Arrow` word
> movement is unaffected.

## History Search

Expand Down
26 changes: 15 additions & 11 deletions packages/cli/src/config/keyBindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,24 @@ export const defaultKeyBindings: KeyBindingConfig = {
{ key: 'n', ctrl: true },
],
// Completion category tab switching (for the tabbed @ completion UI).
// Bound to Ctrl+arrows rather than plain arrows so the bare arrow keys keep
// moving the caret in the editable input buffer (plain arrows only switch
// tabs in modal dialogs, which have no text buffer). Alt/Option+arrows still
// perform word movement.
// Ctrl+←/→ is the primary binding but many terminals intercept it for
// word-jump. Ctrl+Tab / Ctrl+Shift+Tab are alternatives that are less
// commonly intercepted (#8069).
// Bound to the BARE arrow keys: Ctrl+←/→ was the original binding but many
// terminals intercept it for word-jump, and on macOS the system claims it
// for Mission Control, so the documented gesture was unreachable for most
// users (#8069).
Comment on lines +190 to +191

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accurate — #8069 was already closed by merged PR #8074, and the live gap this PR actually closes is #8330 (Ctrl+Tab intercepted by Warp), with the complementary mouse-click fix in #8395. Updating the PR description is a GitHub write that this automated round cannot perform (it has no GitHub credentials; the workflow owns all GitHub writes), so it must be applied by a maintainer rather than in code. Suggested description wording: "Addresses the remaining gap from #8330; complements the mouse-click fix in #8395; #8069 was already closed by #8074." No code change is required for this finding.

中文说明

确实如此—— #8069 已被合并的 PR #8074 关闭,本 PR 实际修复的活跃缺口是 #8330(Ctrl+Tab 被 Warp 拦截),互补的鼠标点击修复是 #8395。更新 PR 描述属于 GitHub 写操作,本轮自动化无法执行(没有 GitHub 凭据,所有 GitHub 写操作由工作流负责),因此需要由维护者应用而非通过代码完成。建议的描述措辞为:"Addresses the remaining gap from #8330; complements the mouse-click fix in #8395; #8069 was already closed by #8074"。该发现无需代码改动。

//
// Tradeoff, accepted deliberately: while the `@` category tabs are visible,
// the bare arrows no longer move the caret in the input buffer — press Esc
// to dismiss the menu first. InputPrompt only renders and handles the tabs
// when they own the arrows, so search and attachment navigation keep their
// normal behavior.
//
// Modifiers are pinned false so Alt/Option+arrow word movement and any
// Ctrl+arrow terminal binding fall through untouched.
[Command.COMPLETION_TAB_LEFT]: [
{ key: 'left', shift: false, ctrl: true, command: false },
{ key: 'tab', shift: true, ctrl: true, command: false },
{ key: 'left', shift: false, ctrl: false, meta: false },
],
[Command.COMPLETION_TAB_RIGHT]: [
{ key: 'right', shift: false, ctrl: true, command: false },
{ key: 'tab', shift: false, ctrl: true, command: false },
{ key: 'right', shift: false, ctrl: false, meta: false },
],

// Text input
Expand Down
100 changes: 88 additions & 12 deletions packages/cli/src/ui/components/InputPrompt.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2709,7 +2709,7 @@ describe('InputPrompt', () => {
unmount();
});

it('should NOT switch category on Ctrl+left/right when availableCategories is exactly 2', async () => {
it('should NOT switch category on left/right when availableCategories is exactly 2', async () => {
const switchCategory = vi.fn();
mockedUseCommandCompletion.mockReturnValue({
...mockCommandCompletion,
Expand All @@ -2726,18 +2726,18 @@ describe('InputPrompt', () => {
const { stdin, unmount } = renderWithProviders(<InputPrompt {...props} />);
await wait();

stdin.write('\x1b[1;5C'); // Ctrl+right arrow
stdin.write('\x1b[C'); // right arrow
await wait();
stdin.write('\x1b[1;5D'); // Ctrl+left arrow
stdin.write('\x1b[D'); // left arrow
await wait();

// With only 2 entries (all + one real category) the tab bar is hidden,
// so Ctrl+arrows must not trigger category switching.
// so the arrows must not trigger category switching.
expect(switchCategory).not.toHaveBeenCalled();
unmount();
});

it('should switch category on Ctrl+left/right when availableCategories > 2', async () => {
it('should switch category on plain arrows before Vim handling', async () => {
const switchCategory = vi.fn();
mockedUseCommandCompletion.mockReturnValue({
...mockCommandCompletion,
Expand All @@ -2753,23 +2753,99 @@ describe('InputPrompt', () => {
switchCategory,
});
props.buffer.setText('@');
props.vimHandleInput = vi.fn().mockReturnValue(true);

const { stdin, unmount } = renderWithProviders(<InputPrompt {...props} />);
await wait();

stdin.write('\x1b[1;5C'); // Ctrl+right arrow
stdin.write('\x1b[C'); // plain right arrow
await wait();

expect(switchCategory).toHaveBeenCalledWith(1);

stdin.write('\x1b[1;5D'); // Ctrl+left arrow
stdin.write('\x1b[D'); // plain left arrow
await wait();

expect(switchCategory).toHaveBeenCalledWith(-1);
expect(props.vimHandleInput).not.toHaveBeenCalled();
unmount();
});

it('should NOT switch category on bare arrows while command search is active', async () => {
props.shellModeActive = false;
const switchCategory = vi.fn();
mockedUseCommandCompletion.mockReturnValue({
...mockCommandCompletion,
completionMode: CompletionMode.AT,
showSuggestions: true,
suggestions: [
{ label: 'file.ts', value: 'file.ts', category: 'file' },
{ label: 'sess', value: 'sess', category: 'session' },
],
activeSuggestionIndex: 0,
isPerfectMatch: false,
availableCategories: ['all', 'file', 'session'],
switchCategory,
});
props.buffer.setText('@ses');

const { stdin, unmount } = renderWithProviders(<InputPrompt {...props} />);
await wait();

stdin.write('\x12');
await wait();
stdin.write('\x1b[C');
await wait();
stdin.write('\x1b[D');
await wait();

expect(switchCategory).not.toHaveBeenCalled();
unmount();
});

it('should NOT switch category on plain left/right when availableCategories > 2 (caret stays free)', async () => {
it('should hide category tabs and keep bare arrows for attachments', async () => {
const isWindows = process.platform === 'win32';
vi.mocked(clipboardUtils.clipboardHasImage).mockResolvedValue(true);
vi.mocked(clipboardUtils.saveClipboardImage).mockResolvedValue(
path.join('test', 'project', '.qwen', 'tmp', 'clipboard.png'),
);
vi.mocked(clipboardUtils.cleanupOldClipboardImages).mockResolvedValue(
undefined,
);

const switchCategory = vi.fn();
mockedUseCommandCompletion.mockReturnValue({
...mockCommandCompletion,
completionMode: CompletionMode.AT,
showSuggestions: true,
suggestions: [{ label: 'file.ts', value: 'file.ts', category: 'file' }],
activeSuggestionIndex: 0,
isPerfectMatch: false,
availableCategories: ['all', 'file', 'session'],
switchCategory,
});
props.buffer.setText('@');

const { stdin, lastFrame, unmount } = renderWithProviders(
<InputPrompt {...props} />,
);
await wait();

stdin.write(isWindows ? '\x1Bv' : '\x16');
await wait();
stdin.write('\x1b[A');
await wait();
stdin.write('\x1b[C');
await wait();
stdin.write('\x1b[D');
await wait();

expect(switchCategory).not.toHaveBeenCalled();
expect(stripAnsi(lastFrame() ?? '')).not.toContain('(←/→ to switch)');
unmount();
});

it('should NOT consume Ctrl+left/right for category switching (#8069)', async () => {
const switchCategory = vi.fn();
mockedUseCommandCompletion.mockReturnValue({
...mockCommandCompletion,
Expand All @@ -2789,13 +2865,13 @@ describe('InputPrompt', () => {
const { stdin, unmount } = renderWithProviders(<InputPrompt {...props} />);
await wait();

stdin.write('\x1b[C'); // plain right arrow
stdin.write('\x1b[1;5C'); // Ctrl+right arrow
await wait();
stdin.write('\x1b[D'); // plain left arrow
stdin.write('\x1b[1;5D'); // Ctrl+left arrow
await wait();

// Plain arrows must not be hijacked for tab switching, so they remain
// available to move the caret in the editable buffer.
// Ctrl+arrows are no longer bound: terminals and macOS Mission Control
// intercept them, so they are left to fall through to the terminal.
expect(switchCategory).not.toHaveBeenCalled();
unmount();
});
Expand Down
45 changes: 23 additions & 22 deletions packages/cli/src/ui/components/InputPrompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,12 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
);
const showCompletionSuggestions =
completion.showSuggestions && !isHistoryRestoredText;
const categoryTabsVisible =
!exportCompletion.suggestionDisplayProps &&
!commandSearchActive &&
!reverseSearchActive &&
!isAttachmentMode &&
(completion.availableCategories?.length ?? 0) > 2;

// Ref so renderLineWithHighlighting (stable useCallback) can access fresh ghost text
const midInputGhostTextRef = useRef<{
Expand Down Expand Up @@ -1081,6 +1087,21 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
return true;
}

// The visible category tabs own the bare arrows, including in Vim mode.
// All other states fall through to their existing input owner.
if (showCompletionSuggestions && categoryTabsVisible) {
if (keyMatchers[Command.COMPLETION_TAB_RIGHT](key)) {
completion.switchCategory(1);
setExpandedSuggestionIndex(-1);
return true;
}
if (keyMatchers[Command.COMPLETION_TAB_LEFT](key)) {
completion.switchCategory(-1);
setExpandedSuggestionIndex(-1);
return true;
}
}

if (vimHandleInput && vimHandleInput(key)) {
return true;
}
Expand Down Expand Up @@ -1442,23 +1463,6 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
}

if (showCompletionSuggestions) {
// Category tab switching for the tabbed `@` completion UI. Only consume
// Ctrl+←/→ (per the COMPLETION_TAB_* bindings) and only when there are
// more than two tabs (at least 3 entries including 'all'). Plain ←/→ are
// never consumed here, so they always move the caret in the editable buffer.
if ((completion.availableCategories?.length ?? 0) > 2) {
if (keyMatchers[Command.COMPLETION_TAB_RIGHT](key)) {
completion.switchCategory(1);
setExpandedSuggestionIndex(-1);
return true;
}
if (keyMatchers[Command.COMPLETION_TAB_LEFT](key)) {
completion.switchCategory(-1);
setExpandedSuggestionIndex(-1);
return true;
}
}

if (completion.suggestions.length > 1) {
const isCompletionUpKey = keyMatchers[Command.COMPLETION_UP](key);
const isCompletionDownKey = keyMatchers[Command.COMPLETION_DOWN](key);
Expand Down Expand Up @@ -1907,6 +1911,7 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
exportCompletion,
isHistoryRestoredText,
showCompletionSuggestions,
categoryTabsVisible,
voiceInput,
targetDir,
],
Expand Down Expand Up @@ -2308,11 +2313,7 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
: completion.activeCategory
}
availableCategories={
suggestionsFromExport ||
commandSearchActive ||
reverseSearchActive
? undefined
: completion.availableCategories
categoryTabsVisible ? completion.availableCategories : undefined
}
onHoverIndex={
suggestionsFromExport ? undefined : handleSuggestionHover
Expand Down
8 changes: 3 additions & 5 deletions packages/cli/src/ui/components/SuggestionsDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,10 @@ export function SuggestionsDisplay({
</Box>
);
})}
{/* Mention Ctrl+Tab as an alternative since many terminals
intercept Ctrl+←/→ for word-jump (#8069). */}
{/* Bare ←/→: the original Ctrl+←/→ was unreachable because terminals
and macOS Mission Control intercept it (#8069). */}
<Box marginLeft={2}>
<Text color={theme.text.secondary}>
{t('(Ctrl+Tab / Ctrl+Shift+Tab or Ctrl+←/→ to switch)')}
</Text>
<Text color={theme.text.secondary}>{t('(←/→ to switch)')}</Text>
</Box>
</Box>
)}
Expand Down
Loading
Loading