Mouse rewrite

This commit is contained in:
Krzosa Karol
2024-08-04 14:14:15 +02:00
parent 605f3aa68d
commit d59a8d9c8b
2 changed files with 22 additions and 1 deletions

View File

@@ -203,6 +203,9 @@ bool GlobalCommand(Event event) {
Assert(DocumentSelected == NULL);
ScrollbarSelected = NULL;
} else if (ScrollbarSelected) {
// :ScrollbarImprovement
// @todo: it generally works ok but it moves the scrollbar a bit on click
// when mouse is not even moving
Assert(DocumentSelected == NULL);
Window *window = ScrollbarSelected;
View *view = GetView(window->active_view);
@@ -227,7 +230,18 @@ bool GlobalCommand(Event event) {
View *view = GetView(window->active_view);
Buffer *buffer = GetBuffer(view->active_buffer);
Vec2I mouse = MouseVec2I();
Vec2I mouse = MouseVec2I();
// Special case for full-screen where we can have document
// aligned with monitor screen in which case mouse cursor cannot
// be smaller then 0 which means we cannot scroll
if (mouse.y == 0 && window->document_rect.min.y == 0) {
float x, y;
SDL_GetGlobalMouseState(&x, &y);
if (y == 0) {
mouse.y = -10;
}
}
Int p = ScreenSpaceToBufferPos(window, view, buffer, mouse);
Caret &caret = view->carets[0];
@@ -310,6 +324,7 @@ bool GlobalCommand(Event event) {
}
// Figure out scrollbar click
// :ScrollbarImprovement
// @todo: it generally works ok but it moves the scrollbar a bit on click
// when mouse is not even moving
For(order) {

View File

@@ -828,6 +828,12 @@ void WindowCommand(Event event, Window *window, View *view) {
Assert(view->underline_count <= 2);
}
}
if (Mouse(MIDDLE)) {
Vec2I mouse = MouseVec2I();
Int p = ScreenSpaceToBufferPos(window, view, buffer, mouse);
Insert(&view->carets, MakeCaret(p, p), 0);
}
}
void UpdateScroll(Window *window, bool update_caret_scrolling) {