src/nnn.c | 34 ++++++++++++++++++++++++++-------- src/nnn.h | 4 ++-- diff --git a/CHANGELOG b/CHANGELOG index 26ebff914331a9930b538e4b537fae8ba202ecc0..06d7405020018ddf3cacee90fd4af10487da3d20 100644 Binary files a/CHANGELOG and b/CHANGELOG differ diff --git a/src/nnn.c b/src/nnn.c index 43cbb8168664a8e7d52b645ff590cb3c512a5b17..bb3c4bce994dddaa91b42c7afe13dab5b90dc71e 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -887,17 +887,26 @@ return TRUE; } +/* Finish selection procedure before an operation */ +static void endselection(void) +{ + if (!cfg.selmode) + return; + + cfg.selmode = 0; + + if (selbufpos) { /* File path(s) written to the buffer */ + writesel(pselbuf, selbufpos - 1); /* Truncate NULL from end */ + spawn(copier, NULL, NULL, NULL, F_NOTRACE); + selbufpos = 0; + } +} + static bool selsafe(void) { /* Fail if selection file path not generated */ if (!g_selpath) { printmsg("selection file not found"); - return FALSE; - } - - /* Warn if selection not completed */ - if (cfg.selmode) { - printmsg("finish selection first"); return FALSE; } @@ -3998,7 +4007,7 @@ case SEL_RUNPAGE: if (!ndents) break; // fallthrough case SEL_REDRAW: // fallthrough - case SEL_RENAMEALL: // fallthrough + case SEL_RENAMEMUL: // fallthrough case SEL_HELP: // fallthrough case SEL_LOCK: { @@ -4017,7 +4026,9 @@ case SEL_REDRAW: if (ndents) copycurname(); goto begin; - case SEL_RENAMEALL: + case SEL_RENAMEMUL: + endselection(); + if (!batch_rename(path)) { printwait("batch rename failed", &presel); goto nochange; @@ -4185,6 +4196,8 @@ case SEL_CP: case SEL_MV: case SEL_RMMUL: { + endselection(); + if (!selsafe()) { presel = MSGWAIT; goto nochange; @@ -4242,10 +4255,13 @@ switch (sel) { case SEL_ARCHIVE: r = get_input("archive selection (else current)? [y/Y confirms]"); if (r == 'y' || r == 'Y') { + endselection(); + if (!selsafe()) { presel = MSGWAIT; goto nochange; } + tmp = NULL; } else if (!ndents) { printwait("no files", &presel); @@ -4409,6 +4425,8 @@ case SEL_PLUGKEY: // fallthrough case SEL_PLUGIN: // fallthrough case SEL_LAUNCH: // fallthrough case SEL_RUNCMD: + endselection(); + switch (sel) { case SEL_EXEC: if (!execute_file(cur, path, newpath, &presel)) diff --git a/src/nnn.h b/src/nnn.h index 8720efc1038692745933506bda091da3ebe8598f..209222c396b40316bdbb8872cc85da41d32d2459 100644 --- a/src/nnn.h +++ b/src/nnn.h @@ -84,7 +84,7 @@ SEL_RM, SEL_OPENWITH, SEL_NEW, SEL_RENAME, - SEL_RENAMEALL, + SEL_RENAMEMUL, SEL_SSHFS, SEL_UMOUNT, SEL_HELP, @@ -220,7 +220,7 @@ /* Show rename prompt */ { CONTROL('R'), SEL_RENAME }, { KEY_F(2), SEL_RENAME }, /* Rename contents of current dir */ - { 'r', SEL_RENAMEALL }, + { 'r', SEL_RENAMEMUL }, /* Connect to server over SSHFS */ { 'c', SEL_SSHFS }, /* Disconnect a SSHFS mount point */