Commit: d0b56d0ef05ffacb89c5439d55d5cac2ee29d328
Parent: 9f07a3c8ab0721beb511b6f28186481a901cfdce
Author: Randy Palamar
Date: Fri, 23 Aug 2024 22:31:59 -0600
allow selection to scroll with framebuffer
Diffstat:
2 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/terminal.c b/terminal.c
@@ -116,6 +116,33 @@ feed_line(LineBuf *lb, u8 *position, CellStyle cursor_state)
}
static void
+selection_clear(Selection *s)
+{
+ s->range.end = INVALID_RANGE_END;
+ s->state = SS_NONE;
+}
+
+static void
+selection_scroll(Term *t, u32 origin, i32 n)
+{
+ Selection *s = &t->selection;
+ if (!is_valid_range(s->range))
+ return;
+
+ b32 start_in_bounds = BETWEEN(s->range.start.y, origin, t->size.h - 1);
+ b32 end_in_bounds = BETWEEN(s->range.end.y, origin, t->size.h - 1);
+ if (start_in_bounds != end_in_bounds) {
+ selection_clear(s);
+ } else if (start_in_bounds) {
+ s->range.start.y += n;
+ s->range.end.y += n;
+ if (s->range.start.y > t->size.h - 1 || s->range.start.y < 0 ||
+ s->range.end.y > t->size.h - 1 || s->range.end.y < 0)
+ selection_clear(s);
+ }
+}
+
+static void
fb_clear_region(Term *t, u32 r1, u32 r2, u32 c1, u32 c2)
{
u32 tmp;
@@ -155,6 +182,7 @@ fb_scroll_down(Term *t, u32 top, u32 n)
tv->fb.rows[i] = tv->fb.rows[i - n];
tv->fb.rows[i - n] = tmp;
}
+ selection_scroll(t, top, n);
}
static void
@@ -169,6 +197,7 @@ fb_scroll_up(Term *t, u32 top, u32 n)
tv->fb.rows[i] = tv->fb.rows[i + n];
tv->fb.rows[i + n] = tmp;
}
+ selection_scroll(t, top, -n);
}
static void
diff --git a/vtgl.c b/vtgl.c
@@ -699,6 +699,7 @@ init_term(Term *t, Arena *a)
cursor_move_to(t, 0, 0);
cursor_alt(t, 1);
}
+ selection_clear(&t->selection);
}
DEBUG_EXPORT void