fix: allow multiple `bindCLIShortcuts` calls with shortcut merging #21103

Openedmundhung wants to merge 2 commits into main from edmundhung/main· opened yesterday
+103−3
edmundhung commented yesterdayAuthor

Fixes #15781. Closes #15881.

This fixes an issue where calling bindCLIShortcuts() multiple times would create duplicate readline instances and lose custom shortcuts from previous calls. This is useful for plugins adding their own shortcuts while Vite CLI continues to print the help message.

Now when you bind shortcuts multiple times, they are properly merged, with new custom shortcuts taking priority:

server.bindCLIShortcuts({
  customShortcuts: [
    { key: 's', description: 'My shortcut', action: () => console.log('foo') },
    { key: 'g', description: 'Greeting', action: () => console.log('Hello World') },
  ]
});

// The "enter + g" shortcut will remain available after binding
server.bindCLIShortcuts({
  customShortcuts: [
    // This overrides the previous "enter + s" shortcut
    { key: 's', description: 'my updated shortcut', action: () => console.log('foobar') },
  ]
});

This works for both dev and preview server.

edmundhung added 2 commits yesterday
fix: allow CLI shortcuts bind twice6442688
align dev server and preview server behavior634266f

Review required

Review the changes, then submit to get graded.

Some checks haven’t completed yet

1 check: dojo / review-grader

Keyboard shortcuts

Site-wide

Focus the search bar
/
Show this dialog
?

Pull request

Move to the next file
j
Move to the previous file
k
Filter changed files
t
Comment on the selected lines
c
Select a range of lines
Shiftclick