Skip to content

Support configurable keybindings #4

Description

@VisenDev

As far as I can tell, all keybindings are hardcoded in the widget_*.zig files. Eg,

        if (std.mem.eql(u8, command, ":def")) {
            if (app.lsp) |lsp| {
                lsp.definition(&(app.currentWidgetTextEdit().editor.buffer), app.currentWidgetTextEdit().cursor.pos) catch |err| {
                    std.log.err("WidgetCommand: can't exec ':def': {}", .{err});
                    return;
                };
            } else {
                app.showMessageBoxError("LSP not initialized.", .{});
            }
            return;
        }

It would be useful if this interface was changed to something more like

if(std.mem.eql(u8, command, keybindings.get(.command, "define")){}

or

if(keybindings.activated(.command, "define")){}

The keybindings could then have default bindings, but also support parsing new bindings from a configuration file.
For example, something like

[keybindings.define]
keys = ":def"
modifiers = ""
widget = "command"

Benefits to this approach

  • Editor key input becomes abstracted away from the functionality that handles that input. This means that the implementation of how input works can be changed and modified in the future without breaking the editor controls which implement that input.|
  • New keybindings can easily be created
  • A list of all active keybindings can easily be shown to the user

More concrete example of this sort of approach from one of my projects

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions