reedline icon indicating copy to clipboard operation
reedline copied to clipboard

Handle more events for until keybindings

Open LemmusLemmus opened this issue 11 months ago • 2 comments

Currently, until keybindings only work for menu events: all other events will be considered successful and hence the remaining until cases will not be considered.

I can think of a number of events that should be considered to have failed at times: e.g. MoveToLineStart if the cursor is already at line start, CutSelection if nothing is selected, BackspaceWord if there is nothing to remove etc.

However, the only event I am personally interested in is CopySelection and CopySelectionSystem (which should reasonably fail if no text is currently selected), since being able to use until for those events would allow for e.g.

event: {
  until : [
    { edit: copyselectionsystem }
    { send: CtrlC }
  ] 
}

which in theory should emulate the behavior that many terminal emulators support as an option: Ctrl+c copies text if any text is selected, otherwise it interrupts / clears the line.

Sidenote

The line editor unselects the selected text when copyselectionsystem is activated, which seems a bit odd as I am not aware of any other text editor where that is the case.

References

The nu documentation mentions that

At the moment of this writing, only the Menu events allow this type of layering. The other non menu event types will always return a success value, meaning that the until event will stop as soon as it reaches the command.

For the ctrl+c behavior, e.g. the Kitty terminal has the mappable action copy_or_interrupt, which the line editor expectedly does not respect since it always receives Ctrl+c from Kitty, as Kitty does not recognize the readline text as selected.

LemmusLemmus avatar Jan 26 '25 11:01 LemmusLemmus

Yes making more operations aware of their success/failure would make a lot of keybinding setup more powerful. We may even be able to drop some of the ReedlineEvents we have right now that combine some behavior in favor of their simpler component parts with an Until sequence. The main limitation we have right now is that all the EditCommands don't provide their success state. So those commands that operate on the line by either doing stuff with the cursor or changing buffer content always succeed. That would be a place to refactor to implement this consistently.

sholderbach avatar Feb 10 '25 13:02 sholderbach

I tried to implement FZF original completion mode of: cd somepath/**<tab>

using 3 different approaches:

  • completion-external.nu - As an External Completer. But a change in v0.103.0 ( nushell#15086 ) breaks being able to complete cd, ls. But works okay with vi, cat, etc.

  • completion-menu.nu - Returning the result of FZF as a single menu option, and then trying to fallback to Nushell' completion_menu using event until. But trying to return null or false doesn't make the closure menu to "fail", so it doesn't fallback.

  • completion-bind.nu - prepend it as an executehostcommand to the tab keybind and tried to get it to fallback completion_menu.

I'm quite out of options. :/

Edit: Just to be a bit more clear. I would need a fallback, so if someone presses <tab> without the **, it would run Nushell' completion_menu.

imsys avatar May 07 '25 03:05 imsys