Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
NiloCK opened this issue May 6, 2022 · 7 comments · Fixed by #387
Closed

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

NiloCK opened this issue May 6, 2022 · 7 comments · Fixed by #387
Assignees
Labels
enhancement New feature or request

Comments

@NiloCK
Copy link

NiloCK commented May 6, 2022

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

@meowgorithm
Copy link
Member

meowgorithm commented May 6, 2022

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 charmbracelet/bubbletea#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 charmbracelet/bubbletea#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).

@NiloCK
Copy link
Author

NiloCK commented May 6, 2022

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.

@bashbunni
Copy link
Member

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

@meowgorithm
Copy link
Member

@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 meowgorithm reopened this May 24, 2022
@meowgorithm meowgorithm changed the title textinput: ctrl + (left, right, backspace, del) not handled Feat(textinput): ctrl + left/right bindings for word jumping May 24, 2022
@muesli muesli added the enhancement New feature or request label Oct 5, 2022
@tartavull
Copy link

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.

@maaslalani
Copy link
Member

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.

Hey @tartavull We are planning to add a way to support shift+enter support to Bubbletea! Currently there isn't a way to recognize this binding since there is limited support in terminals but with the Kitty Keyboard Protocol which is supported in alacritty, kitty, wezterm, etc... we can support it.

@maaslalani
Copy link
Member

Fixed by #387

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants