Retain original context hovered file when selecting from plugin dir

This commit is contained in:
Arun Prakash Jana 2021-08-25 01:23:51 +05:30
parent a62dbf093a
commit 55fc0c500b
No known key found for this signature in database
GPG key ID: A75979F35C080412

View file

@ -4333,7 +4333,7 @@ static uchar_t get_free_ctx(void)
} }
/* ctx is absolute: 1 to 4, + for smart context */ /* ctx is absolute: 1 to 4, + for smart context */
static void set_smart_ctx(int ctx, char *nextpath, char **path, char **lastname, char **lastdir) static void set_smart_ctx(int ctx, char *nextpath, char **path, char *file, char **lastname, char **lastdir)
{ {
if (ctx == '+') /* Get smart context */ if (ctx == '+') /* Get smart context */
ctx = (int)(get_free_ctx() + 1); ctx = (int)(get_free_ctx() + 1);
@ -4346,7 +4346,7 @@ static void set_smart_ctx(int ctx, char *nextpath, char **path, char **lastname,
/* Deactivate the new context and build from scratch */ /* Deactivate the new context and build from scratch */
g_ctx[ctx].c_cfg.ctxactive = 0; g_ctx[ctx].c_cfg.ctxactive = 0;
DPRINTF_S(nextpath); DPRINTF_S(nextpath);
savecurctx(nextpath, ndents ? pdents[cur].name : NULL, ctx); savecurctx(nextpath, file, ctx);
*path = g_ctx[ctx].c_path; *path = g_ctx[ctx].c_path;
*lastdir = g_ctx[ctx].c_last; *lastdir = g_ctx[ctx].c_last;
*lastname = g_ctx[ctx].c_name; *lastname = g_ctx[ctx].c_name;
@ -5116,31 +5116,31 @@ static ssize_t read_nointr(int fd, void *buf, size_t count)
return len; return len;
} }
static void readpipe(int fd, char **path, char **lastname, char **lastdir) static char *readpipe(int fd, char *ctxnum, char **path)
{ {
char ctx, *nextpath = NULL; char ctx, *nextpath = NULL;
if (read_nointr(fd, g_buf, 1) != 1) if (read_nointr(fd, g_buf, 1) != 1)
return; return NULL;
if (g_buf[0] == '-') { /* Clear selection on '-' */ if (g_buf[0] == '-') { /* Clear selection on '-' */
clearselection(); clearselection();
if (read_nointr(fd, g_buf, 1) != 1) if (read_nointr(fd, g_buf, 1) != 1)
return; return NULL;
} }
if (g_buf[0] == '+') if (g_buf[0] == '+')
ctx = (char)(get_free_ctx() + 1); ctx = (char)(get_free_ctx() + 1);
else if (g_buf[0] < '0') else if (g_buf[0] < '0')
return; return NULL;
else { else {
ctx = g_buf[0] - '0'; ctx = g_buf[0] - '0';
if (ctx > CTX_MAX) if (ctx > CTX_MAX)
return; return NULL;
} }
if (read_nointr(fd, g_buf, 1) != 1) if (read_nointr(fd, g_buf, 1) != 1)
return; return NULL;
char op = g_buf[0]; char op = g_buf[0];
@ -5148,7 +5148,7 @@ static void readpipe(int fd, char **path, char **lastname, char **lastdir)
ssize_t len = read_nointr(fd, g_buf, PATH_MAX); ssize_t len = read_nointr(fd, g_buf, PATH_MAX);
if (len <= 0) if (len <= 0)
return; return NULL;
g_buf[len] = '\0'; /* Terminate the path read */ g_buf[len] = '\0'; /* Terminate the path read */
if (g_buf[0] == '/') { if (g_buf[0] == '/') {
@ -5168,15 +5168,18 @@ static void readpipe(int fd, char **path, char **lastname, char **lastdir)
g_state.picked = 1; g_state.picked = 1;
} }
if (nextpath) *ctxnum = ctx;
set_smart_ctx(ctx, nextpath, path, lastname, lastdir);
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)
{ {
pid_t p; pid_t p;
bool cmd_as_plugin = FALSE; char ctx = 0;
uchar_t flags = 0; uchar_t flags = 0;
bool cmd_as_plugin = FALSE;
char *nextpath;
if (!g_state.pluginit) { if (!g_state.pluginit) {
plctrl_init(); plctrl_init();
@ -5246,7 +5249,10 @@ static bool run_plugin(char **path, const char *file, char *runfile, char **last
rfd = open(g_pipepath, O_RDONLY); rfd = open(g_pipepath, O_RDONLY);
while (rfd == -1 && errno == EINTR); while (rfd == -1 && errno == EINTR);
readpipe(rfd, path, lastname, lastdir); nextpath = readpipe(rfd, &ctx, path);
if (nextpath)
set_smart_ctx(ctx, nextpath, path, runfile, lastname, lastdir);
close(rfd); close(rfd);
/* wait for the child to finish. no zombies allowed */ /* wait for the child to finish. no zombies allowed */
@ -6863,7 +6869,9 @@ nochange:
if (r == 'x' || r == 'm') { if (r == 'x' || r == 'm') {
if (newpath[0]) if (newpath[0])
set_smart_ctx('+', newpath, &path, &lastname, &lastdir); set_smart_ctx('+', newpath, &path,
ndents ? pdents[cur].name : NULL,
&lastname, &lastdir);
else else
copycurname(); copycurname();
clearfilter(); clearfilter();
@ -6953,7 +6961,8 @@ nochange:
goto nochange; goto nochange;
} }
set_smart_ctx('+', newpath, &path, &lastname, &lastdir); set_smart_ctx('+', newpath, &path,
ndents ? pdents[cur].name : NULL, &lastname, &lastdir);
clearfilter(); clearfilter();
goto begin; goto begin;
case SEL_CYCLE: // fallthrough case SEL_CYCLE: // fallthrough