Skip to content

Add new line support for multi-line input box #509

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

Closed
wants to merge 35 commits into from

Conversation

WizardOhio24
Copy link
Contributor

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 WizardOhio24 marked this pull request as ready for review February 8, 2021 21:13
@extrawurst
Copy link
Collaborator

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

@WizardOhio24
Copy link
Contributor Author

WizardOhio24 commented Feb 18, 2021

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

@extrawurst
Copy link
Collaborator

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
Copy link
Collaborator

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

@extrawurst extrawurst marked this pull request as draft February 23, 2021 17:38
@extrawurst extrawurst force-pushed the master branch 2 times, most recently from 81a8849 to f84f6f4 Compare March 3, 2021 21:27
@terhechte
Copy link
Contributor

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

@extrawurst
Copy link
Collaborator

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

Thats a good idea!

@WizardOhio24
Copy link
Contributor Author

^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.

@extrawurst
Copy link
Collaborator

extrawurst commented Apr 17, 2021

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
Copy link
Collaborator

@WizardOhio24 see #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

Stephan Dilly and others added 2 commits April 29, 2021 21:36
@WizardOhio24
Copy link
Contributor Author

WizardOhio24 commented Apr 29, 2021

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).

@extrawurst
Copy link
Collaborator

extrawurst commented Apr 30, 2021

@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.

@WizardOhio24
Copy link
Contributor Author

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.

@extrawurst
Copy link
Collaborator

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.

&& self.scroll_max >= 3
{
self.scroll_top = self.scroll_top.saturating_sub(1);
//self.cur_line = self.cur_line.saturating_sub(1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove commented code please

let mut nearest_newline: usize = 0;
let mut prev_line_newline_loc = 0;
for (i, c) in self.msg.chars().enumerate() {
if c == '\n' {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does this behave on windows where a newline is two chars wide?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A newline can be 2 chars? It's just '\n', right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, google ‚windows line endings‘

break;
}
}
// if !self.msg.is_char_boundary(i) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to get the scrolling working with characters which occupy more than 1 byte, such as ö or é. This code should have worked, but it doesn't, nothing seems to.

Size::new(10, 3),
Size::new(
10,
min(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is clamp for this

"New Line [{}]",
key_config.get_hint(key_config.enter),
),
"make a new line in the commit message",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

insert newline

@extrawurst
Copy link
Collaborator

closing in favour of #1309

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

Successfully merging this pull request may close these issues.

3 participants