Changing behavior for TryBindKey() for lua to not write to bindings.json

This commit is contained in:
Neko Box Coder
2025-09-06 20:25:47 +01:00
parent 0b9c7c0c4a
commit b39b5b5916
4 changed files with 19 additions and 10 deletions

View File

@@ -261,9 +261,14 @@ func eventsEqual(e1 Event, e2 Event) bool {
return e1 == e2
}
// TryBindKeyPlug tries to bind a key for the plugin without writing to bindings.json.
func TryBindKeyPlug(k, v string, overwrite bool) (bool, error) {
return TryBindKey(k, v, overwrite, false)
}
// TryBindKey tries to bind a key by writing to config.ConfigDir/bindings.json
// Returns true if the keybinding already existed and a possible error
func TryBindKey(k, v string, overwrite bool) (bool, error) {
// Returns true if the keybinding already existed or is binded successfully and a possible error
func TryBindKey(k, v string, overwrite bool, writeToFile bool) (bool, error) {
var e error
var parsed map[string]any
@@ -310,7 +315,12 @@ func TryBindKey(k, v string, overwrite bool) (bool, error) {
txt, _ := json.MarshalIndent(parsed, "", " ")
txt = append(txt, '\n')
return true, writeFile(filename, txt)
if writeToFile {
return true, writeFile(filename, txt)
} else {
return true, nil
}
}
return false, e
}

View File

@@ -844,7 +844,7 @@ func (h *BufPane) BindCmd(args []string) {
return
}
_, err := TryBindKey(parseKeyArg(args[0]), args[1], true)
_, err := TryBindKey(parseKeyArg(args[0]), args[1], true, true)
if err != nil {
if errors.Is(err, util.ErrOverwrite) {
screen.TermMessage(err)