Adding lockbindings option for disallowing lua to modify bindings at all

This commit is contained in:
Neko Box Coder
2025-09-06 20:28:16 +01:00
parent 7a250b7df4
commit 4f1d2bb543
4 changed files with 13 additions and 0 deletions

View File

@@ -262,7 +262,11 @@ func eventsEqual(e1 Event, e2 Event) bool {
}
// TryBindKeyPlug tries to bind a key for the plugin without writing to bindings.json.
// This operation can be rejected by lockbindings to prevent unexpected actions by the user.
func TryBindKeyPlug(k, v string, overwrite bool) (bool, error) {
if l, ok := config.GlobalSettings["lockbindings"]; ok && l.(bool) {
return false, errors.New("bindings is locked by the user")
}
return TryBindKey(k, v, overwrite, false)
}

View File

@@ -118,6 +118,7 @@ var DefaultGlobalOnlySettings = map[string]any{
"helpsplit": "hsplit",
"infobar": true,
"keymenu": false,
"lockbindings": false,
"mouse": true,
"multiopen": "tab",
"parsecursor": false,

View File

@@ -231,6 +231,12 @@ Here are the available options:
default value: `false`
* `lockbindings`: prevent plugins and lua scripts from binding any keys.
Any custom actions must be binded manually either via commands like `bind`
or by modifying the `bindings.json` file.
default value: `false`
* `matchbrace`: show matching braces for '()', '{}', '[]' when the cursor
is on a brace character or (if `matchbraceleft` is enabled) next to it.

View File

@@ -178,6 +178,8 @@ The packages and their contents are listed below (in Go type signatures):
bind the key `k` to the string `v`. If `overwrite` is true, this will
overwrite any existing binding to key `k`.
Returns true if the binding was made, and a possible error.
This operation can be rejected by `lockbindings` to prevent undesired
actions by the user.
- `Reload()`: reload configuration files.