mirror of
https://github.com/elk-zone/elk.git
synced 2024-11-21 17:05:22 +03:00
feat(command): support for emacs shortcuts (#416)
This commit is contained in:
parent
762a936793
commit
57017a23f4
1 changed files with 16 additions and 10 deletions
|
@ -53,24 +53,32 @@ const intoView = (index: number) => {
|
|||
if (el)
|
||||
el.scrollIntoView({ block: 'nearest' })
|
||||
}
|
||||
|
||||
function setActive(index: number) {
|
||||
const len = result.length
|
||||
active = (index + len) % len
|
||||
intoView(active)
|
||||
}
|
||||
|
||||
const onKeyDown = (e: KeyboardEvent) => {
|
||||
switch (e.key) {
|
||||
case 'p':
|
||||
case 'ArrowUp': {
|
||||
if (e.key === 'p' && !e.ctrlKey)
|
||||
break
|
||||
e.preventDefault()
|
||||
|
||||
active = Math.max(0, active - 1)
|
||||
|
||||
intoView(active)
|
||||
setActive(active - 1)
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
case 'n':
|
||||
case 'ArrowDown': {
|
||||
if (e.key === 'n' && !e.ctrlKey)
|
||||
break
|
||||
e.preventDefault()
|
||||
|
||||
active = Math.min(result.length - 1, active + 1)
|
||||
|
||||
intoView(active)
|
||||
setActive(active + 1)
|
||||
|
||||
break
|
||||
}
|
||||
|
@ -88,9 +96,7 @@ const onKeyDown = (e: KeyboardEvent) => {
|
|||
case 'End': {
|
||||
e.preventDefault()
|
||||
|
||||
active = result.length - 1
|
||||
|
||||
intoView(active)
|
||||
setActive(result.length - 1)
|
||||
|
||||
break
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue