bubbles icon indicating copy to clipboard operation
bubbles copied to clipboard

Feat(textinput): ctrl + left/right bindings for word jumping

Open NiloCK opened this issue 3 years ago • 5 comments

Expected behaviours:

  • ctrl+left/right: move one word left/right
  • ctrl+backspace/delete: delete one word left/right

The above are default behaviours in most linux and windows text editing environments. It would be nice to have them respected by the textinput.

Having spent 3 minutes reading the textinput.Update, I see that a lot of care has gone into handling some specific cases of input for the textinput bubble.

Having spent 5 minutes working in a local fork, I see that keystrokes do not come with Ctrl modifiers in the same way as Alt modifiers, and that the specific KeyCtrlN values are for letters only, and do not include the needed values for the above updates.

Is it correct to assume that there is some technical reason why Ctrl hasn't received a similar treatment as Alt?

Is access to the state of ctrl being worked on?

Thanks

NiloCK avatar May 06 '22 01:05 NiloCK

Hi! There are a few questions here so I'm dividing my response into sections accordingly.

Ctrl + Arrows

Good catch! We should absolutely add support ctrl+arrows and word-jumping as soon as https://github.com/charmbracelet/bubbletea/pull/292 is merged. That PR adds support for ctrl+arrow mappings, among another things.

Ctrl versus Alt

You're correct, ctrl is treated differently than alt for technical reasons, and that's actually why we can't provide a mapping for ctrl+backspace and ctrl+delete. ctrl modifiers in the terminal originally existed to send control characters through the wire and manipulate the terminal, which is mostly why they're so limited. For example backspace and ctrl+h both send a backspace to the terminal, and there isn't much way around that.

CSI u (see https://github.com/charmbracelet/bubbletea/issues/293) solves for this, however it's not particularly well supported and, for now, not a viable solution. It's also possible to get an enormous amount of insight into keyboard input on Windows, however we don't plan on implementing that as it's not cross-platform.

Anyway, all this said, we have considered separating out shift, ctrl, and alt modifiers so that they’d be more like alt from an API perspective. Even if we do that however, those modifiers would not be available for every single key (alt included).

meowgorithm avatar May 06 '22 02:05 meowgorithm

Appreciate the quick info! I am unsurprised that there are deep legacy issues at hand with respect to handling keyboard input in the terminal.

Happy to see progress on the arrows.

NiloCK avatar May 06 '22 02:05 NiloCK

@meowgorithm heyhey looks like the PR you mentioned with the requested changes was merged, can I go ahead and close this issue?

bashbunni avatar May 23 '22 22:05 bashbunni

@bashbunni Heya! We added the necessary key binding support in Bubble Tea to make this possible however we still need to add bindings to textinput for ctrl + left/right for word jumping as described above. So what should happen (in this order is):

  1. After the next Bubble Tea release
  2. Bump the Bubble Tea dep in Bubbles
  3. And add the above bindings to textinput

meowgorithm avatar May 24 '22 00:05 meowgorithm

Is this still in progress?

I'm trying to either use shift+enter to "submit" the text input value. Or use enter for "submission" and shift+enter for a new line. Is there a way to achieve this with the current implementation? I've tried a few things but nothing worked.

tartavull avatar Jun 14 '23 02:06 tartavull