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.

pub type HotkeyId =
  String

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.

Options for additional keys that need to be pressed.

pub type Modifier {
  Shift
  Alt
  Short
}

Constructors

  • Shift

    Shift key

  • Alt

    Alt key

  • Short

    Control key on Windows or Linux, Command key on macOS

Functions

pub fn add(id: String, key: Hotkey) -> Nil

Add a hotkey to a hotkey id.

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_ids(key: Hotkey) -> List(String)

Get all ids associated with a hotkey.

pub fn get_keys(id: String) -> List(Hotkey)

Get all hotkeys associated with a hotkey id.

pub fn init() -> Nil
pub fn override(id: String, key: Hotkey) -> Nil

Overrides all hotkeys associated with the given id.

pub fn remove(id: String, key: Hotkey) -> Nil

Remove a hotkey from a hotkey 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) { ... }))
Search Document