fix: make Files lists scroll with arrow keys
This commit is contained in:
@@ -12,4 +12,4 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define MONTAUK_BUILD_NUMBER 178
|
#define MONTAUK_BUILD_NUMBER 179
|
||||||
|
|||||||
@@ -319,6 +319,27 @@ void filemanager_on_mouse(Window* win, MouseEvent& ev) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Keep the selected row inside the visible list area so arrow-key navigation
|
||||||
|
// scrolls the view along with the selection.
|
||||||
|
static void filemanager_scroll_to_selected(Window* win, FileManagerState* fm) {
|
||||||
|
if (fm->grid_view) return;
|
||||||
|
if (fm->selected < 0 || fm->selected >= fm->entry_count) return;
|
||||||
|
|
||||||
|
int list_y = FM_TOOLBAR_H + FM_PATHBAR_H + FM_HEADER_H;
|
||||||
|
int list_h = win->content_h - list_y;
|
||||||
|
if (list_h <= 0) return;
|
||||||
|
|
||||||
|
int top = fm->selected * FM_ITEM_H;
|
||||||
|
int off = fm->scrollbar.scroll_offset;
|
||||||
|
if (top < off) off = top;
|
||||||
|
else if (top + FM_ITEM_H > off + list_h) off = top + FM_ITEM_H - list_h;
|
||||||
|
|
||||||
|
int max_scroll = fm->entry_count * FM_ITEM_H - list_h;
|
||||||
|
if (off > max_scroll) off = max_scroll;
|
||||||
|
if (off < 0) off = 0;
|
||||||
|
fm->scrollbar.scroll_offset = off;
|
||||||
|
}
|
||||||
|
|
||||||
void filemanager_on_key(Window* win, const montauk::abi::KeyEvent& key) {
|
void filemanager_on_key(Window* win, const montauk::abi::KeyEvent& key) {
|
||||||
FileManagerState* fm = (FileManagerState*)win->app_data;
|
FileManagerState* fm = (FileManagerState*)win->app_data;
|
||||||
if (!fm || !key.pressed) return;
|
if (!fm || !key.pressed) return;
|
||||||
@@ -455,6 +476,7 @@ void filemanager_on_key(Window* win, const montauk::abi::KeyEvent& key) {
|
|||||||
} else {
|
} else {
|
||||||
if (fm->selected > 0) fm->selected--;
|
if (fm->selected > 0) fm->selected--;
|
||||||
}
|
}
|
||||||
|
filemanager_scroll_to_selected(win, fm);
|
||||||
} else if (key.scancode == 0x50) {
|
} else if (key.scancode == 0x50) {
|
||||||
// Down arrow
|
// Down arrow
|
||||||
if (fm->grid_view) {
|
if (fm->grid_view) {
|
||||||
@@ -465,6 +487,7 @@ void filemanager_on_key(Window* win, const montauk::abi::KeyEvent& key) {
|
|||||||
} else {
|
} else {
|
||||||
if (fm->selected < fm->entry_count - 1) fm->selected++;
|
if (fm->selected < fm->entry_count - 1) fm->selected++;
|
||||||
}
|
}
|
||||||
|
filemanager_scroll_to_selected(win, fm);
|
||||||
} else if (key.scancode == 0x4B && !key.alt && fm->grid_view) {
|
} else if (key.scancode == 0x4B && !key.alt && fm->grid_view) {
|
||||||
// Left arrow (grid view only)
|
// Left arrow (grid view only)
|
||||||
if (fm->selected > 0) fm->selected--;
|
if (fm->selected > 0) fm->selected--;
|
||||||
|
|||||||
Reference in New Issue
Block a user