Skip to content

Commit

Permalink
feat: handle more special keys
Browse files Browse the repository at this point in the history
  • Loading branch information
bomgar committed Sep 29, 2024
1 parent 3d00431 commit 429a0ad
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
4 changes: 4 additions & 0 deletions components/main.templ
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ templ Main(nvimResult nvimwrapper.NvimResult) {
if(event.keyCode >= 112 && event.keyCode <= 123) {
return
}
// Modifier keys.
if (event.keyCode === 16 || event.keyCode === 17 || event.keyCode === 18 || event.keyCode === 91) {
return;
}

event.preventDefault()
// Send the keypress information to the server
Expand Down
37 changes: 35 additions & 2 deletions nvimwrapper/nvim.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,41 @@ func (w *NvimWrapper) Input(input string) error {
}

func (w *NvimWrapper) SendKey(keyPress key.KeyPress) {
// TODO actually consider modifiers. "shift" is also a key
err := w.Input(keyPress.Key)
input := ""
// TODO handle modifiers
switch keyPress.Key {
case "Escape":
input = "<Esc>"
case "Enter":
input = "<CR>"
case "Tab":
input = "<Tab>"
case "Backspace":
input = "<BS>"
case "Delete":
input = "<Del>"
case "ArrowUp":
input = "<Up>"
case "ArrowDown":
input = "<Down>"
case "ArrowLeft":
input = "<Left>"
case "ArrowRight":
input = "<Right>"
case "Home":
input = "<Home>"
case "End":
input = "<End>"
case "PageUp":
input = "<PageUp>"
case "PageDown":
input = "<PageDown>"
case "Insert":
input = "<Insert>"
default:
input = keyPress.Key
}
err := w.Input(input)

if err != nil {
slog.Error("Failed to process keypress.", "press", keyPress)
Expand Down

0 comments on commit 429a0ad

Please sign in to comment.