Commit: 571cbe49d74876c0b3fdd6142f2553613144871f
Parent: 577391eb0ca7e74244de3caa3e6344b9acfbf161
Author: Randy Palamar
Date: Thu, 22 Aug 2024 08:06:11 -0600
give a name to invalid selection point
Diffstat:
3 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/util.c b/util.c
@@ -3,6 +3,13 @@
#include <stdio.h>
#include <stdlib.h>
+static b32
+equal_iv2(iv2 a, iv2 b)
+{
+ b32 result = a.x == b.x && a.y == b.y;
+ return result;
+}
+
static void __attribute__((noreturn))
die(char *fmt, ...)
{
diff --git a/util.h b/util.h
@@ -292,6 +292,7 @@ typedef struct {
f32 click_param;
enum selection_states state;
} Selection;
+#define INVALID_SELECTION_POINT (iv2){.x = -1, .y = -1}
enum terminal_mode {
TM_ALTSCREEN = 1 << 0,
diff --git a/vtgl.c b/vtgl.c
@@ -342,7 +342,7 @@ render_framebuffer(Term *t, RenderPushBuffer *rpb)
/* NOTE: draw selection if active */
/* TODO: combine with original push_cell? */
- if (t->selection.end.x != -1) {
+ if (!equal_iv2(t->selection.end, INVALID_SELECTION_POINT)) {
iv2 curs = t->selection.start;
Rect cr = {
.pos = {.x = tl.x + cs.w * curs.x, .y = tl.h - cs.h * (curs.y + 1)},
@@ -415,7 +415,7 @@ update_selection(Term *t)
/* TODO: word selection */
} else {
if (newp.x <= sel->start.x && newp.y <= sel->start.y) {
- if (sel->end.x == -1)
+ if (equal_iv2(t->selection.end, INVALID_SELECTION_POINT))
sel->end = sel->start;
sel->start = newp;
} else {
@@ -426,7 +426,7 @@ update_selection(Term *t)
KEYBIND_FN(copy)
{
- if (t->selection.end.x == -1)
+ if (equal_iv2(t->selection.end, INVALID_SELECTION_POINT))
return 1;
TermView *tv = t->views + t->view_idx;
@@ -643,7 +643,7 @@ char_callback(GLFWwindow *win, u32 codepoint)
t->scroll_offset = 0;
t->gl.flags |= NEEDS_FULL_BLIT;
}
- t->selection.end = (iv2){.x = -1, .y = -1};
+ t->selection.end = INVALID_SELECTION_POINT;
os_child_put_char(t->child, codepoint);
}