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

Add more cursor movements #154

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

sebashwa
Copy link

@sebashwa sebashwa commented May 16, 2022

Hey,

thanks for creating this app, I like it a lot! I thought it might make sense to provide more cursor movement / input editing keybindings. To start with Ctrl-w (word deletion) seemed useful to me in order to delete i.e. a database filter query quickly.

Following changes are included in this PR so far:

  • Refactor logic for keyboard input into a separate util struct
  • Add tests for existing cursor movement functions
  • Allow database selection from list while filter is focused
  • Fix databases component to update directly after keystroke in filter
  • Add Ctrl-w to delete backwards until next whitespace
  • Add Alt-Backspace to delete backwards until next non alphanumeric char
  • Add Ctrl-b to navigate backwards one char
  • Add Ctrl-f to navigate forwards one char
  • Add Ctrl-d to delete char under cursor
  • Add Alt-b to navigate backwards until next non alphanumeric char
  • Add Alt-f to navigate forwards until next non alphanumeric char
  • Add Alt-d to delete forwards until next non alphanumeric char

Any feedback (especially concerning the refactoring) very welcome, as I am not super proficient writing Rust so far.

sebashwa

sebashwa added 15 commits May 15, 2022 21:03
Most of the input logic was duplicated in three places as of now:

* Database filter input
* SQL Editor
* Table filter

This is done in preparation for adding more cursor movement
functionality for inputs.
<Ctrl-w> deletes the input from the current cursor position up to the
first occurence of a whitespace before the current position.
The database tree was updated for the filter string of the previous key
press before. This became more apparent with the new movements like
'delete word' (Ctrl-w).
This deletes in the left direction until a non alphanumeric character is
found.
This makes UX much smoother IMHO.
The filter focus is now moved back to the tree by pressing <Esc> while
in filtering mode.
Move backwards until first non alphanumeric occurence.
Until the next occurence of a nonalphanumeric char.
Until a non alphanumeric char.
To be more consistent with wording.
@TaKO8Ki
Copy link
Owner

TaKO8Ki commented May 23, 2022

Sorry for the late review. I will review when I have time.

@sebashwa
Copy link
Author

Sorry for the late review. I will review when I have time.

Hey, no worries and thanks for taking the time! From my point of view it is pretty complete now.
I hope it didn't grow too big.

self.focus = Focus::Tree;
return Ok(EventState::Consumed);
}
Key::Ctrl('j') | Key::Ctrl('n') => {
Copy link
Author

Choose a reason for hiding this comment

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

Not sure if this is a desired change at all and wether we should take custom key bindings into account?

@@ -69,6 +69,7 @@ pub enum Key {
Char(char),
Ctrl(char),
Alt(char),
AltBackspace,
Copy link
Author

Choose a reason for hiding this comment

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

I'm sure this can be done in a more elegant way like Alt(Key::Backspace)? But I couldn't wrap my head around this.

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.

2 participants