From 6cf973195953fcc6e79c9ade928fdf3069d84127 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Thu, 1 Jan 2026 13:48:21 +0100 Subject: [PATCH] Wheel scrolling --- src/backup/todo.txt | 1 - src/text_editor/globals.cpp | 1 + src/text_editor/text_editor.cpp | 21 +++++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/backup/todo.txt b/src/backup/todo.txt index 60ffb5a..0d51cae 100644 --- a/src/backup/todo.txt +++ b/src/backup/todo.txt @@ -2,7 +2,6 @@ ! From a user (novice) point of view, how does it look like? - Make a fuzzy command !> grep and fuzzy over it??? (doesn't seem very useful for grep) -- Maybe wheel click should scroll??? PROBABLY - Make all the keybinding / hook parsing initialize at the start to reduce runtime problems - RegisterCommand should_appear_in_listing variable diff --git a/src/text_editor/globals.cpp b/src/text_editor/globals.cpp index 6f021ba..94365d7 100644 --- a/src/text_editor/globals.cpp +++ b/src/text_editor/globals.cpp @@ -44,6 +44,7 @@ WindowID DocumentSelected = {-1}; WindowID ResizerSelected = {-1}; WindowID ResizerHover = {-1}; Caret DocumentAnchor; +Vec2I MouseMiddleAnchor; Buffer *GCInfoBuffer; Buffer *EventBuffer; diff --git a/src/text_editor/text_editor.cpp b/src/text_editor/text_editor.cpp index 84e2569..4a4e7e3 100644 --- a/src/text_editor/text_editor.cpp +++ b/src/text_editor/text_editor.cpp @@ -58,6 +58,8 @@ void SetMouseCursor(SDL_SystemCursor id) { JS_SetMouseCursor("default"); } else if (id == SDL_SYSTEM_CURSOR_TEXT) { JS_SetMouseCursor("text"); + } else if (id == SDL_SYSTEM_CURSOR_MOVE) { + JS_SetMouseCursor("all-scroll"); } else { InvalidCodepath(); } @@ -104,6 +106,11 @@ void SetMouseCursor(Event event) { return; } + if (MouseMiddleAnchor.x != 0 && MouseMiddleAnchor.y != 0) { + SetMouseCursor(SDL_SYSTEM_CURSOR_MOVE); + return; + } + For(order) { if (!it->visible) continue; bool mouse_in_total = AreOverlapping(mouse, it->total_rect); @@ -315,6 +322,20 @@ void OnCommand(Event event) { MouseLoadWord(event); } + { + Vec2I mouse = MouseVec2I(); + if (Mouse(MIDDLE)) { + MouseMiddleAnchor = mouse; + } else if (Mouse(MIDDLE_UP)) { + MouseMiddleAnchor = {0, 0}; + } + if (MouseMiddleAnchor.x != 0) { + BSet active = GetBSet(ActiveWindowID); + active.view->scroll += mouse - MouseMiddleAnchor; + } + } + + if (Ctrl() && Mouse(LEFT)) { MouseLoadWord(event); } else if (Mouse(LEFT)) { // Uses Alt and shift