Skip to content

Commit 0525ad3

Browse files
Adding lockbindings option for disallowing lua to modify bindings at all
1 parent 84a7482 commit 0525ad3

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

internal/action/bindings.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,11 @@ func eventsEqual(e1 Event, e2 Event) bool {
262262
}
263263

264264
// TryBindKeyPlug tries to bind key for the plugin without writing to bindings.json.
265+
// This operation can be rejected by lockbindings to prevent unexpected actions by the user.
265266
func TryBindKeyPlug(k, v string, overwrite bool) (bool, error) {
267+
if l, ok := config.GlobalSettings["lockbindings"]; ok && l.(bool) {
268+
return false, errors.New("bindings is locked by the user")
269+
}
266270
return TryBindKey(k, v, overwrite, false)
267271
}
268272

internal/config/settings.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ var DefaultGlobalOnlySettings = map[string]any{
118118
"helpsplit": "hsplit",
119119
"infobar": true,
120120
"keymenu": false,
121+
"lockbindings": false,
121122
"mouse": true,
122123
"multiopen": "tab",
123124
"parsecursor": false,

runtime/help/options.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@ Here are the available options:
231231

232232
default value: `false`
233233

234+
* `lockbindings`: prevent plugins and lua scripts from binding any keys.
235+
Any custom actions must be binded manually either via commands like `bind`
236+
or by modifying the `bindings.json` file.
237+
238+
default value: `false`
239+
234240
* `matchbrace`: show matching braces for '()', '{}', '[]' when the cursor
235241
is on a brace character or (if `matchbraceleft` is enabled) next to it.
236242

runtime/help/plugins.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ The packages and their contents are listed below (in Go type signatures):
178178
bind the key `k` to the string `v`. If `overwrite` is true, this will
179179
overwrite any existing binding to key `k`.
180180
Returns true if the binding was made, and a possible error.
181+
This operation can be rejected by `lockbindings` to prevent undesired
182+
actions by the user.
181183

182184
- `Reload()`: reload configuration files.
183185

0 commit comments

Comments
 (0)