mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-12 12:54:07 -07:00
Support ctrl-C and Ctrl-D correctly Refactor so InputPrompt has priority over AppContainer for input handling. (#17993)
This commit is contained in:
@@ -371,7 +371,9 @@ describe('AppContainer State Management', () => {
|
|||||||
mockedUseTextBuffer.mockReturnValue({
|
mockedUseTextBuffer.mockReturnValue({
|
||||||
text: '',
|
text: '',
|
||||||
setText: vi.fn(),
|
setText: vi.fn(),
|
||||||
// Add other properties if AppContainer uses them
|
lines: [''],
|
||||||
|
cursor: [0, 0],
|
||||||
|
handleInput: vi.fn().mockReturnValue(false),
|
||||||
});
|
});
|
||||||
mockedUseLogger.mockReturnValue({
|
mockedUseLogger.mockReturnValue({
|
||||||
getPreviousUserMessages: vi.fn().mockResolvedValue([]),
|
getPreviousUserMessages: vi.fn().mockResolvedValue([]),
|
||||||
@@ -1900,7 +1902,7 @@ describe('AppContainer State Management', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Keyboard Input Handling (CTRL+C / CTRL+D)', () => {
|
describe('Keyboard Input Handling (CTRL+C / CTRL+D)', () => {
|
||||||
let handleGlobalKeypress: (key: Key) => void;
|
let handleGlobalKeypress: (key: Key) => boolean;
|
||||||
let mockHandleSlashCommand: Mock;
|
let mockHandleSlashCommand: Mock;
|
||||||
let mockCancelOngoingRequest: Mock;
|
let mockCancelOngoingRequest: Mock;
|
||||||
let rerender: () => void;
|
let rerender: () => void;
|
||||||
@@ -1935,9 +1937,11 @@ describe('AppContainer State Management', () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// Capture the keypress handler from the AppContainer
|
// Capture the keypress handler from the AppContainer
|
||||||
mockedUseKeypress.mockImplementation((callback: (key: Key) => void) => {
|
mockedUseKeypress.mockImplementation(
|
||||||
handleGlobalKeypress = callback;
|
(callback: (key: Key) => boolean) => {
|
||||||
});
|
handleGlobalKeypress = callback;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
// Mock slash command handler
|
// Mock slash command handler
|
||||||
mockHandleSlashCommand = vi.fn();
|
mockHandleSlashCommand = vi.fn();
|
||||||
@@ -1961,6 +1965,9 @@ describe('AppContainer State Management', () => {
|
|||||||
mockedUseTextBuffer.mockReturnValue({
|
mockedUseTextBuffer.mockReturnValue({
|
||||||
text: '',
|
text: '',
|
||||||
setText: vi.fn(),
|
setText: vi.fn(),
|
||||||
|
lines: [''],
|
||||||
|
cursor: [0, 0],
|
||||||
|
handleInput: vi.fn().mockReturnValue(false),
|
||||||
});
|
});
|
||||||
|
|
||||||
vi.useFakeTimers();
|
vi.useFakeTimers();
|
||||||
@@ -2020,19 +2027,6 @@ describe('AppContainer State Management', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('CTRL+D', () => {
|
describe('CTRL+D', () => {
|
||||||
it('should do nothing if text buffer is not empty', async () => {
|
|
||||||
mockedUseTextBuffer.mockReturnValue({
|
|
||||||
text: 'some text',
|
|
||||||
setText: vi.fn(),
|
|
||||||
});
|
|
||||||
await setupKeypressTest();
|
|
||||||
|
|
||||||
pressKey({ name: 'd', ctrl: true }, 2);
|
|
||||||
|
|
||||||
expect(mockHandleSlashCommand).not.toHaveBeenCalled();
|
|
||||||
unmount();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should quit on second press if buffer is empty', async () => {
|
it('should quit on second press if buffer is empty', async () => {
|
||||||
await setupKeypressTest();
|
await setupKeypressTest();
|
||||||
|
|
||||||
@@ -2047,6 +2041,50 @@ describe('AppContainer State Management', () => {
|
|||||||
unmount();
|
unmount();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should NOT quit if buffer is not empty (bubbles from InputPrompt)', async () => {
|
||||||
|
mockedUseTextBuffer.mockReturnValue({
|
||||||
|
text: 'some text',
|
||||||
|
setText: vi.fn(),
|
||||||
|
lines: ['some text'],
|
||||||
|
cursor: [0, 9], // At the end
|
||||||
|
handleInput: vi.fn().mockReturnValue(false),
|
||||||
|
});
|
||||||
|
await setupKeypressTest();
|
||||||
|
|
||||||
|
// Capture return value
|
||||||
|
let result = true;
|
||||||
|
const originalPressKey = (key: Partial<Key>) => {
|
||||||
|
act(() => {
|
||||||
|
result = handleGlobalKeypress({
|
||||||
|
name: 'd',
|
||||||
|
shift: false,
|
||||||
|
alt: false,
|
||||||
|
ctrl: true,
|
||||||
|
cmd: false,
|
||||||
|
...key,
|
||||||
|
} as Key);
|
||||||
|
});
|
||||||
|
rerender();
|
||||||
|
};
|
||||||
|
|
||||||
|
originalPressKey({ name: 'd', ctrl: true });
|
||||||
|
|
||||||
|
// AppContainer's handler should return true if it reaches it
|
||||||
|
expect(result).toBe(true);
|
||||||
|
// But it should only be called once, so count is 1, not quitting yet.
|
||||||
|
expect(mockHandleSlashCommand).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
originalPressKey({ name: 'd', ctrl: true });
|
||||||
|
// Now count is 2, it should quit.
|
||||||
|
expect(mockHandleSlashCommand).toHaveBeenCalledWith(
|
||||||
|
'/quit',
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
|
||||||
it('should reset press count after a timeout', async () => {
|
it('should reset press count after a timeout', async () => {
|
||||||
await setupKeypressTest();
|
await setupKeypressTest();
|
||||||
|
|
||||||
@@ -2066,7 +2104,7 @@ describe('AppContainer State Management', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Copy Mode (CTRL+S)', () => {
|
describe('Copy Mode (CTRL+S)', () => {
|
||||||
let handleGlobalKeypress: (key: Key) => void;
|
let handleGlobalKeypress: (key: Key) => boolean;
|
||||||
let rerender: () => void;
|
let rerender: () => void;
|
||||||
let unmount: () => void;
|
let unmount: () => void;
|
||||||
|
|
||||||
@@ -2096,9 +2134,11 @@ describe('AppContainer State Management', () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mocks.mockStdout.write.mockClear();
|
mocks.mockStdout.write.mockClear();
|
||||||
mockedUseKeypress.mockImplementation((callback: (key: Key) => void) => {
|
mockedUseKeypress.mockImplementation(
|
||||||
handleGlobalKeypress = callback;
|
(callback: (key: Key) => boolean) => {
|
||||||
});
|
handleGlobalKeypress = callback;
|
||||||
|
},
|
||||||
|
);
|
||||||
vi.useFakeTimers();
|
vi.useFakeTimers();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -532,6 +532,14 @@ export const AppContainer = (props: AppContainerProps) => {
|
|||||||
shellModeActive,
|
shellModeActive,
|
||||||
getPreferredEditor,
|
getPreferredEditor,
|
||||||
});
|
});
|
||||||
|
const bufferRef = useRef(buffer);
|
||||||
|
useEffect(() => {
|
||||||
|
bufferRef.current = buffer;
|
||||||
|
}, [buffer]);
|
||||||
|
|
||||||
|
const stableSetText = useCallback((text: string) => {
|
||||||
|
bufferRef.current.setText(text);
|
||||||
|
}, []);
|
||||||
|
|
||||||
// Initialize input history from logger (past sessions)
|
// Initialize input history from logger (past sessions)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -826,7 +834,7 @@ Logging in with Google... Restarting Gemini CLI to continue.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setText: (text: string) => buffer.setText(text),
|
setText: stableSetText,
|
||||||
}),
|
}),
|
||||||
[
|
[
|
||||||
setAuthState,
|
setAuthState,
|
||||||
@@ -844,7 +852,7 @@ Logging in with Google... Restarting Gemini CLI to continue.
|
|||||||
openPermissionsDialog,
|
openPermissionsDialog,
|
||||||
addConfirmUpdateExtensionRequest,
|
addConfirmUpdateExtensionRequest,
|
||||||
toggleDebugProfiler,
|
toggleDebugProfiler,
|
||||||
buffer,
|
stableSetText,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -1405,7 +1413,7 @@ Logging in with Google... Restarting Gemini CLI to continue.
|
|||||||
if (ctrlCPressCount > 1) {
|
if (ctrlCPressCount > 1) {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||||
handleSlashCommand('/quit', undefined, undefined, false);
|
handleSlashCommand('/quit', undefined, undefined, false);
|
||||||
} else {
|
} else if (ctrlCPressCount > 0) {
|
||||||
ctrlCTimerRef.current = setTimeout(() => {
|
ctrlCTimerRef.current = setTimeout(() => {
|
||||||
setCtrlCPressCount(0);
|
setCtrlCPressCount(0);
|
||||||
ctrlCTimerRef.current = null;
|
ctrlCTimerRef.current = null;
|
||||||
@@ -1424,7 +1432,7 @@ Logging in with Google... Restarting Gemini CLI to continue.
|
|||||||
if (ctrlDPressCount > 1) {
|
if (ctrlDPressCount > 1) {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||||
handleSlashCommand('/quit', undefined, undefined, false);
|
handleSlashCommand('/quit', undefined, undefined, false);
|
||||||
} else {
|
} else if (ctrlDPressCount > 0) {
|
||||||
ctrlDTimerRef.current = setTimeout(() => {
|
ctrlDTimerRef.current = setTimeout(() => {
|
||||||
setCtrlDPressCount(0);
|
setCtrlDPressCount(0);
|
||||||
ctrlDTimerRef.current = null;
|
ctrlDTimerRef.current = null;
|
||||||
@@ -1465,7 +1473,7 @@ Logging in with Google... Restarting Gemini CLI to continue.
|
|||||||
});
|
});
|
||||||
|
|
||||||
const handleGlobalKeypress = useCallback(
|
const handleGlobalKeypress = useCallback(
|
||||||
(key: Key) => {
|
(key: Key): boolean => {
|
||||||
if (copyModeEnabled) {
|
if (copyModeEnabled) {
|
||||||
setCopyModeEnabled(false);
|
setCopyModeEnabled(false);
|
||||||
enableMouseEvents();
|
enableMouseEvents();
|
||||||
@@ -1492,9 +1500,6 @@ Logging in with Google... Restarting Gemini CLI to continue.
|
|||||||
setCtrlCPressCount((prev) => prev + 1);
|
setCtrlCPressCount((prev) => prev + 1);
|
||||||
return true;
|
return true;
|
||||||
} else if (keyMatchers[Command.EXIT](key)) {
|
} else if (keyMatchers[Command.EXIT](key)) {
|
||||||
if (buffer.text.length > 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
setCtrlDPressCount((prev) => prev + 1);
|
setCtrlDPressCount((prev) => prev + 1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1538,9 +1543,7 @@ Logging in with Google... Restarting Gemini CLI to continue.
|
|||||||
return true;
|
return true;
|
||||||
} else if (
|
} else if (
|
||||||
keyMatchers[Command.FOCUS_SHELL_INPUT](key) &&
|
keyMatchers[Command.FOCUS_SHELL_INPUT](key) &&
|
||||||
(activePtyId ||
|
(activePtyId || (isBackgroundShellVisible && backgroundShells.size > 0))
|
||||||
(isBackgroundShellVisible && backgroundShells.size > 0)) &&
|
|
||||||
buffer.text.length === 0
|
|
||||||
) {
|
) {
|
||||||
if (key.name === 'tab' && key.shift) {
|
if (key.name === 'tab' && key.shift) {
|
||||||
// Always change focus
|
// Always change focus
|
||||||
@@ -1625,7 +1628,6 @@ Logging in with Google... Restarting Gemini CLI to continue.
|
|||||||
config,
|
config,
|
||||||
ideContextState,
|
ideContextState,
|
||||||
setCtrlCPressCount,
|
setCtrlCPressCount,
|
||||||
buffer.text.length,
|
|
||||||
setCtrlDPressCount,
|
setCtrlDPressCount,
|
||||||
handleSlashCommand,
|
handleSlashCommand,
|
||||||
cancelOngoingRequest,
|
cancelOngoingRequest,
|
||||||
@@ -1647,7 +1649,7 @@ Logging in with Google... Restarting Gemini CLI to continue.
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
useKeypress(handleGlobalKeypress, { isActive: true, priority: true });
|
useKeypress(handleGlobalKeypress, { isActive: true });
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Respect hideWindowTitle settings
|
// Respect hideWindowTitle settings
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ import { StreamingState } from '../types.js';
|
|||||||
import { terminalCapabilityManager } from '../utils/terminalCapabilityManager.js';
|
import { terminalCapabilityManager } from '../utils/terminalCapabilityManager.js';
|
||||||
import type { UIState } from '../contexts/UIStateContext.js';
|
import type { UIState } from '../contexts/UIStateContext.js';
|
||||||
import { isLowColorDepth } from '../utils/terminalUtils.js';
|
import { isLowColorDepth } from '../utils/terminalUtils.js';
|
||||||
|
import { keyMatchers, Command } from '../keyMatchers.js';
|
||||||
|
import type { Key } from '../hooks/useKeypress.js';
|
||||||
|
|
||||||
vi.mock('../hooks/useShellHistory.js');
|
vi.mock('../hooks/useShellHistory.js');
|
||||||
vi.mock('../hooks/useCommandCompletion.js');
|
vi.mock('../hooks/useCommandCompletion.js');
|
||||||
@@ -169,7 +171,16 @@ describe('InputPrompt', () => {
|
|||||||
allVisualLines: [''],
|
allVisualLines: [''],
|
||||||
visualCursor: [0, 0],
|
visualCursor: [0, 0],
|
||||||
visualScrollRow: 0,
|
visualScrollRow: 0,
|
||||||
handleInput: vi.fn(),
|
handleInput: vi.fn((key: Key) => {
|
||||||
|
if (keyMatchers[Command.CLEAR_INPUT](key)) {
|
||||||
|
if (mockBuffer.text.length > 0) {
|
||||||
|
mockBuffer.setText('');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}),
|
||||||
move: vi.fn(),
|
move: vi.fn(),
|
||||||
moveToOffset: vi.fn((offset: number) => {
|
moveToOffset: vi.fn((offset: number) => {
|
||||||
mockBuffer.cursor = [0, offset];
|
mockBuffer.cursor = [0, offset];
|
||||||
@@ -499,6 +510,23 @@ describe('InputPrompt', () => {
|
|||||||
unmount();
|
unmount();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should clear the buffer and reset completion on Ctrl+C', async () => {
|
||||||
|
mockBuffer.text = 'some text';
|
||||||
|
const { stdin, unmount } = renderWithProviders(<InputPrompt {...props} />, {
|
||||||
|
uiActions,
|
||||||
|
});
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
stdin.write('\u0003'); // Ctrl+C
|
||||||
|
});
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(mockBuffer.setText).toHaveBeenCalledWith('');
|
||||||
|
expect(mockCommandCompletion.resetCompletionState).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
|
||||||
describe('clipboard image paste', () => {
|
describe('clipboard image paste', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.mocked(clipboardUtils.clipboardHasImage).mockResolvedValue(false);
|
vi.mocked(clipboardUtils.clipboardHasImage).mockResolvedValue(false);
|
||||||
|
|||||||
@@ -604,6 +604,12 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (keyMatchers[Command.CLEAR_SCREEN](key)) {
|
||||||
|
setBannerVisible(false);
|
||||||
|
onClearScreen();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (shellModeActive && keyMatchers[Command.REVERSE_SEARCH](key)) {
|
if (shellModeActive && keyMatchers[Command.REVERSE_SEARCH](key)) {
|
||||||
setReverseSearchActive(true);
|
setReverseSearchActive(true);
|
||||||
setTextBeforeReverseSearch(buffer.text);
|
setTextBeforeReverseSearch(buffer.text);
|
||||||
@@ -611,12 +617,6 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keyMatchers[Command.CLEAR_SCREEN](key)) {
|
|
||||||
setBannerVisible(false);
|
|
||||||
onClearScreen();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reverseSearchActive || commandSearchActive) {
|
if (reverseSearchActive || commandSearchActive) {
|
||||||
const isCommandSearch = commandSearchActive;
|
const isCommandSearch = commandSearchActive;
|
||||||
|
|
||||||
@@ -881,14 +881,6 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
|||||||
buffer.move('end');
|
buffer.move('end');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Ctrl+C (Clear input)
|
|
||||||
if (keyMatchers[Command.CLEAR_INPUT](key)) {
|
|
||||||
if (buffer.text.length > 0) {
|
|
||||||
buffer.setText('');
|
|
||||||
resetCompletionState();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Kill line commands
|
// Kill line commands
|
||||||
if (keyMatchers[Command.KILL_LINE_RIGHT](key)) {
|
if (keyMatchers[Command.KILL_LINE_RIGHT](key)) {
|
||||||
@@ -933,17 +925,23 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
|||||||
// Fall back to the text buffer's default input handling for all other keys
|
// Fall back to the text buffer's default input handling for all other keys
|
||||||
const handled = buffer.handleInput(key);
|
const handled = buffer.handleInput(key);
|
||||||
|
|
||||||
// Clear ghost text when user types regular characters (not navigation/control keys)
|
if (handled) {
|
||||||
if (
|
if (keyMatchers[Command.CLEAR_INPUT](key)) {
|
||||||
completion.promptCompletion.text &&
|
resetCompletionState();
|
||||||
key.sequence &&
|
}
|
||||||
key.sequence.length === 1 &&
|
|
||||||
!key.alt &&
|
// Clear ghost text when user types regular characters (not navigation/control keys)
|
||||||
!key.ctrl &&
|
if (
|
||||||
!key.cmd
|
completion.promptCompletion.text &&
|
||||||
) {
|
key.sequence &&
|
||||||
completion.promptCompletion.clear();
|
key.sequence.length === 1 &&
|
||||||
setExpandedSuggestionIndex(-1);
|
!key.alt &&
|
||||||
|
!key.ctrl &&
|
||||||
|
!key.cmd
|
||||||
|
) {
|
||||||
|
completion.promptCompletion.clear();
|
||||||
|
setExpandedSuggestionIndex(-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return handled;
|
return handled;
|
||||||
},
|
},
|
||||||
@@ -982,7 +980,10 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
useKeypress(handleInput, { isActive: !isEmbeddedShellFocused });
|
useKeypress(handleInput, {
|
||||||
|
isActive: !isEmbeddedShellFocused,
|
||||||
|
priority: true,
|
||||||
|
});
|
||||||
|
|
||||||
const linesToRender = buffer.viewportVisualLines;
|
const linesToRender = buffer.viewportVisualLines;
|
||||||
const [cursorVisualRowAbsolute, cursorVisualColAbsolute] =
|
const [cursorVisualRowAbsolute, cursorVisualColAbsolute] =
|
||||||
|
|||||||
@@ -1515,6 +1515,50 @@ describe('useTextBuffer', () => {
|
|||||||
expect(getBufferState(result).text).toBe('');
|
expect(getBufferState(result).text).toBe('');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle CLEAR_INPUT (Ctrl+C)', () => {
|
||||||
|
const { result } = renderHook(() =>
|
||||||
|
useTextBuffer({
|
||||||
|
initialText: 'hello',
|
||||||
|
viewport,
|
||||||
|
isValidPath: () => false,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(getBufferState(result).text).toBe('hello');
|
||||||
|
let handled = false;
|
||||||
|
act(() => {
|
||||||
|
handled = result.current.handleInput({
|
||||||
|
name: 'c',
|
||||||
|
shift: false,
|
||||||
|
alt: false,
|
||||||
|
ctrl: true,
|
||||||
|
cmd: false,
|
||||||
|
insertable: false,
|
||||||
|
sequence: '\u0003',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
expect(handled).toBe(true);
|
||||||
|
expect(getBufferState(result).text).toBe('');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should NOT handle CLEAR_INPUT if buffer is empty', () => {
|
||||||
|
const { result } = renderHook(() =>
|
||||||
|
useTextBuffer({ viewport, isValidPath: () => false }),
|
||||||
|
);
|
||||||
|
let handled = true;
|
||||||
|
act(() => {
|
||||||
|
handled = result.current.handleInput({
|
||||||
|
name: 'c',
|
||||||
|
shift: false,
|
||||||
|
alt: false,
|
||||||
|
ctrl: true,
|
||||||
|
cmd: false,
|
||||||
|
insertable: false,
|
||||||
|
sequence: '\u0003',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
expect(handled).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
it('should handle "Backspace" key', () => {
|
it('should handle "Backspace" key', () => {
|
||||||
const { result } = renderHook(() =>
|
const { result } = renderHook(() =>
|
||||||
useTextBuffer({
|
useTextBuffer({
|
||||||
|
|||||||
@@ -2930,6 +2930,13 @@ export function useTextBuffer({
|
|||||||
move('end');
|
move('end');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (keyMatchers[Command.CLEAR_INPUT](key)) {
|
||||||
|
if (text.length > 0) {
|
||||||
|
setText('');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (keyMatchers[Command.DELETE_WORD_BACKWARD](key)) {
|
if (keyMatchers[Command.DELETE_WORD_BACKWARD](key)) {
|
||||||
deleteWordLeft();
|
deleteWordLeft();
|
||||||
return true;
|
return true;
|
||||||
@@ -2943,6 +2950,13 @@ export function useTextBuffer({
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (keyMatchers[Command.DELETE_CHAR_RIGHT](key)) {
|
if (keyMatchers[Command.DELETE_CHAR_RIGHT](key)) {
|
||||||
|
const lastLineIdx = lines.length - 1;
|
||||||
|
if (
|
||||||
|
cursorRow === lastLineIdx &&
|
||||||
|
cursorCol === cpLen(lines[lastLineIdx] ?? '')
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
del();
|
del();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -2974,6 +2988,8 @@ export function useTextBuffer({
|
|||||||
cursorCol,
|
cursorCol,
|
||||||
lines,
|
lines,
|
||||||
singleLine,
|
singleLine,
|
||||||
|
setText,
|
||||||
|
text,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user