Migrate keybindings (#16460)

This commit is contained in:
Tommaso Sciortino
2026-01-12 16:28:10 -08:00
committed by GitHub
parent 548641c952
commit 8d3e93cdb0
6 changed files with 165 additions and 63 deletions

View File

@@ -144,7 +144,7 @@ export const Help: React.FC<Help> = ({ commands }) => (
</Text>
<Text color={theme.text.primary}>
<Text bold color={theme.text.accent}>
{process.platform === 'darwin' ? 'Ctrl+X / Meta+Enter' : 'Ctrl+X'}
Ctrl+X
</Text>{' '}
- Open input in external editor
</Text>

View File

@@ -25,6 +25,7 @@ import {
} from '../../utils/textUtils.js';
import { parsePastedPaths } from '../../utils/clipboardUtils.js';
import type { Key } from '../../contexts/KeypressContext.js';
import { keyMatchers, Command } from '../../keyMatchers.js';
import type { VimAction } from './vim-buffer-actions.js';
import { handleVimAction } from './vim-buffer-actions.js';
@@ -2220,38 +2221,20 @@ export function useTextBuffer({
input === '\\r') // VSCode terminal represents shift + enter this way
)
newline();
else if (key.name === 'left' && !key.meta && !key.ctrl) move('left');
else if (key.ctrl && key.name === 'b') move('left');
else if (key.name === 'right' && !key.meta && !key.ctrl) move('right');
else if (key.ctrl && key.name === 'f') move('right');
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 ((key.ctrl || key.meta) && key.name === 'left') move('wordLeft');
else if (key.meta && key.name === 'b') move('wordLeft');
else if ((key.ctrl || key.meta) && key.name === 'right')
move('wordRight');
else if (key.meta && key.name === 'f') move('wordRight');
else if (key.name === 'home') move('home');
else if (key.ctrl && key.name === 'a') move('home');
else if (key.name === 'end') move('end');
else if (key.ctrl && key.name === 'e') move('end');
else if (key.ctrl && key.name === 'w') deleteWordLeft();
else if (
(key.meta || key.ctrl) &&
(key.name === 'backspace' || input === '\x7f')
)
deleteWordLeft();
else if ((key.meta || key.ctrl) && key.name === 'delete')
deleteWordRight();
else if (
key.name === 'backspace' ||
input === '\x7f' ||
(key.ctrl && key.name === 'h')
)
backspace();
else if (key.name === 'delete' || (key.ctrl && key.name === 'd')) del();
else if (key.ctrl && !key.shift && key.name === 'z') undo();
else if (key.ctrl && key.shift && key.name === 'z') redo();
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');
else if (keyMatchers[Command.END](key)) move('end');
else if (keyMatchers[Command.DELETE_WORD_BACKWARD](key)) deleteWordLeft();
else if (keyMatchers[Command.DELETE_WORD_FORWARD](key)) deleteWordRight();
else if (keyMatchers[Command.DELETE_CHAR_LEFT](key)) backspace();
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: key.paste });
}

View File

@@ -112,7 +112,7 @@ export const INFORMATIVE_TIPS = [
'Paste from your clipboard with Ctrl+V...',
'Undo text edits in the input with Ctrl+Z...',
'Redo undone text edits with Ctrl+Shift+Z...',
'Open the current prompt in an external editor with Ctrl+X or Meta+Enter...',
'Open the current prompt in an external editor with Ctrl+X...',
'In menus, move up/down with k/j or the arrow keys...',
'In menus, select an item by typing its number...',
"If you're using an IDE, see the context with Ctrl+G...",

View File

@@ -39,7 +39,7 @@ describe('keyMatchers', () => {
// Cursor movement
{
command: Command.HOME,
positive: [createKey('a', { ctrl: true })],
positive: [createKey('a', { ctrl: true }), createKey('home')],
negative: [
createKey('a'),
createKey('a', { shift: true }),
@@ -48,13 +48,41 @@ describe('keyMatchers', () => {
},
{
command: Command.END,
positive: [createKey('e', { ctrl: true })],
positive: [createKey('e', { ctrl: true }), createKey('end')],
negative: [
createKey('e'),
createKey('e', { shift: true }),
createKey('a', { ctrl: true }),
],
},
{
command: Command.MOVE_LEFT,
positive: [createKey('left'), createKey('b', { ctrl: true })],
negative: [createKey('left', { ctrl: true }), createKey('b')],
},
{
command: Command.MOVE_RIGHT,
positive: [createKey('right'), createKey('f', { ctrl: true })],
negative: [createKey('right', { ctrl: true }), createKey('f')],
},
{
command: Command.MOVE_WORD_LEFT,
positive: [
createKey('left', { ctrl: true }),
createKey('left', { meta: true }),
createKey('b', { meta: true }),
],
negative: [createKey('left'), createKey('b', { ctrl: true })],
},
{
command: Command.MOVE_WORD_RIGHT,
positive: [
createKey('right', { ctrl: true }),
createKey('right', { meta: true }),
createKey('f', { meta: true }),
],
negative: [createKey('right'), createKey('f', { ctrl: true })],
},
// Text deletion
{
@@ -72,14 +100,49 @@ describe('keyMatchers', () => {
positive: [createKey('c', { ctrl: true })],
negative: [createKey('c'), createKey('k', { ctrl: true })],
},
{
command: Command.DELETE_CHAR_LEFT,
positive: [
createKey('backspace'),
{ ...createKey('\x7f'), sequence: '\x7f' },
createKey('h', { ctrl: true }),
],
negative: [createKey('h'), createKey('x', { ctrl: true })],
},
{
command: Command.DELETE_CHAR_RIGHT,
positive: [createKey('delete'), createKey('d', { ctrl: true })],
negative: [createKey('d'), createKey('x', { ctrl: true })],
},
{
command: Command.DELETE_WORD_BACKWARD,
positive: [
createKey('backspace', { ctrl: true }),
createKey('backspace', { meta: true }),
{ ...createKey('\x7f', { ctrl: true }), sequence: '\x7f' },
{ ...createKey('\x7f', { meta: true }), sequence: '\x7f' },
createKey('w', { ctrl: true }),
],
negative: [createKey('backspace'), createKey('delete', { ctrl: true })],
},
{
command: Command.DELETE_WORD_FORWARD,
positive: [
createKey('delete', { ctrl: true }),
createKey('delete', { meta: true }),
],
negative: [createKey('delete'), createKey('backspace', { ctrl: true })],
},
{
command: Command.UNDO,
positive: [createKey('z', { ctrl: true, shift: false })],
negative: [createKey('z'), createKey('z', { ctrl: true, shift: true })],
},
{
command: Command.REDO,
positive: [createKey('z', { ctrl: true, shift: true })],
negative: [createKey('z'), createKey('z', { ctrl: true, shift: false })],
},
// Screen control
{