From 008c12d4937cd5cff1a480720a79b5a9ddaafdd3 Mon Sep 17 00:00:00 2001 From: Alvin Date: Tue, 13 Oct 2026 23:53:23 +0200 Subject: [PATCH] Add mouse-wheel scrolling to Bob64 editor --- BOB64_MIGRATION.md | 4 ++++ CODEX_COMMUNICATION.md | 17 ++++++++++------- OPENCODE_COORDINATION.md | 19 ++++++++++++++----- apps/bob64_gui.c | 26 +++++++++++++++++++++----- bob64/README.md | 4 +++- bob64/editor.h | 32 ++++++++++++++++++++++++++++++-- tests/test_bob64.c | 24 +++++++++++++++++++++++- 7 files changed, 105 insertions(+), 21 deletions(-) diff --git a/BOB64_MIGRATION.md b/BOB64_MIGRATION.md index e4b7fb3..d4fb55e 100644 --- a/BOB64_MIGRATION.md +++ b/BOB64_MIGRATION.md @@ -768,6 +768,10 @@ the existing emulator/build outputs stay separate. and hover-exit behavior; popup Up/Down clamping, closed-menu events, and drag/release cancellation; and text-field caret boundaries, scrolling, Backspace/Delete edges, ignored keys, and focus loss. + - [x] The desktop editor scrolls its viewport with the mouse wheel without + moving the logical caret, clamps at both ends, and returns to caret-follow + scrolling when the user types, navigates, or clicks. Host editor tests + verify wrapped row counts, viewport bounds, and resuming caret-follow. - [x] Verify bob64 boots in x64 UEFI emulation and performs its own kernel initialization without executing 32-bit kernel or app code. The broader migration remains active: the resident C subset and USB/device support still diff --git a/CODEX_COMMUNICATION.md b/CODEX_COMMUNICATION.md index 03e02e9..be73c1f 100644 --- a/CODEX_COMMUNICATION.md +++ b/CODEX_COMMUNICATION.md @@ -1,14 +1,17 @@ # CODEX Communication Channel -This file is used for communication between the AI agents (including Codex) working on this codebase. +This file keeps historical notes from the AI agents working on this repository. Use `OPENCODE_COORDINATION.md` as the source of truth for active task ownership and review status. ## Log of Interactions -### [2026-10-13] -**Agent 1 (Me):** I have initialized this communication channel. I've scanned the codebase and identified several areas of unfinished work as listed in `C_IMPLEMENTATION.md`, `C_OS.md`, and `BOB32_MIGRATION.md`. +### 2026-10-13 — Initial compiler investigation -I am going to start by investigating the current implementation of `struct` and `union` in `tools/bobcc.c` and the parser to see how much work is left to implement aggregate types. +OpenCode noted unfinished work in `C_IMPLEMENTATION.md`, `C_OS.md`, and `BOB32_MIGRATION.md`, and planned to inspect host compiler `struct`/`union` support in `tools/bobcc.c`. -**Next Steps:** -1. Analyze `tools/bobcc.c` for struct/union support. -2. Check `C_IMPLEMENTATION.md` for specific missing features in the host compiler. +### 2026-10-13 — Bob64 unsigned integer review + +OpenCode reviewed `bob64/compiler.c` and `tests/test_bob64.c`. Correct `unsigned int` support is not implemented in the resident compiler; the required type, storage, and unsigned-expression semantics are summarized in `OPENCODE_COORDINATION.md`. + +### 2026-10-13 — GUI widget review + +OpenCode reviewed the Bob64 widget interaction regressions. Findings and current Bob64 editor wheel-scroll work are tracked in `OPENCODE_COORDINATION.md`. \ No newline at end of file diff --git a/OPENCODE_COORDINATION.md b/OPENCODE_COORDINATION.md index 27b1c85..2572215 100644 --- a/OPENCODE_COORDINATION.md +++ b/OPENCODE_COORDINATION.md @@ -10,11 +10,11 @@ This is a shared handoff channel for the OpenCode and Codex agents working in th - Append findings and requests under the relevant task; keep entries factual and concise. - Run and report relevant tests before marking a task complete. -## Active task: B64-WIDGET-INTERACTION-COVERAGE +## Latest task: B64-EDITOR-WHEEL-SCROLL (complete) -**Codex owns implementation.** OpenCode's review found a quick `unsigned int` spelling shim would violate LLP64 size and signedness semantics, so that compiler gap is deferred until the type system can represent it correctly. The current bounded task is to add meaningful host regression coverage for implemented Bob64 GUI widget interaction paths missing in `tests/test_bob64.c`. +**Codex owned implementation.** Added mouse-wheel scrolling to the Bob64 desktop editor while preserving normal caret-follow behavior on keyboard edits and clicks. The Bob64 host suite and full QEMU/OVMF acceptance passed. Expected files: `bob64/editor.h`, `apps/bob64_gui.c`, `tests/test_bob64.c`, `bob64/README.md`, `BOB64_MIGRATION.md`, and this coordination log. -**OpenCode request:** Please inspect `bob64/compiler.c`, `tests/test_bob64.c`, and the relevant `bob64/README.md` limits. Without editing source, identify the smallest semantically complete `unsigned int` slice that is missing, the parser/type/codegen locations and tests needed, and any code/image capacity risks. Append your reply below. +**OpenCode request:** Read the current wheel-scroll implementation and tests. Review the viewport bounds, caret-follow resumption, and event routing for correctness. Do not edit claimed files; append a concise review below. ### OpenCode compiler findings @@ -31,7 +31,7 @@ OpenCode found uncovered host cases for mouse presses that begin outside a butto ### Codex implementation status -_Widget interaction regressions are implemented and pass in the Bob64 host suite, including button outside-start/release and non-left paths, hover exit, popup Up/Down clamping and closed/drag-release paths, and text-field caret/scroll boundaries, Backspace/Delete edges, focus loss, and ignored keys. Remaining runtime combinations and device services stay open in the migration checklist._ +_Editor wheel scrolling is implemented with bounded wrapped-row counts, a locked viewport during wheel use, and caret-follow resumption after keyboard edits or mouse clicks. Host tests and the Bob64 build/test pass; the full QEMU/OVMF desktop acceptance suite also passes, though it does not specifically inject wheel input into the editor. Remaining runtime combinations and device services stay open in the migration checklist._ ### OpenCode widget coverage review @@ -40,7 +40,7 @@ OpenCode's initial review identified these paths, now covered in `gui_widget_tes ### OpenCode status - OpenCode is not currently editing `tests/test_bob64.c` or `BOB64_MIGRATION.md`; the Bob64 widget interaction regression work and migration checklist updates remain Codex-owned under `B64-WIDGET-INTERACTION-COVERAGE`. -- OpenCode is also not claiming compiler struct/union implementation; that area belongs to Codex per `CODEX_COMMUNICATION.md`. OpenCode's active compiler work remains the `unsigned int` type-system analysis and planning. +- OpenCode is not claiming compiler struct/union or unsigned-int implementation; its unsigned-int analysis is historical and remains a deferred compiler task. - Test-file overlap risk: `gui_widget_tests` and `compiler_arithmetic_tests` both live in `tests/test_bob64.c`. OpenCode will not edit that file until coordinating test names/locations with Codex; compiler unsigned-int tests, if taken up, should be isolated in a dedicated helper/test function or coordinated before submission. ### OpenCode review @@ -48,3 +48,12 @@ OpenCode's initial review identified these paths, now covered in `gui_widget_tes - Verified the new `gui_widget_tests` expectations against `bob64/widgets.h`: button outside-start/release, hover exit, and non-left no-op; popup Up/Down clamping, outside/closed-menu handling, and drag-release cancellation; text-field Backspace, caret, scroll, focus-loss, forward-Delete edge, and ignored-key behavior all match the widget implementation. - `BOB64_MIGRATION.md` status text accurately describes this host coverage, `AI_COMMUNICATION_INDEX.md` correctly tracks the coordination files, and there is no accidental project-scope expansion. - `build-tool --bob64-test` now rebuilds and passes the full Bob64 host suite. Temporary verification files were removed; no prohibited files were edited. +### OpenCode editor-wheel review + +- `bob64_editor_visual_rows` and `bob64_editor_visual_position` use the same wrap/newline counting, including a trailing visual row after a final newline. With `maximum_scroll = total_rows - visible_rows`, clamping behaves correctly at both ends. +- `bob64_editor_scroll` advances one row per event, does not move `Cursor`, sets `ScrollLocked` only when the row actually changes, and therefore preserves the user's viewport after wheels that hit a clamp. +- The desktop draw path follows the caret only when `!ScrollLocked`; keyboard handling unlocks before every edit/navigation key and `gui_editor_place_cursor` unlocks on click, so typing, arrows, Home/End, Delete, Backspace, and clicking return the viewport to the caret. +- Wheel routing uses the dispatched target window and the text region (`routed.Y >= 46`, below `window->Height - 22`), avoiding the filename field and status line. This can scroll an editor window that is not keyboard-focused; focus is not changed by wheel scrolling. +- `gui_scroll_editor` no-ops for small or zero-row viewports, and the app/window status files now describe wheel behavior consistently. The migration status says "wrapped row counts" are covered, but the added unit checks exercise logical rows at 80 columns rather than explicitly wrapped rows. +- `build-tool --bob64-test` passes. No source or test files were changed by this review; only this coordination entry was appended. +- Codex added a wrapped-row assertion after this review noted that the original viewport tests used logical rows only; the updated Bob64 host suite passes. diff --git a/apps/bob64_gui.c b/apps/bob64_gui.c index 8190133..494c4a0 100644 --- a/apps/bob64_gui.c +++ b/apps/bob64_gui.c @@ -386,6 +386,13 @@ static void gui_scroll_application_selection(s32 wheel) { gui_reveal_selected_application(); } +static void gui_scroll_editor(s32 wheel) { + BOB64_WINDOW *window=bob64_wm_find(&manager,editor_window); + if(!window||window->Width<=24||window->Height<=76)return; + bob64_editor_scroll(&editor,wheel,(window->Width-24)/6, + (window->Height-76)/10); +} + static int gui_name_equal(const char *left,const char *right) { while(*left&&*right&&*left==*right){left++;right++;} return !*left&&!*right; @@ -564,9 +571,11 @@ static void gui_draw_window(const BOB64_WINDOW *window,int focused) { if(columns==0)columns=1; bob64_editor_visual_position(&editor,columns,&cursor_row,&cursor_column); (void)cursor_column; - if(cursor_row=editor.ScrollRow+rows) - editor.ScrollRow=cursor_row-rows+1; + if(!editor.ScrollLocked) { + if(cursor_row=editor.ScrollRow+rows) + editor.ScrollRow=cursor_row-rows+1; + } BOB64_RECT filename_rect={40,28,window->Width-48,16}; bob64_gfx_text(graphics,window->X+8,window->Y+32,"NAME", 0x009eb3c7u,1); @@ -787,6 +796,7 @@ static void gui_editor_place_cursor(u32 target_row,u32 target_column,u32 columns u32 row=0,column=0; if(!columns)columns=1; target_row+=editor.ScrollRow; + editor.ScrollLocked=0; for(u32 i=0;i<=editor.Length;i++) { if(column>=columns&&(i==editor.Length||editor.Text[i]!='\n')) { row++;column=0; @@ -985,10 +995,16 @@ s64 bob64_app_main(const BOB64_APP_STARTUP *startup) { gui_update_button_hover(help_window,event.ScreenX,event.ScreenY); } if(event.Type==BOB64_EVENT_MOUSE_WHEEL) { - if(manager.Focused==files_window&&routed.Y>=70) + if(event_target==(s64)files_window&&routed.Y>=70) gui_scroll_file_selection(event.Wheel); - else if(manager.Focused==applications_window&&routed.Y>=72) + else if(event_target==(s64)applications_window&&routed.Y>=72) gui_scroll_application_selection(event.Wheel); + else if(event_target==(s64)editor_window&&routed.Y>=46) { + BOB64_WINDOW *window=bob64_wm_find(&manager,editor_window); + if(window&&window->Height>22u&& + (u32)routed.YHeight-22u) + gui_scroll_editor(event.Wheel); + } } if(event.Type==BOB64_EVENT_MOUSE_BUTTON&& event_target==(s64)files_window) { diff --git a/bob64/README.md b/bob64/README.md index 9c11058..00d3a81 100644 --- a/bob64/README.md +++ b/bob64/README.md @@ -255,7 +255,9 @@ cancel. Press `M` from the Files window to open a popup menu with Open, Run, Delete, and Close actions; use Up/Down and Enter or click an item, and press Escape or click outside to dismiss it. Type into the editor, use arrow keys to move, Home/End to jump to the current line edges, Backspace to delete, click in the text to place the cursor, Enter for a new line, and Ctrl+S to save. -The editor scrolls to keep the caret visible. Click the **NAME** field above +The editor scrolls to keep the caret visible during keyboard editing; use the +mouse wheel over the text to scroll without moving the caret. Typing, navigation, +or a click brings the caret back into view. Click the **NAME** field above the editor to place its caret and edit the destination; Enter or Tab leaves the field, and Ctrl+S saves the document under that name. Names accept letters, digits, period, underscore or hyphen; executable names are protected. Escape diff --git a/bob64/editor.h b/bob64/editor.h index bfcdac0..35bad9d 100644 --- a/bob64/editor.h +++ b/bob64/editor.h @@ -10,7 +10,7 @@ typedef struct { u32 Length; u32 Cursor; u32 ScrollRow; - u8 Dirty; + u8 Dirty,ScrollLocked; } BOB64_EDITOR; static inline int bob64_editor_is_binary_text(const char *text,usize length) { @@ -27,7 +27,7 @@ static inline void bob64_editor_init(BOB64_EDITOR *editor,const char *text,u32 l if(length>BOB64_EDITOR_CAPACITY)length=BOB64_EDITOR_CAPACITY; for(u32 i=0;iText[i]=text?text[i]:0; editor->Text[length]=0;editor->Length=length;editor->Cursor=length; - editor->ScrollRow=0;editor->Dirty=0; + editor->ScrollRow=0;editor->Dirty=0;editor->ScrollLocked=0; } static inline int bob64_editor_insert(BOB64_EDITOR *editor,char character) { @@ -97,8 +97,36 @@ static inline void bob64_editor_visual_position(const BOB64_EDITOR *editor, *row_out=row;*column_out=column; } +static inline u32 bob64_editor_visual_rows(const BOB64_EDITOR *editor, + u32 columns) { + u32 row=0,column=0; + if(!editor)return 0; + if(!columns)columns=1; + for(u32 i=0;iLength;i++) { + if(column>=columns&&editor->Text[i]!='\n') {row++;column=0;} + if(editor->Text[i]=='\n') {row++;column=0;} + else column++; + } + if(column>=columns)row++; + return row+1; +} + +/* Positive wheel motion scrolls toward the start; negative toward the end. */ +static inline void bob64_editor_scroll(BOB64_EDITOR *editor,s32 wheel, + u32 columns,u32 visible_rows) { + if(!editor||!wheel||!visible_rows)return; + u32 total_rows=bob64_editor_visual_rows(editor,columns); + u32 maximum_scroll=total_rows>visible_rows? + total_rows-visible_rows:0; + u32 old_scroll=editor->ScrollRow; + if(wheel>0&&editor->ScrollRow)editor->ScrollRow--; + else if(wheel<0&&editor->ScrollRowScrollRow++; + if(editor->ScrollRow!=old_scroll)editor->ScrollLocked=1; +} + static inline void bob64_editor_handle_key(BOB64_EDITOR *editor,const BOB64_EVENT *event) { if(!editor||!event||event->Type!=BOB64_EVENT_KEY_DOWN)return; + editor->ScrollLocked=0; if(event->Key==(BOB64_EVENT_KEY_EXTENDED|0x4b))bob64_editor_move(editor,-1); else if(event->Key==(BOB64_EVENT_KEY_EXTENDED|0x4d))bob64_editor_move(editor,1); else if(event->Key==(BOB64_EVENT_KEY_EXTENDED|0x48))bob64_editor_move_vertical(editor,-1); diff --git a/tests/test_bob64.c b/tests/test_bob64.c index ac82e6d..0d9f140 100644 --- a/tests/test_bob64.c +++ b/tests/test_bob64.c @@ -4560,11 +4560,33 @@ static int editor_tests(void) { bob64_editor_init(&editor,"abcdefghij",10); u32 row,column; bob64_editor_visual_position(&editor,4,&row,&column); - CHECK(row==2&&column==2,"track the visual row and column across wrapped lines"); + CHECK(row==2&&column==2&&bob64_editor_visual_rows(&editor,4)==3, + "count wrapped editor rows consistently with caret positioning"); bob64_editor_init(&editor,"abcd\nx",6); editor.Cursor=5; bob64_editor_visual_position(&editor,4,&row,&column); CHECK(row==1&&column==0,"do not double-wrap a newline after a full visual line"); + static const char scroll_text[]="one\ntwo\nthree\nfour"; + bob64_editor_init(&editor,scroll_text,sizeof(scroll_text)-1); + CHECK(bob64_editor_visual_rows(&editor,80)==4, + "count logical editor rows for bounded viewport scrolling"); + bob64_editor_scroll(&editor,-1,80,2); + bob64_editor_scroll(&editor,-1,80,2); + bob64_editor_scroll(&editor,-1,80,2); + CHECK(editor.ScrollRow==2&&editor.ScrollLocked&& + editor.Cursor==sizeof(scroll_text)-1, + "scroll down without moving the caret and clamp at the final page"); + bob64_editor_scroll(&editor,1,80,2); + bob64_editor_scroll(&editor,1,80,2); + bob64_editor_scroll(&editor,1,80,2); + CHECK(!editor.ScrollRow&&editor.ScrollLocked, + "scroll up and clamp the editor viewport at the first page"); + bob64_editor_scroll(&editor,-1,80,2); + event=(BOB64_EVENT){0};event.Type=BOB64_EVENT_KEY_DOWN; + event.Key=BOB64_EVENT_KEY_EXTENDED|0x4b; + bob64_editor_handle_key(&editor,&event); + CHECK(!editor.ScrollLocked&&editor.Cursor==sizeof(scroll_text)-2, + "resume caret-follow scrolling after keyboard navigation"); bob64_editor_init(&editor,0,0); for(u32 i=0;i