Prevent cursor jumping to bottom after deleting file #1247
Merged
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.
Fixes #1236
This happens because by default the
dir.sel
function tries to move the cursor to the bottom of the window, which is supposedly a reasonable default if the current cursor position isn't known.Anyway I changed the code so that when a directory changes (e.g. a file gets deleted), the cursor position for the updated directory will be copied from the directory cache entry, and then
dir.sel
will just simply apply 'bounds checking' to ensure the cursor doesn't end in an invalid location.It turns out this kind of check is reusable, so I extracted it out into a separate function and applied it in the
nav.up
andnav.down
commands as well.I have tested these changes a fair bit myself, but I would appreciate it if someone else also tested it too, in case I missed something.