cleanup: Improve keybindings (#16672)

This commit is contained in:
Tommaso Sciortino
2026-01-14 16:30:07 -08:00
committed by GitHub
parent e58fca68ce
commit 42c26d1e1b
5 changed files with 17 additions and 23 deletions

View File

@@ -19,6 +19,8 @@ available combinations.
| ------------------------------------------- | ------------------------------------------------------------ |
| Move the cursor to the start of the line. | `Ctrl + A`<br />`Home` |
| Move the cursor to the end of the line. | `Ctrl + E`<br />`End` |
| Move the cursor up one line. | `Up Arrow (no Ctrl, no Cmd)` |
| Move the cursor down one line. | `Down Arrow (no Ctrl, no Cmd)` |
| Move the cursor one character to the left. | `Left Arrow (no Ctrl, no Cmd)`<br />`Ctrl + B` |
| Move the cursor one character to the right. | `Right Arrow (no Ctrl, no Cmd)`<br />`Ctrl + F` |
| Move the cursor one word to the left. | `Ctrl + Left Arrow`<br />`Cmd + Left Arrow`<br />`Cmd + B` |

View File

@@ -66,6 +66,8 @@ export enum Command {
TOGGLE_AUTO_EDIT = 'toggleAutoEdit',
UNDO = 'undo',
REDO = 'redo',
MOVE_UP = 'moveUp',
MOVE_DOWN = 'moveDown',
MOVE_LEFT = 'moveLeft',
MOVE_RIGHT = 'moveRight',
MOVE_WORD_LEFT = 'moveWordLeft',
@@ -141,6 +143,8 @@ export const defaultKeyBindings: KeyBindingConfig = {
{ key: 'right', ctrl: false, command: false },
{ key: 'f', ctrl: true },
],
[Command.MOVE_UP]: [{ key: 'up', ctrl: false, command: false }],
[Command.MOVE_DOWN]: [{ key: 'down', ctrl: false, command: false }],
[Command.MOVE_WORD_LEFT]: [
{ key: 'left', ctrl: true },
{ key: 'left', command: true },
@@ -269,6 +273,8 @@ export const commandCategories: readonly CommandCategory[] = [
commands: [
Command.HOME,
Command.END,
Command.MOVE_UP,
Command.MOVE_DOWN,
Command.MOVE_LEFT,
Command.MOVE_RIGHT,
Command.MOVE_WORD_LEFT,
@@ -372,6 +378,8 @@ export const commandDescriptions: Readonly<Record<Command, string>> = {
[Command.END]: 'Move the cursor to the end of the line.',
[Command.MOVE_LEFT]: 'Move the cursor one character to the left.',
[Command.MOVE_RIGHT]: 'Move the cursor one character to the right.',
[Command.MOVE_UP]: 'Move the cursor up one line.',
[Command.MOVE_DOWN]: 'Move the cursor down one line.',
[Command.MOVE_WORD_LEFT]: 'Move the cursor one word to the left.',
[Command.MOVE_WORD_RIGHT]: 'Move the cursor one word to the right.',
[Command.KILL_LINE_RIGHT]: 'Delete from the cursor to the end of the line.',

View File

@@ -2223,25 +2223,12 @@ export function useTextBuffer({
(key: Key): void => {
const { sequence: input } = key;
if (key.name === 'paste') {
// Do not do any other processing on pastes so ensure we handle them
// before all other cases.
insert(input, { paste: true });
return;
}
if (
!singleLine &&
(key.name === 'return' ||
input === '\r' ||
input === '\n' ||
input === '\\r') // VSCode terminal represents shift + enter this way
)
newline();
if (key.name === 'paste') insert(input, { paste: true });
else if (keyMatchers[Command.RETURN](key)) newline();
else if (keyMatchers[Command.MOVE_LEFT](key)) move('left');
else if (keyMatchers[Command.MOVE_RIGHT](key)) move('right');
else if (key.name === 'up') move('up');
else if (key.name === 'down') move('down');
else if (keyMatchers[Command.MOVE_UP](key)) move('up');
else if (keyMatchers[Command.MOVE_DOWN](key)) move('down');
else if (keyMatchers[Command.MOVE_WORD_LEFT](key)) move('wordLeft');
else if (keyMatchers[Command.MOVE_WORD_RIGHT](key)) move('wordRight');
else if (keyMatchers[Command.HOME](key)) move('home');
@@ -2252,9 +2239,7 @@ export function useTextBuffer({
else if (keyMatchers[Command.DELETE_CHAR_RIGHT](key)) del();
else if (keyMatchers[Command.UNDO](key)) undo();
else if (keyMatchers[Command.REDO](key)) redo();
else if (key.insertable) {
insert(input, { paste: false });
}
else if (key.insertable) insert(input, { paste: false });
},
[
newline,
@@ -2266,7 +2251,6 @@ export function useTextBuffer({
insert,
undo,
redo,
singleLine,
],
);

View File

@@ -179,7 +179,7 @@ describe('KeypressContext', () => {
expect(keyHandler).toHaveBeenLastCalledWith(
expect.objectContaining({
name: '',
name: 'return',
sequence: '\r',
insertable: true,
}),

View File

@@ -157,7 +157,7 @@ function bufferFastReturn(keypressHandler: KeypressHandler): KeypressHandler {
if (key.name === 'return' && now - lastKeyTime <= FAST_RETURN_TIMEOUT) {
keypressHandler({
...key,
name: '',
name: 'return',
sequence: '\r',
insertable: true,
});