]> Sergey Matveev's repositories - nnn.git/commitdiff
Fix #976: check external selection in 'c'urrent / 's'el prompt
authorArun Prakash Jana <engineerarun@gmail.com>
Wed, 28 Apr 2021 06:12:57 +0000 (11:42 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Wed, 28 Apr 2021 06:16:07 +0000 (11:46 +0530)
src/nnn.c

index 9ab807c33c93ade0d959bbe989349ec2558f0647..a89689e515d1187a30b64752f20168f9f8fc0a7e 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -1258,10 +1258,21 @@ static int get_input(const char *prompt)
        return r;
 }
 
+static bool isselfileempty(void)
+{
+       struct stat sb;
+
+       return (stat(selpath, &sb) == -1) || (!sb.st_size);
+}
+
 static int get_cur_or_sel(void)
 {
-       if (selbufpos && ndents) {
-               if (cfg.prefersel)
+       /* Check both local buffer and selection file for external selection */
+       if ((selbufpos || !isselfileempty()) && ndents) {
+               /* If selection is preferred and we have a local selection, return selection.
+                * Always show the prompt in case of an external selection.
+                */
+               if (cfg.prefersel && selbufpos)
                        return 's';
 
                int choice = get_input(messages[MSG_CUR_SEL_OPTS]);
@@ -1379,13 +1390,6 @@ static size_t seltofile(int fd, uint_t *pcount)
        return pos;
 }
 
-static bool isselfileempty(void)
-{
-       struct stat sb;
-
-       return (stat(selpath, &sb) == -1) || (!sb.st_size);
-}
-
 /* List selection from selection file (another instance) */
 static bool listselfile(void)
 {