-
-
Notifications
You must be signed in to change notification settings - Fork 765
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
avoid cursor jump when file under cursor is renamed by plugin/r
#1869
Conversation
d15749a
to
e3be631
Compare
if (nextpath) | ||
set_smart_ctx(ctx, nextpath, path, runfile, lastname, lastdir); | ||
else | ||
*cd = FALSE; |
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.
Prior, there was an assumption that every plugin execution could change the directory, and so cd = TRUE
for every plugin run. We now accurately set cd
based on whether the plugin changed the directory or not.
I believe this is the only way for a plugin to change the directory, would like confirmation.
int target; | ||
if (*lastname) { | ||
target = dentfind(lastname, ndents); | ||
/* If we failed to find the previous filename, and we didn't change directories, */ | ||
/* default to the previous cursor position. This way, when a file is renamed by */ | ||
/* a plugin, the cursor does not jump to the top of the directory. */ | ||
if (target == 0 && !cd) | ||
target = cur; | ||
} else | ||
target = 0; | ||
|
||
move_cursor(target, 0); |
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.
What if now lastname
is on position 0 and we didn't cd
? You set target = cur
which is probably not what we want.
Also, we generally don't know if cur
will be a valid position after running external actions. Any number of entries may be added or removed or renamed, in which case you might as well place the cursor on a random line.
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, I didn't consider these cases. I will fix them in my fork.
From the
If you are changing only 1 file/dir, use Alternatively, use filters to reach a file quickly. Since you have just renamed it, you should be knowing the name. |
I am neither using |
This PR prevents the cursor from jumping back to the top of the directory when the active file (file underneath the cursor) is renamed by the
r
renamer tool or an external plugin.nojump.mp4
My use case:
I use
nnn
to navigate my music library, with a custom plugin to operate on music directories. Several of these commands rename the directory. Currently, once the directory is renamed (often the change of a single character), the cursor jumps back to the top of the working directory, requiring me to navigate back to where I was in a fairly large directory. After this change, the cursor no longer jumps.