mirror of
https://github.com/makew0rld/amfora.git
synced 2025-02-02 15:07:34 -05:00
Add option for custom keybinds for navigation (#222)
Co-authored-by: makeworld <25111343+makeworld-the-better-one@users.noreply.github.com>
This commit is contained in:
parent
29996d2051
commit
9337f63ed2
@ -210,6 +210,10 @@ func Init() error {
|
||||
viper.SetDefault("keybindings.bind_sub", "Ctrl-A")
|
||||
viper.SetDefault("keybindings.bind_add_sub", "Ctrl-X")
|
||||
viper.SetDefault("keybindings.bind_save", "Ctrl-S")
|
||||
viper.SetDefault("keybindings.bind_moveup", "k")
|
||||
viper.SetDefault("keybindings.bind_movedown", "j")
|
||||
viper.SetDefault("keybindings.bind_moveleft", "h")
|
||||
viper.SetDefault("keybindings.bind_moveright", "l")
|
||||
viper.SetDefault("keybindings.bind_pgup", []string{"PgUp", "u"})
|
||||
viper.SetDefault("keybindings.bind_pgdn", []string{"PgDn", "d"})
|
||||
viper.SetDefault("keybindings.bind_bottom", "Space")
|
||||
|
@ -148,6 +148,10 @@ scrollbar = "auto"
|
||||
# bind_reload
|
||||
# bind_back
|
||||
# bind_forward
|
||||
# bind_moveup
|
||||
# bind_movedown
|
||||
# bind_moveleft
|
||||
# bind_moveright
|
||||
# bind_pgup
|
||||
# bind_pgdn
|
||||
# bind_new_tab
|
||||
|
@ -3,6 +3,7 @@ package config
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"code.rocketnine.space/tslocum/cview"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
@ -42,6 +43,10 @@ const (
|
||||
CmdReload
|
||||
CmdBack
|
||||
CmdForward
|
||||
CmdMoveUp
|
||||
CmdMoveDown
|
||||
CmdMoveLeft
|
||||
CmdMoveRight
|
||||
CmdPgup
|
||||
CmdPgdn
|
||||
CmdNewTab
|
||||
@ -168,6 +173,10 @@ func KeyInit() {
|
||||
CmdReload: "keybindings.bind_reload",
|
||||
CmdBack: "keybindings.bind_back",
|
||||
CmdForward: "keybindings.bind_forward",
|
||||
CmdMoveUp: "keybindings.bind_moveup",
|
||||
CmdMoveDown: "keybindings.bind_movedown",
|
||||
CmdMoveLeft: "keybindings.bind_moveleft",
|
||||
CmdMoveRight: "keybindings.bind_moveright",
|
||||
CmdPgup: "keybindings.bind_pgup",
|
||||
CmdPgdn: "keybindings.bind_pgdn",
|
||||
CmdNewTab: "keybindings.bind_new_tab",
|
||||
@ -203,6 +212,11 @@ func KeyInit() {
|
||||
tcellKeys[kname] = k
|
||||
}
|
||||
|
||||
cview.Keys.MoveUp2 = viper.GetStringSlice(configBindings[CmdMoveUp])
|
||||
cview.Keys.MoveDown2 = viper.GetStringSlice(configBindings[CmdMoveDown])
|
||||
cview.Keys.MoveLeft2 = viper.GetStringSlice(configBindings[CmdMoveLeft])
|
||||
cview.Keys.MoveRight2 = viper.GetStringSlice(configBindings[CmdMoveRight])
|
||||
|
||||
for c, allb := range configBindings {
|
||||
for _, b := range viper.GetStringSlice(allb) {
|
||||
parseBinding(c, b)
|
||||
|
@ -145,6 +145,10 @@ scrollbar = "auto"
|
||||
# bind_reload
|
||||
# bind_back
|
||||
# bind_forward
|
||||
# bind_moveup
|
||||
# bind_movedown
|
||||
# bind_moveleft
|
||||
# bind_moveright
|
||||
# bind_pgup
|
||||
# bind_pgdn
|
||||
# bind_new_tab
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
var helpCells = strings.TrimSpace(
|
||||
"?\tBring up this help. You can scroll!\n" +
|
||||
"Esc\tLeave the help\n" +
|
||||
"Arrow keys, h/j/k/l\tScroll and move a page.\n" +
|
||||
"Arrow keys, %s(left)/%s(down)/%s(up)/%s(right)\tScroll and move a page.\n" +
|
||||
"%s\tGo up a page in document\n" +
|
||||
"%s\tGo down a page in document\n" +
|
||||
"g\tGo to top of document\n" +
|
||||
@ -80,6 +80,10 @@ func helpInit() {
|
||||
strings.Split(config.GetKeyBinding(config.CmdLink0), ",")[0])
|
||||
|
||||
helpCells = fmt.Sprintf(helpCells,
|
||||
config.GetKeyBinding(config.CmdMoveLeft),
|
||||
config.GetKeyBinding(config.CmdMoveDown),
|
||||
config.GetKeyBinding(config.CmdMoveUp),
|
||||
config.GetKeyBinding(config.CmdMoveRight),
|
||||
config.GetKeyBinding(config.CmdPgup),
|
||||
config.GetKeyBinding(config.CmdPgdn),
|
||||
config.GetKeyBinding(config.CmdBack),
|
||||
|
@ -122,13 +122,12 @@ func makeNewTab() *tab {
|
||||
}
|
||||
})
|
||||
t.view.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
||||
// Capture left/right scrolling and change the left margin size accordingly, see #197
|
||||
// Up/down scrolling is saved in this func to keep them in sync, but the keys
|
||||
// are passed and no extra behaviour happens.
|
||||
// Capture scrolling and change the left margin size accordingly, see #197
|
||||
// This was also touched by #222
|
||||
|
||||
key := event.Key()
|
||||
mod := event.Modifiers()
|
||||
ru := event.Rune()
|
||||
cmd := config.TranslateKeyEvent(event)
|
||||
|
||||
height, width := t.view.GetBufferSize()
|
||||
_, _, boxW, boxH := t.view.GetInnerRect()
|
||||
@ -140,8 +139,7 @@ func makeNewTab() *tab {
|
||||
boxW--
|
||||
}
|
||||
|
||||
if (key == tcell.KeyRight && mod == tcell.ModNone) ||
|
||||
(key == tcell.KeyRune && mod == tcell.ModNone && ru == 'l') {
|
||||
if cmd == config.CmdMoveRight || (key == tcell.KeyRight && mod == tcell.ModNone) {
|
||||
// Scrolling to the right
|
||||
|
||||
if t.page.Column >= leftMargin() {
|
||||
@ -158,23 +156,20 @@ func makeNewTab() *tab {
|
||||
}
|
||||
}
|
||||
t.page.Column++
|
||||
} else if (key == tcell.KeyLeft && mod == tcell.ModNone) ||
|
||||
(key == tcell.KeyRune && mod == tcell.ModNone && ru == 'h') {
|
||||
} else if cmd == config.CmdMoveLeft || (key == tcell.KeyLeft && mod == tcell.ModNone) {
|
||||
// Scrolling to the left
|
||||
if t.page.Column == 0 {
|
||||
// Can't scroll to the left anymore
|
||||
return nil
|
||||
}
|
||||
t.page.Column--
|
||||
} else if (key == tcell.KeyUp && mod == tcell.ModNone) ||
|
||||
(key == tcell.KeyRune && mod == tcell.ModNone && ru == 'k') {
|
||||
} else if cmd == config.CmdMoveUp || (key == tcell.KeyUp && mod == tcell.ModNone) {
|
||||
// Scrolling up
|
||||
if t.page.Row > 0 {
|
||||
t.page.Row--
|
||||
}
|
||||
return event
|
||||
} else if (key == tcell.KeyDown && mod == tcell.ModNone) ||
|
||||
(key == tcell.KeyRune && mod == tcell.ModNone && ru == 'j') {
|
||||
} else if cmd == config.CmdMoveDown || (key == tcell.KeyDown && mod == tcell.ModNone) {
|
||||
// Scrolling down
|
||||
if t.page.Row < height {
|
||||
t.page.Row++
|
||||
|
Loading…
x
Reference in New Issue
Block a user