-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5394,7 +5394,7 @@ static char *readpipe(int fd, char *ctxnum, char **path) | |
return nextpath; | ||
} | ||
|
||
static bool run_plugin(char **path, const char *file, char *runfile, char **lastname, char **lastdir) | ||
static bool run_plugin(char **path, const char *file, char *runfile, char **lastname, char **lastdir, bool *cd) | ||
{ | ||
pid_t p; | ||
char ctx = 0; | ||
|
@@ -5477,6 +5477,8 @@ static bool run_plugin(char **path, const char *file, char *runfile, char **last | |
nextpath = readpipe(rfd, &ctx, path); | ||
if (nextpath) | ||
set_smart_ctx(ctx, nextpath, path, runfile, lastname, lastdir); | ||
else | ||
*cd = FALSE; | ||
|
||
close(rfd); | ||
|
||
|
@@ -5991,7 +5993,7 @@ static int dentfill(char *path, struct entry **ppdents) | |
return ndents; | ||
} | ||
|
||
static void populate(char *path, char *lastname) | ||
static void populate(char *path, char *lastname, bool cd) | ||
{ | ||
#ifdef DEBUG | ||
struct timespec ts1, ts2; | ||
|
@@ -6014,7 +6016,18 @@ static void populate(char *path, char *lastname) | |
|
||
/* Find cur from history */ | ||
/* No NULL check for lastname, always points to an array */ | ||
move_cursor(*lastname ? dentfind(lastname, ndents) : 0, 0); | ||
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); | ||
Comment on lines
+6019
to
+6030
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if now Also, we generally don't know if There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
// Force full redraw | ||
last_curscroll = -1; | ||
|
@@ -6887,15 +6900,16 @@ static bool browse(char *ipath, const char *session, int pkey) | |
} else | ||
cfgsort[cfg.curctx] = cfgsort[CTX_MAX]; | ||
} | ||
cd = TRUE; | ||
|
||
populate(path, lastname); | ||
populate(path, lastname, cd); | ||
if (g_state.interrupt) { | ||
g_state.interrupt = cfg.apparentsz = cfg.blkorder = 0; | ||
blk_shift = BLK_SHIFT_512; | ||
presel = CONTROL('L'); | ||
} | ||
|
||
cd = TRUE; | ||
|
||
#ifdef LINUX_INOTIFY | ||
if (presel != FILTER && inotify_wd == -1) | ||
inotify_wd = inotify_add_watch(inotify_fd, path, INOTIFY_MASK); | ||
|
@@ -7122,7 +7136,7 @@ static bool browse(char *ipath, const char *session, int pkey) | |
clearfilter(); | ||
|
||
if (chdir(path) == -1 | ||
|| !run_plugin(&path, pent->name, runfile, &lastname, &lastdir)) { | ||
|| !run_plugin(&path, pent->name, runfile, &lastname, &lastdir, &cd)) { | ||
DPRINTF_S("plugin failed!"); | ||
} | ||
|
||
|
@@ -7940,7 +7954,7 @@ static bool browse(char *ipath, const char *session, int pkey) | |
r = TRUE; | ||
|
||
if (!run_plugin(&path, tmp, (ndents ? pdents[cur].name : NULL), | ||
&lastname, &lastdir)) { | ||
&lastname, &lastdir, &cd)) { | ||
printwait(messages[MSG_FAILED], &presel); | ||
goto nochange; | ||
} | ||
|
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 setcd
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.