fix(cli): restore ? shortcuts in vim normal mode

This commit is contained in:
YingchaoX 2026-04-04 22:24:56 +08:00
parent 3bce84d5da
commit 0be974b1d7
3 changed files with 53 additions and 0 deletions

View file

@ -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', () => {

View file

@ -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') {