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

split TextInputComponent::process_inputs into separate methods #2503

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gim913
Copy link

@gim913 gim913 commented Jan 31, 2025

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:

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

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.

1 participant