Class dkb.modal

Class to bind keys within modals.

Uses hs.hotkey.modal behind the scenes. Use it in combination with dkb.keybindings to easily define modals and bind keys to them. If you want to filter keybindings based on the focuse window, see dkb.filter. Nesting modals is possible, the one activated on top (later) will have precedence over the previous one and so on. Nesting can get out of hand quickly so be sure you understand how it works if you want to get creative with it.

This module returns a func used to instantiate modals. See usage in the function below.

See also:

Functions

dkb.modal (init_function) Function returned by this module when imported.

Methods

dkb.modal:enter (action) Enter modal.
dkb.modal:exit (action) Exit modal.
dkb.modal:bind (func, arg) Execute a function with bindings enabled.


Functions

Methods
dkb.modal (init_function)
Function returned by this module when imported. Used to create Modal instances.

Parameters:

  • init_function func[opt] The provied function will be executed on modal creation. Keybindings inside the function will map to the modal.

See also:

Usage:

    local Modal = require("dkb.modal") --> Import class
    
    local test_modal = Modal(function(modal) --> Define new modal
        -- Actions will be mapped only when the modal is active
        mod1("p", print, "printing from inside modal!")
        -- Action to exit modal
        mod1("s", modal.exit, function(modal) print("exit test modal") end)
    end)
    
    -- Map action to enter modal
    mod1("s", stack_modal.enter, function(modal) print("enter modal") end)

Methods

dkb.modal:enter (action)
Enter modal. Activates it's keybindings.

Parameters:

  • action func[opt] Function to be executed after entering the modal.
dkb.modal:exit (action)
Exit modal. Deactivates it's keybindings and restores previous ones.

Parameters:

  • action func[opt] Function to be executed after exiting the modal.
dkb.modal:bind (func, arg)
Execute a function with bindings enabled. This means that bindigns executed within the function will be bound to the modal only.

Parameters:

  • func func ` Function to be executed.
  • arg Any extra argument will be passed to the provided function.
generated by LDoc 1.5.0 Last updated 2023-10-31 00:05:48