-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Keep cursor at top/bottom when navigating by page #5019
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
Keep cursor at top/bottom when navigating by page #5019
Conversation
stefanhaller
left a comment
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.
Thanks for the PR, this looks mostly good.
There's one small thing that feels like a regression to me: when you have non-model items at the top of a view, they are no longer scrolled into view when pressing ,. One example is the --- Pending rebase todos --- line at the top of the commits window when rebasing. To reproduce, select the head commit, then press i to enter an interactive rebase, then press . to scroll down one page, and then , to scroll back up. Now the top-most "pick" todo is at the top of the window, and the "Pending rebase todos" line is not visible. Before this branch it was, and when pressing < instead of , it gets scrolled into view too.
I don't have an immediate great idea what to do about it, and I don't have time to wrap my head around what's conceptually wrong here, but if you can think of ways to improve this, that would be great.
| list.MoveSelectedLine(delta) | ||
| after := list.GetSelectedLineIdx() | ||
|
|
||
| if err := self.pushContextIfNotFocused(); err != nil { |
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.
I don't think this is needed. The method is only called from keybinding handlers, so the view must be focused already, otherwise the binding wouldn't have been dispatched to it.
I realize that this is copied from handleLineChangeAux, but it doesn't seem to be needed there, either (for the same reason), so it might be nice to add a cleanup commit to remove it there, too.
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.
Removed in 2576258.
|
Ok, this is trickier than I thought. Your additional commit improves it a bit, but I felt this is too complicated, and there must be an easier way to express what we want. I pushed a commit (e2fd771) that simplifies this by decoupling the selection logic from how much we scroll the view. In other words, if we press In addition, this commit fixes jumping over-non-model items. One example is the However, with that commit I still wasn't happy because when you have a non-model item at the top (e.g. the "--- Pending rebase todos ---" line in a rebase), then if you press I intuitively felt that in that situation I want to move the cursor to the bottom of the view without scrolling at all, and I wondered what's the logic to achieve that. I decided that in general, if the selection isn't already at the bottom of the view when you press Sorry for the wall of text, all of this is hard to explain, but with this latest version the behavior feels good to me. Let me know what you think. |
|
Thanks for taking the time to refine this! Your changes make a lot of sense. The behavior feels good to me! Thanks for improving this. Let me know if you need me to test anything specific or if there's anything else I should do. |
The method is only called from keybinding handlers, so the view must be focused already, otherwise the binding wouldn't have been dispatched to it.
When pressing '.' (next page) or ',' (previous page), the selection now stays at the bottom or top of the viewport respectively, instead of being centered which caused items to scroll off. If the selection is not already on the last/first line of the view, '.'/',' moves it there without scrolling. This implements a special case for page navigation as suggested by the maintainer in issue #5017, keeping the cursor position consistent with user expectations for page-based navigation. Fixes #5017 Co-authored-by: Stefan Haller <stefan@haller-berlin.de>
8b550c8 to
8114943
Compare
|
@RaphaeleL Thanks for reviewing my changes. I squashed the commits and am going to merge once CI is green. |
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [jesseduffield/lazygit](https://github.com/jesseduffield/lazygit) | minor | `v0.56.0` -> `v0.57.0` | MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot). **Proposed changes to behavior should be submitted there as MRs.** --- ### Release Notes <details> <summary>jesseduffield/lazygit (jesseduffield/lazygit)</summary> ### [`v0.57.0`](https://github.com/jesseduffield/lazygit/releases/tag/v0.57.0) [Compare Source](jesseduffield/lazygit@v0.56.0...v0.57.0) <!-- Release notes generated using configuration in .github/release.yml at v0.57.0 --> #### What's Changed ##### Enhancements 🔥 - Open pull requests in browser with extra leading slashes removed by [@​hrzlgnm](https://github.com/hrzlgnm) in [#​5018](jesseduffield/lazygit#5018) - Allow using SelectedSubmodule in CustomCommands by [@​rlkandela](https://github.com/rlkandela) in [#​5015](jesseduffield/lazygit#5015) - Don't allow empty input in most prompts by [@​stefanhaller](https://github.com/stefanhaller) in [#​5043](jesseduffield/lazygit#5043) - Suppress output from background fetch (unless there were errors) by [@​stefanhaller](https://github.com/stefanhaller) in [#​5044](jesseduffield/lazygit#5044) - feat: add fork remote command by [@​karolzwolak](https://github.com/karolzwolak) in [#​4831](jesseduffield/lazygit#4831) - Trigger immediate background fetch when switching repos by [@​stefanhaller](https://github.com/stefanhaller) in [#​5047](jesseduffield/lazygit#5047) ##### Fixes 🔧 - Keep cursor at top/bottom when navigating by page by [@​RaphaeleL](https://github.com/RaphaeleL) in [#​5019](jesseduffield/lazygit#5019) - Switch to branches view when checking out a commit by [@​stefanhaller](https://github.com/stefanhaller) in [#​5048](jesseduffield/lazygit#5048) - Fix deleting a remote tag when a remote branch with the same name exists, or vice versa by [@​stefanhaller](https://github.com/stefanhaller) in [#​5075](jesseduffield/lazygit#5075) - Show fixup base commits in correct order in ctrl-f error message by [@​stefanhaller](https://github.com/stefanhaller) in [#​5073](jesseduffield/lazygit#5073) - Band-aid fix for rare crashes when refreshing files by [@​stefanhaller](https://github.com/stefanhaller) in [#​5074](jesseduffield/lazygit#5074) - Fix to support creating MRs for repositories cloned with SSH alias by [@​roveo](https://github.com/roveo) in [#​5082](jesseduffield/lazygit#5082) ##### Maintenance ⚙️ - Keep config and schema unchanged during a release by [@​stefanhaller](https://github.com/stefanhaller) in [#​5010](jesseduffield/lazygit#5010) - Modernize all codes by [@​phanen](https://github.com/phanen) in [#​5036](jesseduffield/lazygit#5036) - Bump golang.org/x/crypto from 0.37.0 to 0.45.0 by [@​dependabot](https://github.com/dependabot)\[bot] in [#​5054](jesseduffield/lazygit#5054) - Don't use "HEADLESS" environment variable for running tests by [@​stefanhaller](https://github.com/stefanhaller) in [#​5064](jesseduffield/lazygit#5064) - refactor: use strings.Builder and strings.Repeat to simplify code by [@​boqishan](https://github.com/boqishan) in [#​5068](jesseduffield/lazygit#5068) - chore: fix function name in comment by [@​riyueguang](https://github.com/riyueguang) in [#​4481](jesseduffield/lazygit#4481) ##### Docs 📖 - Add a "Commit history" section to CONTRIBUTING.md by [@​stefanhaller](https://github.com/stefanhaller) in [#​5022](jesseduffield/lazygit#5022) - Update table of contents in README.md by [@​madscientist16](https://github.com/madscientist16) in [#​5045](jesseduffield/lazygit#5045) - Update docs and schema for release by [@​stefanhaller](https://github.com/stefanhaller) in [#​5091](jesseduffield/lazygit#5091) ##### I18n 🌎 - Update translations from Crowdin by [@​stefanhaller](https://github.com/stefanhaller) in [#​5090](jesseduffield/lazygit#5090) ##### Performance Improvements 📊 - Fix and speed up the file list for the "Enter path to filter by" feature by [@​stefanhaller](https://github.com/stefanhaller) in [#​5056](jesseduffield/lazygit#5056) #### New Contributors - [@​hrzlgnm](https://github.com/hrzlgnm) made their first contribution in [#​5018](jesseduffield/lazygit#5018) - [@​RaphaeleL](https://github.com/RaphaeleL) made their first contribution in [#​5019](jesseduffield/lazygit#5019) - [@​rlkandela](https://github.com/rlkandela) made their first contribution in [#​5015](jesseduffield/lazygit#5015) - [@​phanen](https://github.com/phanen) made their first contribution in [#​5036](jesseduffield/lazygit#5036) - [@​madscientist16](https://github.com/madscientist16) made their first contribution in [#​5045](jesseduffield/lazygit#5045) - [@​karolzwolak](https://github.com/karolzwolak) made their first contribution in [#​4831](jesseduffield/lazygit#4831) - [@​boqishan](https://github.com/boqishan) made their first contribution in [#​5068](jesseduffield/lazygit#5068) - [@​riyueguang](https://github.com/riyueguang) made their first contribution in [#​4481](jesseduffield/lazygit#4481) - [@​roveo](https://github.com/roveo) made their first contribution in [#​5082](jesseduffield/lazygit#5082) **Full Changelog**: <jesseduffield/lazygit@v0.56.0...v0.57.0> </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi40Ny4wIiwidXBkYXRlZEluVmVyIjoiNDIuNDcuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
When pressing '.' (next page) or ',' (previous page), the selection now stays at the bottom or top of the viewport respectively, instead of being centered which caused items to scroll off. (If the selection is not already on the last/first line of the view, '.'/',' moves it there without scrolling.)
This implements a special case for page navigation as suggested by the maintainer in issue #5017, keeping the cursor position consistent with user expectations for page-based navigation.
Fixes #5017