Skip to content

Enhance documentation for atom.commands.dispatch() method#1411

Merged
savetheclocktower merged 3 commits into
pulsar-edit:masterfrom
trusktr:patch-1
Feb 14, 2026
Merged

Enhance documentation for atom.commands.dispatch() method#1411
savetheclocktower merged 3 commits into
pulsar-edit:masterfrom
trusktr:patch-1

Conversation

@trusktr

@trusktr trusktr commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

Add comments to clarify that atom.commands.dispatch() can pass arguments to commands.

I haven't tested it yet, but this detail arg seems to allow for the following ability:

atom.commands.add(`selector`, {
  'my:custom-command': event => console.log(event.detail),
})

And this:

atom.commands.onDidDispatch(event => {
  console.log(event.type, event.detail)
});

Technically we can dispatch a command like this too:

class MyCustomEvent extends Event {
  foo = 123
  bar = 456

  constructor(foo, bar) {
    this.foo = foo ?? this.foo
    this.bar = bar ?? this.bar
    super('my:custom-command')
  }
}

const event = MyCustomEvent(42, 84)

Object.defineProperty(event, 'target', { value: atom.workspace.element });
atom.commands.handleCommandEvent(event);

and the command handler could use those properties:

atom.commands.add('selector', {
  'my:custom-command': ({foo, bar}) => console.log(foo, bar), // logs "42 84"
})

A separate PR should be able to add arg support for key maps if it doesn't exist already (or document that if it does). For keymaps, the .detail property makes sense, as there'd be no way to handle custom event classes via static JSON (unless we maintained a map of class by their class name, and use their class name in the JSON).

Add comments to clarify that atom.commands.dispatch() can pass arguments to commands
Copilot AI review requested due to automatic review settings February 4, 2026 20:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enhances the inline API documentation for CommandRegistry::dispatch() to clarify that command dispatch can carry arguments via event detail.

Changes:

  • Add explanatory notes describing using dispatch() to pass arguments when keymaps can’t.
  • Document the detail parameter as being assigned to the dispatched event’s .detail.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/command-registry.js Outdated
Comment thread src/command-registry.js Outdated
savetheclocktower and others added 2 commits February 14, 2026 14:36
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@savetheclocktower savetheclocktower merged commit d9cdd95 into pulsar-edit:master Feb 14, 2026
197 of 199 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants