Commit: 4c5dbf0d04ad4f9c38566da51daaa4096d91495e
Parent: d0b56d0ef05ffacb89c5439d55d5cac2ee29d328
Author: Randy Palamar
Date: Fri, 23 Aug 2024 22:46:17 -0600
properly clear the selection
This should happen when the selection scrolls out of view (covered
before) and when the cursor collides while inserting cells into
the framebuffer (new).
Diffstat:
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/terminal.c b/terminal.c
@@ -142,6 +142,18 @@ selection_scroll(Term *t, u32 origin, i32 n)
}
}
+static b32
+is_selected(Selection *s, i32 x, i32 y)
+{
+ if (!is_valid_range(s->range))
+ return 0;
+
+ b32 result = BETWEEN(y, s->range.start.y, s->range.end.y) &&
+ (y != s->range.start.y || x >= s->range.start.x) &&
+ (y != s->range.end.y || x <= s->range.end.x);
+ return result;
+}
+
static void
fb_clear_region(Term *t, u32 r1, u32 r2, u32 c1, u32 c2)
{
@@ -166,6 +178,8 @@ fb_clear_region(Term *t, u32 r1, u32 r2, u32 c1, u32 c2)
for (u32 c = c1; c <= c2; c++) {
tv->fb.rows[r][c].style = t->cursor.state;
tv->fb.rows[r][c].cp = ' ';
+ if (is_selected(&t->selection, c, r))
+ selection_clear(&t->selection);
}
}
}
@@ -982,6 +996,8 @@ push_line(Term *t, Line *line, Arena a)
if (!wrap_next)
cursor_step_column(t, 1);
}
+ if (is_selected(&t->selection, t->cursor.pos.x, t->cursor.pos.y))
+ selection_clear(&t->selection);
}
if (wrap_next && (t->cursor.pos.y != t->size.h - 1))
cursor_step_column(t, 1);
diff --git a/vtgl.c b/vtgl.c
@@ -660,7 +660,6 @@ char_callback(GLFWwindow *win, u32 codepoint)
t->scroll_offset = 0;
t->gl.flags |= NEEDS_FULL_BLIT;
}
- t->selection.range.end = INVALID_RANGE_END;
os_child_put_char(t->child, codepoint);
}