gitui icon indicating copy to clipboard operation
gitui copied to clipboard

split TextInputComponent::process_inputs into separate methods

Open gim913 opened this issue 1 year ago • 0 comments

Hello,

I've ~~stolen~~ borrowed the code that handles key combos for tui_textarea to my own project, in the process I've split it into multiple functions:

  • process_command_key - handling Ctrl
  • process_meta_key - handling Alt
  • process_meta_command_key - Ctrl + Alt
  • process_non_modded - no modifiers

I'm not sure if this is a good idea, up to you to decide.

I've double checked if all the keys that were handled before this change are also handled afterwards.

Pros:

In my opinion code is cleaner / easier to read:

	fn process_command_key(ta: &mut TextArea<'_>, key: Key) -> bool {
		match key {
			Key::Char('h') => {
				ta.delete_char();
				true
			}
			Key::Char('d') => {
				ta.delete_next_char();
				true
			}

Cons:

repeating functionality occurs in multiple methods:

	fn process_non_modded(ta: &mut TextArea<'_>, key: Key) -> bool {
...
			Key::Left => {
				ta.move_cursor(CursorMove::Back);
				true
			}
...
	}
	
	fn process_command_key(ta: &mut TextArea<'_>, key: Key) -> bool {
...
			Key::Char('b') => {
				ta.move_cursor(CursorMove::Back);
				true
			}

P.S. I've been looking at the project in 2021, it's nice to see how it progressed.

I followed the checklist:

  • [x] I ran make check without errors
  • [x] I tested the overall application
  • [?] I added an appropriate item to the changelog

gim913 avatar Jan 31 '25 22:01 gim913