mirror of
https://github.com/jarun/nnn.git
synced 2025-01-10 01:49:38 +00:00
Fix #257: fix the logic for determining which file was clicked.
This commit is contained in:
parent
c8e54ce4e2
commit
2297373306
11
src/nnn.c
11
src/nnn.c
|
@ -109,6 +109,8 @@
|
||||||
#define LEN(x) (sizeof(x) / sizeof(*(x)))
|
#define LEN(x) (sizeof(x) / sizeof(*(x)))
|
||||||
#undef MIN
|
#undef MIN
|
||||||
#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
||||||
|
#undef MAX
|
||||||
|
#define MAX(x, y) ((x) > (y) ? (x) : (y))
|
||||||
#define ISODD(x) ((x) & 1)
|
#define ISODD(x) ((x) & 1)
|
||||||
#define ISBLANK(x) ((x) == ' ' || (x) == '\t')
|
#define ISBLANK(x) ((x) == ' ' || (x) == '\t')
|
||||||
#define TOUPPER(ch) \
|
#define TOUPPER(ch) \
|
||||||
|
@ -3155,19 +3157,20 @@ nochange:
|
||||||
|
|
||||||
// Handle clicking on a file:
|
// Handle clicking on a file:
|
||||||
if (2 <= event.y && event.y < xlines - 2) {
|
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)
|
if (r >= ndents)
|
||||||
goto nochange;
|
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
|
// Single click just selects, double click also opens
|
||||||
if (event.bstate != BUTTON1_DOUBLE_CLICKED)
|
if (event.bstate != BUTTON1_DOUBLE_CLICKED)
|
||||||
break;
|
break;
|
||||||
|
// fallthrough to select the file
|
||||||
} else
|
} else
|
||||||
goto nochange; // fallthrough
|
goto nochange; // fallthrough
|
||||||
case SEL_NAV_IN: // fallthrough
|
case SEL_NAV_IN: // fallthrough
|
||||||
|
|
Loading…
Reference in a new issue