]> Sergey Matveev's repositories - nnn.git/commitdiff
Add middle click copy (#491)
authorlvgx <l@vgx.fr>
Wed, 11 Mar 2020 03:39:57 +0000 (04:39 +0100)
committerGitHub <noreply@github.com>
Wed, 11 Mar 2020 03:39:57 +0000 (09:09 +0530)
* Add middle click copy

* Make middle click action configurable

This introduces the NNN_MIDDLECLICK environment variable, containing the
key that middle mouse click emulates. Only the first character is read.

* Document NNN_MIDDLECLICK in nnn.1

* Use NNN_MCLICK instead of NNN_MIDDLECLICK

* Add '^key' syntax to set middle click to Ctrl+Key

nnn.1
src/nnn.c

diff --git a/nnn.1 b/nnn.1
index 3682e094c7d79aa22dd4e1eff80ae0f32e369fc5..28e069df545619d456bc37afd9ece89caf7f76c1 100644 (file)
--- a/nnn.1
+++ b/nnn.1
@@ -375,6 +375,18 @@ separated by \fI;\fR:
     export NNN_TRASH=1
 .Ed
 .Pp
+\fBNNN_MCLICK:\fR key emulated by a middle mouse click.
+.Bd -literal
+    export NNN_MCLICK='p'
+
+    NOTES:
+    1. You can use the '^\fIkey\fR' syntax to assign it to a \fICtrl+key\fR combo, e.g.:
+
+    export NNN_MCLICK='^A'
+
+    2. Otherwise, only the first character is taken into account.
+.Ed
+.Pp
 \fBnnn:\fR this is a special variable set to the hovered entry before executing
 a command from the command prompt or spawning a shell.
 .Sh KNOWN ISSUES
index 9633c46f37fa69aefdf2f0b547ec742ba7e25272..d2370635d0ee0275bd844c9479995427f17f5196 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -362,6 +362,9 @@ static kv *plug;
 static uchar tmpfplen;
 static uchar blk_shift = BLK_SHIFT_512;
 static const uint _WSHIFT = (LONG_SIZE == 8) ? 3 : 2;
+#ifndef NOMOUSE
+static int middle_click_key;
+#endif
 #ifdef PCRE
 static pcre *archive_pcre;
 #else
@@ -567,8 +570,9 @@ static const char * const messages[] = {
 #define NNN_COLORS 4
 #define NNNLVL 5
 #define NNN_PIPE 6
-#define NNN_ARCHIVE 7 /* strings end here */
-#define NNN_TRASH 8 /* flags begin here */
+#define NNN_MCLICK 7
+#define NNN_ARCHIVE 8 /* strings end here */
+#define NNN_TRASH 9 /* flags begin here */
 
 static const char * const env_cfg[] = {
        "NNN_OPTS",
@@ -578,6 +582,7 @@ static const char * const env_cfg[] = {
        "NNN_COLORS",
        "NNNLVL",
        "NNN_PIPE",
+       "NNN_MCLICK",
        "NNN_ARCHIVE",
        "NNN_TRASH",
 };
@@ -1459,10 +1464,10 @@ static bool initcurses(void *oldmask)
        keypad(stdscr, TRUE);
 #ifndef NOMOUSE
 #if NCURSES_MOUSE_VERSION <= 1
-       mousemask(BUTTON1_PRESSED | BUTTON1_DOUBLE_CLICKED | BUTTON3_PRESSED,
+       mousemask(BUTTON1_PRESSED | BUTTON1_DOUBLE_CLICKED | BUTTON2_PRESSED | BUTTON3_PRESSED,
                        (mmask_t *)oldmask);
 #else
-       mousemask(BUTTON1_PRESSED | BUTTON3_PRESSED | BUTTON4_PRESSED | BUTTON5_PRESSED,
+       mousemask(BUTTON1_PRESSED | BUTTON2_PRESSED | BUTTON3_PRESSED | BUTTON4_PRESSED | BUTTON5_PRESSED,
                        (mmask_t *)oldmask);
 #endif
        mouseinterval(0);
@@ -5141,6 +5146,11 @@ nochange:
 #endif
 
 #ifndef NOMOUSE
+                       /* Middle click action */
+                       if (event.bstate == BUTTON2_PRESSED) {
+                               presel = middle_click_key;
+                               goto nochange;
+                       }
 #if NCURSES_MOUSE_VERSION > 1
                        /* Scroll up */
                        if (event.bstate == BUTTON4_PRESSED && ndents && (cfg.rollover || cur)) {
@@ -6592,6 +6602,11 @@ int main(int argc, char *argv[])
        int opt;
 #ifndef NOMOUSE
        mmask_t mask;
+       char *middle_click_env = xgetenv(env_cfg[NNN_MCLICK], "\0");
+       if (middle_click_env[0] == '^' && middle_click_env[1])
+               middle_click_key = CONTROL(middle_click_env[1]);
+       else
+               middle_click_key = middle_click_env[0];
 #endif
        const char* const env_opts = xgetenv(env_cfg[NNN_OPTS], NULL);
        int env_opts_id = env_opts ? (int)strlen(env_opts) : -1;