keymap

package
v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package keymap sets key bindings from JSON files, so users can change shortcuts without code. It uses only the exported API of package ui.

A keymap file is a JSON array of sections, applied in order: a later section, or a later key within one, wins, as code order does. A section has an optional context (a BindIn expression; none means global) and its bindings. A value is an action name, null (NoAction) or {"unbind": name} (Unbind):

[
  {"bindings": {"ctrl+shift+n": "notes.new"}},
  {"context": "Editor", "bindings": {
    "ctrl+d": "editor.delete-forward",
    "ctrl+a": null,
    "ctrl+z": {"unbind": "editor.undo"}
  }}
]

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(path string, actions []*ui.Action) ([]ui.Binding, error)

Load reads the keymap file at path and parses it as Parse does. A missing file is not an error: it returns no bindings and a nil error. Other errors name the file.

func Parse

func Parse(data []byte, actions []*ui.Action) ([]ui.Binding, error)

Parse reads a keymap file (see the package documentation) and returns its bindings in file order. actions are the actions the file may name, in addition to the text-field actions (ui.EditorActions) and ui.NoAction, which are always available. Every problem is reported, naming its section (1-based), context and keys; the valid bindings are returned along with the errors, joined.

Types

type File

type File struct {
	// Path is the path of the keymap file.
	Path string
	// Actions lists the actions that the file may name.
	Actions []*ui.Action
	// contains filtered or unexported fields
}

File is a keymap file applied to a runtime as its own binding layer, named "keymap:"+Path, which keeps its place among the bindings (see ui.Runtime.SetBindings). Actions are the actions the file may name.

func (*File) Apply

func (f *File) Apply(rt *ui.Runtime) (changed bool, err error)

Apply reads the file and applies it to rt, which must run on the UI thread. It reads the file on each call and does nothing when the bytes are the same as last time, so it is cheap to call on every change notification.

A missing file removes the layer. A file that cannot be read, or that is not a JSON array, keeps the layer as it was and returns the error, so a half-saved file does not wipe the user's keymap. Otherwise the layer is replaced by the file's valid bindings, and err joins the problems with the entries that were skipped; changed reports whether the bindings changed (or the file could not be read).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL