keymap

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecorateSetting

func DecorateSetting(
	setting *keymapv1.Keymap,
	config *mappings.MappingConfig,
) *keymapv1.Keymap

DecorateSetting applies metadata (Description, Name, Category) to each KeyBinding in the provided KeymapSetting using the given MappingConfig. It also fills the KeyChordsReadable field when chords are present.

func Load

func Load(reader io.Reader) (*keymapv1.Keymap, error)

Load reads from the given reader, parses the user config file format, and converts it into the internal KeymapSetting proto message.

func MustFormatKeyBinding

func MustFormatKeyBinding(kb *KeyBinding, p platform.Platform) string

func NewActioinBinding

func NewActioinBinding(action string, keyChords ...string) *keymapv1.Action

NewActioinBinding creates an ActionBinding with a single Binding. Note: Does not create ActionConfig to keep test expectations simple.

func NewActionBindingWithComment

func NewActionBindingWithComment(action, keyChords, comment string) *keymapv1.Action

NewActionBindingWithComment creates an ActionBinding with one Binding and a comment.

func NewActionBindingWithDescription

func NewActionBindingWithDescription(action, keyChords, description string) *keymapv1.Action

NewActionBindingWithDescription creates an ActionBinding with one Binding and a description.

func Save

func Save(writer io.Writer, setting *keymapv1.Keymap) error

Save takes a KeymapSetting proto message and writes it to the given writer in the user config file format.

Types

type KeyBinding

type KeyBinding struct {
	*keymapv1.Binding
}

KeyBinding represents a sequence of one or more key chords that must be pressed in order to trigger an action. This allows for multi-key sequences like "shift shift" or "ctrl+k ctrl+s".

func MustParseKeyBinding

func MustParseKeyBinding(keybind string) *KeyBinding

MustParseKeyBinding parses a vscode-like keybind string (e.g., "ctrl+c") into a KeyBinding and panics on error.

func NewKeyBinding

func NewKeyBinding(binding *keymapv1.Binding) *KeyBinding

func ParseKeyBinding

func ParseKeyBinding(keybind string, modifierSeparator string) (*KeyBinding, error)

ParseKeyBinding parse from vscode-like keybind into `KeyBinding` struct e.g. ctrl+c separator between key chords can be customized.

func (*KeyBinding) Format

func (kb *KeyBinding) Format(p platform.Platform, keyChordSeparator string) (string, error)

Format formats the key binding into a vscode-like keybind string, e.g. ctrl+c separator between key chords can be customized.

type KeybindingStrings

type KeybindingStrings []string

KeybindingStrings is a custom type to handle single or multiple keybindings.

func (KeybindingStrings) MarshalJSON

func (ks KeybindingStrings) MarshalJSON() ([]byte, error)

MarshalJSON allows KeybindingStrings to be marshalled to a single string if it contains only one element.

func (*KeybindingStrings) UnmarshalJSON

func (ks *KeybindingStrings) UnmarshalJSON(data []byte) error

UnmarshalJSON allows KeybindingStrings to be unmarshalled from either a single string or an array of strings.

type OneKeymapConfig

type OneKeymapConfig struct {
	ID          string            `json:"id,omitempty"`
	Keybinding  KeybindingStrings `json:"keybinding,omitempty"`
	Comment     string            `json:"comment,omitempty"`
	Description string            `json:"description,omitempty"`
	Name        string            `json:"name,omitempty"`
}

OneKeymapConfig is a struct that matches the user config file format.

type OneKeymapSetting

type OneKeymapSetting struct {
	// Version default to 1.0. When having breaking changes, increment the version.
	Version string            `json:"version"`
	Keymaps []OneKeymapConfig `json:"keymaps"`
}

OneKeymapSetting is the root struct for the user config file.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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