Skip to main content

HotkeySequenceRecorderController

还没翻译译自英文(tanstack.com)本页 79 段都还没译

Defined in: controllers/hotkey-sequence-recorder.ts:45

A Lit ReactiveController that records multi-chord sequences (Vim-style shortcuts).

Wraps the framework-agnostic HotkeySequenceRecorder class, managing store subscriptions and host update lifecycle automatically.

Example

class ShortcutSettings extends LitElement {
  private recorder = new HotkeySequenceRecorderController(this, {
    onRecord: (sequence) => {
      this.sequence = sequence
      this.requestUpdate()
    },
    onCancel: () => {
      console.log('Recording cancelled')
    },
  })

  private sequence: HotkeySequence | null = null

  render() {
    return html`
      <button @click=${() => this.recorder.startRecording()}>
        ${this.recorder.isRecording ? 'Recording...' : 'Edit Sequence'}
      </button>
      ${this.recorder.steps.length
        ? html`<div>Steps: ${this.recorder.steps.join(' → ')}</div>`
        : nothing}
      ${this.recorder.recordedSequence
        ? html`<div>Recorded: ${this.recorder.recordedSequence.join(' → ')}</div>`
        : nothing}
    `
  }
}

Implements

  • ReactiveController

Constructors

Constructor

new HotkeySequenceRecorderController(_host, _options): HotkeySequenceRecorderController;

Defined in: controllers/hotkey-sequence-recorder.ts:77

Parameters

_host

ReactiveControllerHost

The Lit component that owns this controller.

_options

HotkeySequenceRecorderOptions | (() => HotkeySequenceRecorderOptions)

Options or a getter, read during recording.

Returns

HotkeySequenceRecorderController

Accessors

isRecording

Get Signature

get isRecording(): boolean;

Defined in: controllers/hotkey-sequence-recorder.ts:59

Whether recording is currently active.

Returns

boolean


recordedSequence

Get Signature

get recordedSequence(): HotkeySequence | null;

Defined in: controllers/hotkey-sequence-recorder.ts:69

Last committed sequence, or null if none.

Returns

HotkeySequence | null


steps

Get Signature

get steps(): HotkeySequence;

Defined in: controllers/hotkey-sequence-recorder.ts:64

Chords captured in the current session.

Returns

HotkeySequence

Methods

cancelRecording()

cancelRecording(): void;

Defined in: controllers/hotkey-sequence-recorder.ts:139

Cancel recording without saving.

Returns

void


commitRecording()

commitRecording(): void;

Defined in: controllers/hotkey-sequence-recorder.ts:144

Commit current steps as a sequence (no-op if empty).

Returns

void


hostConnected()

hostConnected(): void;

Defined in: controllers/hotkey-sequence-recorder.ts:92

Subscribes to the recorder store and updates internal state when changes occur.

Returns

void

Implementation of

ReactiveController.hostConnected

hostDisconnected()

hostDisconnected(): void;

Defined in: controllers/hotkey-sequence-recorder.ts:114

Unsubscribes from the recorder store and destroys the recorder instance to prevent memory leaks.

Returns

void

Implementation of

ReactiveController.hostDisconnected

setOptions()

setOptions(options): void;

Defined in: controllers/hotkey-sequence-recorder.ts:124

Updates the recorder options.

Parameters

options

Partial<HotkeySequenceRecorderOptions>

Returns

void


startRecording()

startRecording(): void;

Defined in: controllers/hotkey-sequence-recorder.ts:129

Start recording a new sequence.

Returns

void


stopRecording()

stopRecording(): void;

Defined in: controllers/hotkey-sequence-recorder.ts:134

Stop recording (same as cancel but without calling onCancel).

Returns

void