Skip to content

Commit 213aea8

Browse files
authored
Add support for neovim cursor motion (#56)
2 parents b5e78cb + 6690e74 commit 213aea8

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

.changeset/tough-drinks-cheat.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@clack/core': patch
3+
---
4+
5+
Add support for neovim cursor motion (`hjkl`)
6+
7+
Thanks [@esau-morais](https://github.com/esau-morais) for the assist!

packages/core/src/prompts/prompt.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function setRawMode(input: Readable, value: boolean) {
2929
if ((input as typeof stdin).isTTY) (input as typeof stdin).setRawMode(value);
3030
}
3131

32+
const aliases = new Map([['k', 'up'], ['j', 'down'], ['h', 'left'], ['l', 'right']]);
3233
const keys = new Set(['up', 'down', 'left', 'right', 'space', 'enter']);
3334

3435
export interface PromptOptions<Self extends Prompt> {
@@ -147,7 +148,9 @@ export default class Prompt {
147148
if (this.state === 'error') {
148149
this.state = 'active';
149150
}
150-
151+
if (key?.name && !this._track && aliases.has(key.name)) {
152+
this.emit('cursor', aliases.get(key.name));
153+
}
151154
if (key?.name && keys.has(key.name)) {
152155
this.emit('cursor', key.name);
153156
}

0 commit comments

Comments
 (0)