gitui icon indicating copy to clipboard operation
gitui copied to clipboard

Add new line support for multi-line input box

Open WizardOhio24 opened this issue 4 years ago • 15 comments

Adds multi-line support for multi-line input boxes, in particular the commit message box: Screenshot_20210208_204919

This is done with ALT+Enter, because SHIFT+Enter does not work in terminals and so does not work in crossterm.

The support is simple because it can sometimes be useful to add an extra line quickly and would be useful (and easier) to do in GitUI, but GitUI is not a text editor and so for large multi-line commit messages, a proper text editor should be used.

WizardOhio24 avatar Feb 08 '21 21:02 WizardOhio24

Can you make this showup in the commands section aswell then?

extrawurst avatar Feb 09 '21 08:02 extrawurst

Done, I'm unsure the alt symbol is that clear, but should be fixable with #516 Screenshot_20210218_194626

WizardOhio24 avatar Feb 18 '21 19:02 WizardOhio24

I just checked and it unfortunately does not work with this key binding on a Mac. it just commits, no line break. I'd like to find a binding that works on all platforms out of the box

extrawurst avatar Feb 23 '21 17:02 extrawurst

modifier keys+enter will not work reliably anyway (I think its a known limitation in crossterm)

extrawurst avatar Feb 23 '21 17:02 extrawurst

What about Enter inserts a newline and ^c (ctrl c or alt c) commits (just like ^a) amends?

terhechte avatar Mar 20 '21 15:03 terhechte

What about Enter inserts a newline and ^c (ctrl c or alt c) commits (just like ^a) amends?

Thats a good idea!

extrawurst avatar Mar 20 '21 16:03 extrawurst

^c is to exit GitUI, so I'd be worried the user could try to exit and instead commit whatever was in the textbox so right now I've changed it to alt+c, but that seems awkward. With nano it would be ^x, would that be better? (The user can always change it to what they want in the config) Happy to go with whatever people want.

WizardOhio24 avatar Apr 16 '21 16:04 WizardOhio24

Option+c does not work either on a Mac.. image

at this point only something Ctrl + ... seems to be a workable option. lets start with Ctrl + m and gather some feedback (x with Ctrl breaks my wrist ^^)

edit: damn ctrl + m is a carriage return and cannot be differentiated in crossterm, so I settled on ctrl + o for now

extrawurst avatar Apr 17 '21 08:04 extrawurst

@WizardOhio24 see https://github.com/extrawurst/gitui/pull/645

after playing around with this PR I realize we cannot merge this without also adding scrolling to the TextInputComponent otherwise after adding a couple of newlines the user cannot see the cursor anymore

extrawurst avatar Apr 17 '21 09:04 extrawurst

Yeah, I mean, this was more for writing a commit message in a single line (i.e 50 chars) then adding a new line and putting some other detail (such as issues it was linked to). If the user wanted to put in a lot of text it would be better to use nano or vim (or micro), this is more intended for small commits where 2-3 lines are needed (I think, though could be expanded to have a scrollbar).

WizardOhio24 avatar Apr 29 '21 20:04 WizardOhio24

@WizardOhio24 thanks for updating this branch. still we can do better and add the scrollbar code we use all over the place already here aswell. this makes the cursor stay in view even when adding newlines.

extrawurst avatar Apr 30 '21 12:04 extrawurst

This is emitting a warning in clippy about intersperse (on iterators), this is fine, both functions will do the same thing. All this is saying is that in the future, intersperse will be included in Rust and so will not use the itertools version. It will go away when intersperse is in stable Rust.

WizardOhio24 avatar May 23 '21 10:05 WizardOhio24

This is emitting a warning in clippy about intersperse (on iterators), this is fine, both functions will do the same thing. All this is saying is that in the future, intersperse will be included in Rust and so will not use the itertools version. It will go away when intersperse is in stable Rust.

please look for get_text_info in details.rs on how to explicitly allow this. we wanna be warning free (this turned to be an error now on master)

extrawurst avatar May 23 '21 11:05 extrawurst

This now grows the commit box as new lines are added up to a limit, at which it stops growing and starts using a scrollbar, which seems better when typing out multiline commits.

WizardOhio24 avatar May 25 '21 23:05 WizardOhio24

typed around a bit:

07:17:06 [ERROR] panic: PanicInfo { payload: Any, message: Some(attempt to subtract with overflow), location: Location { file: "src/c
omponents/textinput.rs", line: 148, col: 13 } }
trace:
[...]
  11: gitui::components::textinput::TextInputComponent::decr_cursor_multiline
             at src/components/textinput.rs:148:13
  12: gitui::components::textinput::TextInputComponent::decr_cursor
             at src/components/textinput.rs:163:13
  13: gitui::components::textinput::TextInputComponent::backspace
             at src/components/textinput.rs:286:13

also up/down behaves weird when having empty lines in between:

Screenflick Movie 18

the scrollbar is also not keeping the cursor in view. instead of adding new features like auto growing lets focus on getting one thing working first please.

extrawurst avatar May 26 '21 07:05 extrawurst

closing in favour of #1309

extrawurst avatar Sep 04 '22 17:09 extrawurst