mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-05-05 07:10:55 +00:00
fix(cli): restore ? shortcuts in vim normal mode
This commit is contained in:
parent
3bce84d5da
commit
0be974b1d7
3 changed files with 53 additions and 0 deletions
|
|
@ -1300,6 +1300,23 @@ describe('InputPrompt', () => {
|
|||
expect(mockBuffer.handleInput).toHaveBeenCalled();
|
||||
unmount();
|
||||
});
|
||||
|
||||
it('should toggle shortcuts when vim passes through ? on an empty prompt', async () => {
|
||||
props.vimHandleInput = vi.fn().mockReturnValue(false);
|
||||
props.onToggleShortcuts = vi.fn();
|
||||
|
||||
const { stdin, unmount } = renderWithProviders(
|
||||
<InputPrompt {...props} />,
|
||||
);
|
||||
await wait();
|
||||
|
||||
stdin.write('?');
|
||||
await wait();
|
||||
|
||||
expect(props.vimHandleInput).toHaveBeenCalled();
|
||||
expect(props.onToggleShortcuts).toHaveBeenCalled();
|
||||
unmount();
|
||||
});
|
||||
});
|
||||
|
||||
describe('unfocused paste', () => {
|
||||
|
|
|
|||
|
|
@ -215,6 +215,31 @@ describe('useVim hook', () => {
|
|||
|
||||
expect(testBuffer.vimMoveWordBackward).toHaveBeenCalledWith(1);
|
||||
});
|
||||
|
||||
it('should pass through ? in NORMAL mode when the buffer is empty', () => {
|
||||
const emptyBuffer = createMockBuffer('', [0, 0]);
|
||||
emptyBuffer.lines = [''];
|
||||
emptyBuffer.text = '';
|
||||
const { result } = renderVimHook(emptyBuffer);
|
||||
|
||||
let handled = true;
|
||||
act(() => {
|
||||
handled = result.current.handleInput({ sequence: '?', name: '' });
|
||||
});
|
||||
|
||||
expect(handled).toBe(false);
|
||||
});
|
||||
|
||||
it('should still handle ? in NORMAL mode when the buffer is not empty', () => {
|
||||
const { result } = renderVimHook();
|
||||
|
||||
let handled = false;
|
||||
act(() => {
|
||||
handled = result.current.handleInput({ sequence: '?', name: '' });
|
||||
});
|
||||
|
||||
expect(handled).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Navigation commands', () => {
|
||||
|
|
|
|||
|
|
@ -411,6 +411,17 @@ export function useVim(buffer: TextBuffer, onSubmit?: (value: string) => void) {
|
|||
|
||||
// Handle NORMAL mode
|
||||
if (state.mode === 'NORMAL') {
|
||||
// Let the documented shortcuts panel toggle handle plain `?` when the
|
||||
// prompt is empty and vim is otherwise idle.
|
||||
if (
|
||||
normalizedKey.sequence === '?' &&
|
||||
buffer.text.length === 0 &&
|
||||
state.pendingOperator === null &&
|
||||
state.count === 0
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If in NORMAL mode, allow escape to pass through to other handlers
|
||||
// if there's no pending operation.
|
||||
if (normalizedKey.name === 'escape') {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue