fix: fix Files double-click bug
This commit is contained in:
1 parent
8de98f3ab3
commit
8ae19258b1
3 files changed
+21
-10
No files matched your search
@@ -12,4 +12,4 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define MONTAUK_BUILD_NUMBER 21
|
#define MONTAUK_BUILD_NUMBER 22
|
||||||
@@ -73,6 +73,13 @@ bool filemanager_dnd_mouse(Window* win, FileManagerState* fm, const FileManagerL
|
|||||||
}
|
}
|
||||||
if (fm->drag_serial) return true;
|
if (fm->drag_serial) return true;
|
||||||
|
|
||||||
|
// A fresh press means we missed the release of the armed one (focus
|
||||||
|
// went elsewhere mid-press); drop it and let this press be handled anew.
|
||||||
|
if (ev.left_pressed()) {
|
||||||
|
fm->press_idx = -1;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int dx = x - fm->press_x;
|
int dx = x - fm->press_x;
|
||||||
int dy = y - fm->press_y;
|
int dy = y - fm->press_y;
|
||||||
if (dx * dx + dy * dy < DRAG_THRESHOLD * DRAG_THRESHOLD) return true;
|
if (dx * dx + dy * dy < DRAG_THRESHOLD * DRAG_THRESHOLD) return true;
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ static bool filemanager_is_listing(const FileManagerState* fm) {
|
|||||||
// Left click on an entry. Ctrl toggles it, Shift selects the range from the
|
// Left click on an entry. Ctrl toggles it, Shift selects the range from the
|
||||||
// anchor (Ctrl+Shift adds that range); a plain click selects it alone, and a
|
// anchor (Ctrl+Shift adds that range); a plain click selects it alone, and a
|
||||||
// second plain click within 400 ms opens it.
|
// second plain click within 400 ms opens it.
|
||||||
static void filemanager_click_entry(FileManagerState* fm, int idx) {
|
// True if the click opened the entry (the second click of a double-click).
|
||||||
|
static bool filemanager_click_entry(FileManagerState* fm, int idx) {
|
||||||
DesktopState* ds = fm->desktop;
|
DesktopState* ds = fm->desktop;
|
||||||
bool ctrl = ds && ds->kbd_ctrl_down;
|
bool ctrl = ds && ds->kbd_ctrl_down;
|
||||||
bool shift = ds && ds->kbd_shift_down;
|
bool shift = ds && ds->kbd_shift_down;
|
||||||
@@ -38,7 +39,7 @@ static void filemanager_click_entry(FileManagerState* fm, int idx) {
|
|||||||
else filemanager_toggle_selection(fm, idx);
|
else filemanager_toggle_selection(fm, idx);
|
||||||
fm->last_click_item = -1;
|
fm->last_click_item = -1;
|
||||||
fm->last_click_time = 0;
|
fm->last_click_time = 0;
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t now = montauk::get_milliseconds();
|
uint64_t now = montauk::get_milliseconds();
|
||||||
@@ -46,11 +47,12 @@ static void filemanager_click_entry(FileManagerState* fm, int idx) {
|
|||||||
filemanager_open_entry(fm, idx);
|
filemanager_open_entry(fm, idx);
|
||||||
fm->last_click_item = -1;
|
fm->last_click_item = -1;
|
||||||
fm->last_click_time = 0;
|
fm->last_click_time = 0;
|
||||||
} else {
|
return true;
|
||||||
filemanager_select_single(fm, idx);
|
|
||||||
fm->last_click_item = idx;
|
|
||||||
fm->last_click_time = now;
|
|
||||||
}
|
}
|
||||||
|
filemanager_select_single(fm, idx);
|
||||||
|
fm->last_click_item = idx;
|
||||||
|
fm->last_click_time = now;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void filemanager_on_mouse(Window* win, MouseEvent& ev) {
|
void filemanager_on_mouse(Window* win, MouseEvent& ev) {
|
||||||
@@ -290,9 +292,11 @@ void filemanager_on_mouse(Window* win, MouseEvent& ev) {
|
|||||||
if (in_view) {
|
if (in_view) {
|
||||||
int clicked_idx = entry_at(local_x, local_y);
|
int clicked_idx = entry_at(local_x, local_y);
|
||||||
if (clicked_idx >= 0) {
|
if (clicked_idx >= 0) {
|
||||||
filemanager_click_entry(fm, clicked_idx);
|
// A press on a selected entry may turn into a drag, unless it
|
||||||
// A press on a selected entry may turn into a drag.
|
// opened the entry: the opened app takes focus, so we would
|
||||||
if (filemanager_is_entry_selected(fm, clicked_idx)) {
|
// never see the release.
|
||||||
|
bool opened = filemanager_click_entry(fm, clicked_idx);
|
||||||
|
if (!opened && filemanager_is_entry_selected(fm, clicked_idx)) {
|
||||||
fm->press_idx = clicked_idx;
|
fm->press_idx = clicked_idx;
|
||||||
fm->press_x = local_x;
|
fm->press_x = local_x;
|
||||||
fm->press_y = local_y;
|
fm->press_y = local_y;
|
||||||
|
|||||||
Reference in new issue
Block a user