mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-29 22:27:13 +09:00
Changing behavior for TryBindKey() for lua to not write to bindings.json
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user