fix: fix Files double-click bug

This commit is contained in:
daniel committed 2026-10-24 13:34:36 +02:00
1 parent 8de98f3ab3
commit 8ae19258b1
3 files changed
+21 -10

No files matched your search

+7
View File
@@ -73,6 +73,13 @@ bool filemanager_dnd_mouse(Window* win, FileManagerState* fm, const FileManagerL
}
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 dy = y - fm->press_y;
if (dx * dx + dy * dy < DRAG_THRESHOLD * DRAG_THRESHOLD) return true;
+13 -9
View File
@@ -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
// anchor (Ctrl+Shift adds that range); a plain click selects it alone, and a
// 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;
bool ctrl = ds && ds->kbd_ctrl_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);
fm->last_click_item = -1;
fm->last_click_time = 0;
return;
return false;
}
uint64_t now = montauk::get_milliseconds();
@@ -46,11 +47,12 @@ static void filemanager_click_entry(FileManagerState* fm, int idx) {
filemanager_open_entry(fm, idx);
fm->last_click_item = -1;
fm->last_click_time = 0;
} else {
filemanager_select_single(fm, idx);
fm->last_click_item = idx;
fm->last_click_time = now;
return true;
}
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) {
@@ -290,9 +292,11 @@ void filemanager_on_mouse(Window* win, MouseEvent& ev) {
if (in_view) {
int clicked_idx = entry_at(local_x, local_y);
if (clicked_idx >= 0) {
filemanager_click_entry(fm, clicked_idx);
// A press on a selected entry may turn into a drag.
if (filemanager_is_entry_selected(fm, clicked_idx)) {
// A press on a selected entry may turn into a drag, unless it
// opened the entry: the opened app takes focus, so we would
// 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_x = local_x;
fm->press_y = local_y;