novdom/hotkey
Types
Hotkey definition.
pub type Hotkey {
Hotkey(code: String, modifiers: List(Modifier))
}
Constructors
-
Hotkey(code: String, modifiers: List(Modifier))
The Code needs to be the
event.code
from JavaScript (e.g. “KeyB”), see https://keycode.info/.
The Modifiers are the additional keys that need to be pressed.
Options when adding a hotkey to a callback.
pub type HotkeyOption {
Key(Hotkey)
Id(HotkeyId)
}
Constructors
-
Key(Hotkey)
Add a hotkey directly.
-
Id(HotkeyId)
Use an existing hotkey id.
Functions
pub fn configure_ids(
config: List(#(String, List(Hotkey))),
) -> Nil
Configure hotkeys with a list of hotkey ids and their corresponding hotkeys. Ids do not need to be unique and the same hotkey can be used for multible ids.
This should be called once at the beginning of the application (rigth after novdom.start(..)
).
Example:
hotkey.configure_ids([
#("bold", [Hotkey("KeyB", [Short])]),
#("italic", [Hotkey("KeyI", [Short])]),
#("underline", [Hotkey("KeyU", [Short])]),
])
pub fn get_keys(id: String) -> List(Hotkey)
Get all hotkeys associated with a hotkey id.
pub fn override(id: String, key: Hotkey) -> Nil
Overrides all hotkeys associated with the given id.
pub fn with_hotkey(
option: HotkeyOption,
callback: fn(Event) -> Nil,
) -> fn(Event) -> Nil
Add a hotkey to a callback.
Example:
onclick(with_hotkey(Key(Hotkey("KeyB", [Short])), fn(e) { ... }))
onclick(with_hotkey(Id("bold"), fn(e) { ... }))