summaryrefslogtreecommitdiff
path: root/buffer.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-30 23:00:20 -0500
committerpommicket <pommicket@gmail.com>2022-12-30 23:00:20 -0500
commit43bd0763959ecd8f8a835d09190b55ba6fab7d67 (patch)
treea79dae99561a26f5c6ba50e5423111f7ff52fb78 /buffer.c
parent74ca500fcad9f6f1ee2d43498b92beee92112fb0 (diff)
clip highlight to buffer rect
Diffstat (limited to 'buffer.c')
-rw-r--r--buffer.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/buffer.c b/buffer.c
index 13d3310..9b25538 100644
--- a/buffer.c
+++ b/buffer.c
@@ -3019,3 +3019,46 @@ void buffer_toggle_comment_selection(TextBuffer *buffer) {
}
buffer_toggle_comment_lines(buffer, l1, l2);
}
+
+
+// make sure to call gl_geometry_draw after this
+void buffer_highlight_lsp_range(TextBuffer *buffer, LSPRange range) {
+ Font *font = buffer_font(buffer);
+ const u32 *colors = buffer_settings(buffer)->colors;
+ float char_height = font->char_height;
+ BufferPos range_start = buffer_pos_from_lsp(buffer, range.start);
+ BufferPos range_end = buffer_pos_from_lsp(buffer, range.end);
+ // draw the highlight
+ if (range_start.line == range_end.line) {
+ v2 a = buffer_pos_to_pixels(buffer, range_start);
+ v2 b = buffer_pos_to_pixels(buffer, range_end);
+ b.y += char_height;
+ Rect r = rect_endpoints(a, b); buffer_clip_rect(buffer, &r);
+ gl_geometry_rect(r, colors[COLOR_HOVER_HL]);
+ } else if (range_end.line - range_start.line < 1000) { // prevent gigantic highlights from slowing things down
+ // multiple lines.
+ v2 a = buffer_pos_to_pixels(buffer, range_start);
+ v2 b = buffer_pos_to_pixels(buffer, buffer_pos_end_of_line(buffer, range_start.line));
+ b.y += char_height;
+ Rect r1 = rect_endpoints(a, b); buffer_clip_rect(buffer, &r1);
+ gl_geometry_rect(r1, colors[COLOR_HOVER_HL]);
+
+ for (u32 line = range_start.line + 1; line < range_end.line; ++line) {
+ // these lines are fully contained in the range.
+ BufferPos start = buffer_pos_start_of_line(buffer, line);
+ BufferPos end = buffer_pos_end_of_line(buffer, line);
+ a = buffer_pos_to_pixels(buffer, start);
+ b = buffer_pos_to_pixels(buffer, end);
+ b.y += char_height;
+ Rect r = rect_endpoints(a, b); buffer_clip_rect(buffer, &r);
+ gl_geometry_rect(r, colors[COLOR_HOVER_HL]);
+ }
+
+ // last line
+ a = buffer_pos_to_pixels(buffer, buffer_pos_start_of_line(buffer, range_end.line));
+ b = buffer_pos_to_pixels(buffer, range_end);
+ b.y += char_height;
+ Rect r2 = rect_endpoints(a, b); buffer_clip_rect(buffer, &r2);
+ gl_geometry_rect(r2, colors[COLOR_HOVER_HL]);
+ }
+}