src/nnn.c | 45 ++++++++++++++++++++++++++++++++------------- src/nnn.h | 3 +++ diff --git a/src/nnn.c b/src/nnn.c index 36e2c30d0b769f8518a025c7428e5d33f5788b08..59bfb00187cc26e2f86da2ed1580cbfe9ba85a36 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -4617,9 +4617,10 @@ "b^R Rename/dup%-14cr Batch rename\n" "cz Archive%-17ce Edit file\n" "c* Toggle exe%-14c> Export list\n" "5Space ^J (Un)select%-7cm ^Space Mark range/clear sel\n" - "9p ^P Copy sel here%-11ca Select all\n" - "9v ^V Move sel here%-8cw ^W Cp/mv sel as\n" - "9x ^X Delete%-18cE Edit sel\n" + "ca Select all%-14cA Invert sel\n" + "9p ^P Copy sel here%-8cw ^W Cp/mv sel as\n" + "9v ^V Move sel here%-11cE Edit sel\n" + "9x ^X Delete\n" "1MISC\n" "8Alt ; Select plugin%-11c= Launch app\n" "9! ^] Shell%-19c] Cmd prompt\n" @@ -6615,8 +6616,9 @@ resetselind(); clearselection(); break; } // fallthrough - case SEL_SELALL: - if (sel == SEL_SELALL) { + case SEL_SELALL: // fallthrough + case SEL_SELINV: + if (sel == SEL_SELALL || sel == SEL_SELINV) { if (!ndents) goto nochange; @@ -6628,17 +6630,34 @@ selstartid = 0; selendid = ndents - 1; } - /* Remember current selection buffer position */ - for (r = selstartid; r <= selendid; ++r) - if (!(pdents[r].flags & FILE_SELECTED)) { - /* Write the path to selection file to avoid flush */ - appendfpath(newpath, mkpath(path, pdents[r].name, newpath)); + if (sel == SEL_SELINV) { + /* Toggle selection status */ + for (r = selstartid; r <= selendid; ++r) { + pdents[r].flags ^= FILE_SELECTED; + pdents[r].flags & FILE_SELECTED ? ++nselected : --nselected; + } - pdents[r].flags |= FILE_SELECTED; - ++nselected; + selbufpos = lastappendpos; + if (nselected) { + updateselbuf(path, newpath); + writesel(pselbuf, selbufpos - 1); /* Truncate NULL from end */ + } else + writesel(NULL, 0); + } else { + /* Remember current selection buffer position */ + for (r = selstartid; r <= selendid; ++r) { + if (!(pdents[r].flags & FILE_SELECTED)) { + /* Write the path to selection file to avoid flush */ + appendfpath(newpath, mkpath(path, pdents[r].name, newpath)); + + pdents[r].flags |= FILE_SELECTED; + ++nselected; + } } - writesel(pselbuf, selbufpos - 1); /* Truncate NULL from end */ + writesel(pselbuf, selbufpos - 1); /* Truncate NULL from end */ + } + if (cfg.x11) plugscript(utils[UTIL_CBCP], F_NOWAIT | F_NOTRACE); continue; diff --git a/src/nnn.h b/src/nnn.h index 222d1a955b34587534e6e0cd505799973d49a606..605caff36b2cf74152a9932af99628debdd9838f 100644 --- a/src/nnn.h +++ b/src/nnn.h @@ -87,6 +87,7 @@ SEL_REDRAW, SEL_SEL, SEL_SELMUL, SEL_SELALL, + SEL_SELINV, SEL_SELEDIT, SEL_CP, SEL_MV, @@ -215,6 +216,8 @@ { 'm', SEL_SELMUL }, { CONTROL(' '), SEL_SELMUL }, /* Select all files in current dir */ { 'a', SEL_SELALL }, + /* Invert selection in current dir */ + { 'A', SEL_SELINV }, /* List, edit selection */ { 'E', SEL_SELEDIT }, /* Copy from selection buffer */