Skip to content

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