-
-
Notifications
You must be signed in to change notification settings - Fork 609
Replace textarea with tui-textarea #2045
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
Conversation
still would like to point out that one of the tests fails on windows due to a privilege issue. It would be nice if that test was cfg !windows |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few nitpicks but ultimately the primary problem is: for me in none of the macos terminals (iterm2, Terminal, vscode embedded) the newline command works
src/components/textinput.rs
Outdated
New line is shift-enter, ctrl-enter . These are all common new line editor commands (discord, emacs,...) | ||
|
||
There is no help for the editor window. The only thing a user really needs to know is the newline key stroke, | ||
but there are 10-15 ctrl key codes. I could add then to the general help popup, or make a special one for textinput |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of a specific help popup for the editor
Its odd because I partially developed on mac so this shift-enter must be new-ish problem. Anyway there is a crossterm issue that I have reported (crossterm-rs/crossterm#861). It is immediately resolvable by changing the startup code of gitui where it sets up crossterm. But that only works in some terminals (ITerm2 works, apple terminal does not). I can also put back the ctrl-M code for newline that was there way back but one early reviewer said they didnt like it so I took it out. I will wait a few days to see what crossterm has to say |
I have added ctrl-m back , meaing 'new line' I have added the code to partially fix the mac issue, in my tests it works on iterm2, but not plain terminal. I dont think thats a good way to do it since its now not 100% clear to the user what will work when. The code is there so you can verify that it works. Fixed everything else (pedantic is a pain, I think some things are less clear now, but whatever..) Regarding adding help popup , extra key help etc... Can we get this big change in first. Everything works as before so nobody looses anything by not knowing the keystrokes |
I think thats a really bad idea, people will hate it
If you use my suggestion (ctrl-m for new line) then the feature is enabled, and nothing breaks, its an obscure key combination for use in a rare case. And maybe disable ctrl-enter on terminals where it doesnt work. Its your codebase but I guarantee you will annoy lots of users. Including me, because my muscle memory will still hit enter every time (just like I hit Esc every time to close a popup dialog because that seems natural - and it does close many popups, Annoys me every time it happens). I will be annoyed but at least I know the solution, others will not know what to do. |
i am unsure: its been a long discussion prior. see old PR. its not a stable version of gitui yet, it will be documented in the cmd-bar. if anything can be broken its before 1.0. Plus: your muscle memory will lead to no breaking change, you will insert a new-line, newcomers might be put of by the fact right now that enter is not a new-line and does a commit. plus plus: you can re-bind the command if you want to. |
How about this
Making it hard to do the no brainer thing is a really bad idea. But with the above changes people who want to make it hard to do the 99% case and easy to do the 1% case can do exactly that. Everybody happy. Commit = enter needs a new key list entry too (just thought about it). Enter is used all over the place - new branch name for example- I assume you want to keep 'enter' there and all the other places, NOTE, that textinput (branch name) should be set to single-line, its not , its left to default to multiline. Originally, I had fixed that (and a few others) in this PR but wanted to reduce the changes as much as possible, I got fanatical about making it one file. So we would need a new keydef for commit_enter or something like that |
I have modified the PR so that all the changes I suggest are there, just so you can test it out and see Here is the key config file for people who like it the hard way :-)
Includes fixing the textinput clients that should be single line (like branch name etc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for sticking with this. i think we are getting closer. i added a bunch of comments here and there.
src/components/commit.rs
Outdated
@@ -565,7 +565,7 @@ impl Component for CommitComponent { | |||
} | |||
|
|||
if let Event::Key(e) = ev { | |||
if key_match(e, self.key_config.keys.enter) | |||
if key_match(e, self.key_config.keys.multiline_enter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be commit
like we call most key bindings by its purpose elsewhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its a bit more fiddly than that . What should the behavior be for other multi-line edit boxes. For example 'reword commit'. I also wonder about stash name dialog, I changed it to be single-line but I think thats wrong, it can be a multi-line commit style message. Do all those behave the same way? If so (and I should check that they do work) them maybe 'commit' isnt the best name
src/components/create_branch.rs
Outdated
@@ -104,7 +104,8 @@ impl CreateBranchComponent { | |||
&strings::create_branch_popup_title(&env.key_config), | |||
&strings::create_branch_popup_msg(&env.key_config), | |||
true, | |||
), | |||
) | |||
.with_input_type(InputType::Singleline), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm good catch, this was already an oversight before but now its getting to be a very small input field. let me see if I can fix that on master separately
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/keys/key_list.rs
Outdated
@@ -209,6 +211,8 @@ impl Default for KeysList { | |||
view_submodule_parent: GituiKeyEvent::new(KeyCode::Char('p'), KeyModifiers::empty()), | |||
update_submodule: GituiKeyEvent::new(KeyCode::Char('u'), KeyModifiers::empty()), | |||
commit_history_next: GituiKeyEvent::new(KeyCode::Char('n'), KeyModifiers::CONTROL), | |||
multiline_enter: GituiKeyEvent::new(KeyCode::Enter, KeyModifiers::empty()), | |||
textbox_newline: GituiKeyEvent::new(KeyCode::Char('r'), KeyModifiers::CONTROL), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets call it just newline
src/main.rs
Outdated
io::stdout().execute(EnterAlternateScreen)?; | ||
Ok(()) | ||
} | ||
|
||
fn shutdown_terminal() { | ||
let leave_screen = | ||
io::stdout().execute(LeaveAlternateScreen).map(|_f| ()); | ||
stdout().execute(LeaveAlternateScreen).map(|_f| ()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets leave it consistent with above, this change is not needed
src/main.rs
Outdated
Ok(true) | ||
); | ||
if supports_keyboard_enhancement { | ||
crossterm::queue!(io::stdout(), PopKeyboardEnhancementFlags) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i dont know yet how to reproduce this but I get this printed after closing gitui using this branch:
PopKeyboardEnhancementFlags failed%
how can we get rid of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we are not using ctrl/shift enter anymore I will remove all these changes, I dont really understand why they work, people can set it up using keyboard override if they want, but they will only do it if it works (ie not on a mac). Revisit if crossterm fixes their issue
src/components/textinput.rs
Outdated
} | ||
|
||
/// Get the `msg`. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consistency: no empty line between doc comment and fn
src/components/textinput.rs
Outdated
if ends_in_nl { | ||
txt.lines.push(Line::default()); | ||
} | ||
if self.is_visible() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why recreate the whole textarea ?
src/components/textinput.rs
Outdated
self.update_count(); | ||
self.msg = msg.into(); | ||
if self.is_visible() { | ||
self.create_and_show(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why recreate the whole textarea ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dont go there :-). This code is the result of > 6 months of work arm wrestling with tui-textarea, your API into textarea (which I took as a given) and rust lifetime management.
src/components/textinput.rs
Outdated
let is_in_word = self.at_alphanumeric(index); | ||
if was_in_word && !is_in_word { | ||
return Some(last_pos); | ||
fn create_and_show(&mut self) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets call it create_inner_textarea
src/components/textinput.rs
Outdated
self.char_count | ||
)) | ||
.alignment(Alignment::Right); | ||
fn draw_newline_hint<B: Backend>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i missed that, will change. And in fact that code needs to be updated to reflect the 'commit' key anyway.
OK. we are close :-) I did everything you said. Notes: Should stash msg dialog be multi or single? I made it single but I think it should be multiple. Not sure tho. If multiple I need to change the plumbing around it too. The defaults are Enter = commit, ctrl-r = newline. I have test both these
which is the one you asked for at the start and
Which is what I originally had but doesnt work on a mac - as you found out. |
PR for #1662
now using tui-textarea v.04, that adds keyboard based text selection (hold down shift key while moving cursor with mouse)
reminder that a newline is made by pressing ctrl-enter or shift-enter