-
Notifications
You must be signed in to change notification settings - Fork 43
feat: scroll with mouse faster #137
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
Open
istudyatuni
wants to merge
7
commits into
Cretezy:main
Choose a base branch
from
istudyatuni:push-nwmwvlrwullx
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
67236e6
feat: scroll with mouse faster
istudyatuni b8999f8
refactor: move match mouse event for details to details panel
istudyatuni f422613
feat: keybinds for files tab
istudyatuni 3762725
refactor: extract handle_event
istudyatuni d6c67f6
feat: mouse scroll in files tab
istudyatuni 8f7bcf3
fix: show refresh keybind in help
istudyatuni 7e9c873
chore: easier to understand scroll calculation
istudyatuni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| use std::str::FromStr; | ||
|
|
||
| use ratatui::crossterm::event::KeyEvent; | ||
|
|
||
| use crate::{make_keybinds_help, set_keybinds, update_keybinds}; | ||
|
|
||
| use super::{config::FilesTabKeybindsConfig, keybinds_store::KeybindsStore, Shortcut}; | ||
|
|
||
| #[derive(Debug)] | ||
| pub struct FilesTabKeybinds { | ||
| // todo: probably split keys for different contexts, e.g when describe_textarea is opened | ||
| keys: KeybindsStore<FilesTabEvent>, | ||
| } | ||
|
|
||
| #[derive(Debug, PartialEq, Eq, Clone, Copy)] | ||
| pub enum FilesTabEvent { | ||
| ScrollDown, | ||
| ScrollUp, | ||
| ScrollDownHalf, | ||
| ScrollUpHalf, | ||
|
|
||
| FocusCurrent, | ||
| ToggleDiffFormat, | ||
|
|
||
| Refresh, | ||
| OpenHelp, | ||
|
|
||
| Unbound, | ||
| } | ||
|
|
||
| impl Default for FilesTabKeybinds { | ||
| fn default() -> Self { | ||
| let mut keys = KeybindsStore::<FilesTabEvent>::default(); | ||
| set_keybinds!( | ||
| keys, | ||
| FilesTabEvent::ScrollDown => "j", | ||
| FilesTabEvent::ScrollDown => "down", | ||
| FilesTabEvent::ScrollUp => "k", | ||
| FilesTabEvent::ScrollUp => "up", | ||
| FilesTabEvent::ScrollDownHalf => "shift+j", | ||
| FilesTabEvent::ScrollUpHalf => "shift+k", | ||
| FilesTabEvent::FocusCurrent => "@", | ||
| // todo: move to DetailsKeybindings | ||
| FilesTabEvent::ToggleDiffFormat => "w", | ||
| FilesTabEvent::Refresh => "shift+r", | ||
| FilesTabEvent::Refresh => "f5", | ||
| FilesTabEvent::OpenHelp => "?", | ||
| ); | ||
|
|
||
| Self { keys } | ||
| } | ||
| } | ||
|
|
||
| impl FilesTabKeybinds { | ||
| pub fn match_event(&self, event: KeyEvent) -> FilesTabEvent { | ||
| if let Some(action) = self.keys.match_event(event) { | ||
| action | ||
| } else { | ||
| FilesTabEvent::Unbound | ||
| } | ||
| } | ||
| pub fn extend_from_config(&mut self, config: &FilesTabKeybindsConfig) { | ||
| update_keybinds!( | ||
| self.keys, | ||
| FilesTabEvent::ScrollDown => config.scroll_down, | ||
| FilesTabEvent::ScrollUp => config.scroll_up, | ||
| FilesTabEvent::ScrollDownHalf => config.scroll_down_half, | ||
| FilesTabEvent::ScrollUpHalf => config.scroll_up_half, | ||
| FilesTabEvent::FocusCurrent => config.focus_current, | ||
| FilesTabEvent::ToggleDiffFormat => config.toggle_diff_format, | ||
| FilesTabEvent::Refresh => config.refresh, | ||
| FilesTabEvent::OpenHelp => config.open_help, | ||
| ); | ||
| } | ||
| pub fn make_main_panel_help(&self) -> Vec<(String, String)> { | ||
| make_keybinds_help!( | ||
| self.keys, | ||
| FilesTabEvent::ScrollDown => "scroll down", | ||
| FilesTabEvent::ScrollUp => "scroll up", | ||
| FilesTabEvent::ScrollDownHalf => "scroll down by ½ page", | ||
| FilesTabEvent::ScrollUpHalf => "scroll up by ½ page", | ||
| FilesTabEvent::FocusCurrent => "view files from current change", | ||
| FilesTabEvent::Refresh => "refresh", | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_files_tab_keybinds_default() { | ||
| let _ = FilesTabKeybinds::default(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 not eliminate ScrollDown / -Up ? ScrollDownRows is more accurate.
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.
To use it as "default" scroll