Skip to content

Commit

Permalink
Fix scroll position resetting on resize
Browse files Browse the repository at this point in the history
In several cases when the terminal was resized the scroll position was
reset back to the top. This was partially by design as a quick fix to
ensure that the top position did not go out of bounds. This change adds
a new function to the scroll position module that will ensure that the
scroll top value stays within the allowed range when the view is
resized.
  • Loading branch information
MitMaro committed May 23, 2020
1 parent 0bf3ad3 commit 4fb102c
Show file tree
Hide file tree
Showing 5 changed files with 646 additions and 48 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed
- Change page up and page down to scroll half the height of the view area

### Fixed
- Scroll position resetting on resize

## [1.2.1] - 2020-01-26

### Fixed
Expand Down
7 changes: 6 additions & 1 deletion src/help/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ impl<'h> ProcessModule for Help<'h> {
self.scroll_position.page_up(view_height, self.get_help_lines().len());
},
Input::Resize => {
self.scroll_position.reset();
self.scroll_position.view_resize(
view_height,
view_width,
self.get_help_lines().len(),
self.get_max_help_line_length(),
);
},
_ => {
result = result.state(self.return_state.clone());
Expand Down
1 change: 1 addition & 0 deletions src/list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ impl<'l> ProcessModule for List<'l> {
let (_, view_height) = view.get_view_size();
let lines = git_interactive.get_lines();
let selected_index = *git_interactive.get_selected_line_index() - 1;
// TODO move this to handle_input
self.scroll_position
.ensure_cursor_visible(selected_index, view_height, lines.len());

Expand Down
11 changes: 7 additions & 4 deletions src/show_commit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ impl ProcessModule for ShowCommit {
view: &View,
) -> HandleInputResult
{
let (view_width, view_height) = view.get_view_size();

let input = input_handler.get_input(InputMode::Default);
let (view_width, view_height) = view.get_view_size();
let mut result = HandleInputResultBuilder::new(input);
match input {
Input::MoveCursorLeft => {
Expand Down Expand Up @@ -84,8 +83,12 @@ impl ProcessModule for ShowCommit {
.page_up(view_height, self.get_commit_stats_length())
},
Input::Resize => {
self.scroll_position
.scroll_up(view_height, self.get_commit_stats_length());
self.scroll_position.view_resize(
view_height,
view_width,
self.get_commit_stats_length(),
self.get_max_line_length(view_height),
)
},
_ => {
result = result.state(State::List(false));
Expand Down
Loading

0 comments on commit 4fb102c

Please sign in to comment.