diff options
author | Bruce Hill <bruce@bruce-hill.com> | 2019-05-08 19:37:37 -0700 |
---|---|---|
committer | Arun Prakash Jana <engineerarun@gmail.com> | 2019-05-22 08:44:19 +0530 |
commit | 22973733066c5939ed6c41992c907ff5f09b7923 (patch) | |
tree | 0227453eb74585977ebb4d6df0745f184c3e52b5 /src | |
parent | c8e54ce4e24036f35d81b475033cf24c1838f317 (diff) | |
download | nnn-22973733066c5939ed6c41992c907ff5f09b7923.tar.gz |
Fix #257: fix the logic for determining which file was clicked.
Diffstat (limited to 'src')
-rw-r--r-- | src/nnn.c | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -109,6 +109,8 @@ #define LEN(x) (sizeof(x) / sizeof(*(x))) #undef MIN #define MIN(x, y) ((x) < (y) ? (x) : (y)) +#undef MAX +#define MAX(x, y) ((x) > (y) ? (x) : (y)) #define ISODD(x) ((x) & 1) #define ISBLANK(x) ((x) == ' ' || (x) == '\t') #define TOUPPER(ch) \ @@ -3155,19 +3157,20 @@ nochange: // Handle clicking on a file: if (2 <= event.y && event.y < xlines - 2) { - r = event.y - 2; + // Get index of the first file listed on-screen: + r = MAX(0, MIN(cur-((xlines-4)>>1), ndents-(xlines-4))); + // Add the mouse click position to get the clicked file: + r += event.y - 2; if (r >= ndents) goto nochange; - if (ndents > (xlines - 4) && cur >= ((xlines - 4) >> 1)) - cur -= ((xlines - 4) >> 1) - r; - else - cur = r; + cur = r; // Single click just selects, double click also opens if (event.bstate != BUTTON1_DOUBLE_CLICKED) break; + // fallthrough to select the file } else goto nochange; // fallthrough case SEL_NAV_IN: // fallthrough |