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

Prevent cursor jumping to bottom after deleting file #1247

Merged
merged 1 commit into from
May 21, 2023
Merged

Prevent cursor jumping to bottom after deleting file #1247

merged 1 commit into from
May 21, 2023

Conversation

joelim-work
Copy link
Collaborator

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 and nav.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.

@gokcehan
Copy link
Owner

@joelim-work It looks good, thanks for the patch.

@gokcehan gokcehan merged commit 24bba62 into gokcehan:master May 21, 2023
@joelim-work joelim-work deleted the bound-pos branch May 21, 2023 12:42
@ilyagr
Copy link
Collaborator

ilyagr commented Jun 5, 2023

FYI, I noticed this changes the behavior of lf if it shows at least 3 columns and you do the following:

$ mkdir t{1..100}                                                     
$ cd t55
$ lf

Previously, as lf starts, the parent directory in the column one left from the active cursor was shown at the bottom of the list. Now, it's at the top.

I don't think this is a problem, it could even be considered a minor improvement. My ultimate preference would be for the parent directory to be in the middle, but I don't think that's important.

@gokcehan gokcehan mentioned this pull request Sep 17, 2023
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.

Delete after scrolling in large directories jumps cursor
3 participants