From e40238c37331103d482b9f28ef22a6d642fa8d85 Mon Sep 17 00:00:00 2001 From: "Dustin L. Howett" Date: Fri, 30 May 2025 17:02:38 -0500 Subject: [PATCH 1/4] color visualizer --- src/buffer/mod.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/buffer/mod.rs b/src/buffer/mod.rs index 4676fb945b9..8d5fc117915 100644 --- a/src/buffer/mod.rs +++ b/src/buffer/mod.rs @@ -1654,6 +1654,27 @@ impl TextBuffer { }; // Our manually constructed UTF8 is never going to be invalid. Trust. line.push_str(unsafe { str::from_utf8_unchecked(&visualizer_buf) }); + + let cursor_visualizer = self.cursor_move_to_offset_internal( + cursor_beg, + global_off + chunk_off + 1, + ); + let mut visualizer_rect = Rect::two( + destination.top + cursor_visualizer.visual_pos.y, + destination.left + + self.margin_width + + cursor_visualizer.visual_pos.x, + ); + visualizer_rect.right += 1; + visualizer_rect.bottom += 1; + fb.blend_bg( + visualizer_rect, + fb.indexed_alpha(IndexedColor::Red, 3, 3), + ); + fb.blend_fg( + visualizer_rect, + fb.indexed_alpha(IndexedColor::BrightWhite, 3, 3), + ); } } From c02f96aa0549a3387ab668a15b68e5c1c9c6f6c1 Mon Sep 17 00:00:00 2001 From: "Dustin L. Howett" Date: Fri, 30 May 2025 17:30:57 -0500 Subject: [PATCH 2/4] make it work, make it yeller --- src/buffer/mod.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/buffer/mod.rs b/src/buffer/mod.rs index 8d5fc117915..d338256f953 100644 --- a/src/buffer/mod.rs +++ b/src/buffer/mod.rs @@ -1657,24 +1657,25 @@ impl TextBuffer { let cursor_visualizer = self.cursor_move_to_offset_internal( cursor_beg, - global_off + chunk_off + 1, + global_off + chunk_off - 1, ); let mut visualizer_rect = Rect::two( - destination.top + cursor_visualizer.visual_pos.y, + destination.top + cursor_visualizer.visual_pos.y - origin.y, destination.left + self.margin_width - + cursor_visualizer.visual_pos.x, + + cursor_visualizer.visual_pos.x + - origin.x, ); visualizer_rect.right += 1; visualizer_rect.bottom += 1; - fb.blend_bg( - visualizer_rect, - fb.indexed_alpha(IndexedColor::Red, 3, 3), - ); - fb.blend_fg( - visualizer_rect, - fb.indexed_alpha(IndexedColor::BrightWhite, 3, 3), - ); + if visualizer_rect.top >= destination.top + && visualizer_rect.left >= destination.left + { + let bg = fb.indexed(IndexedColor::Yellow); + let fg = fb.contrasted(bg); + fb.blend_bg(visualizer_rect, bg); + fb.blend_fg(visualizer_rect, fg); + } } } From d8047458f3ab67a4753522c901d3bee6f133c177 Mon Sep 17 00:00:00 2001 From: "Dustin L. Howett" Date: Fri, 30 May 2025 17:44:21 -0500 Subject: [PATCH 3/4] make it pretty --- src/buffer/mod.rs | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/buffer/mod.rs b/src/buffer/mod.rs index d338256f953..6084d2883da 100644 --- a/src/buffer/mod.rs +++ b/src/buffer/mod.rs @@ -1655,27 +1655,24 @@ impl TextBuffer { // Our manually constructed UTF8 is never going to be invalid. Trust. line.push_str(unsafe { str::from_utf8_unchecked(&visualizer_buf) }); - let cursor_visualizer = self.cursor_move_to_offset_internal( - cursor_beg, - global_off + chunk_off - 1, - ); - let mut visualizer_rect = Rect::two( - destination.top + cursor_visualizer.visual_pos.y - origin.y, - destination.left + let visualizer_rect = { + let cursor_visualizer = self.cursor_move_to_offset_internal( + cursor_beg, + global_off + chunk_off - 1, + ); + let left = destination.left + self.margin_width + cursor_visualizer.visual_pos.x - - origin.x, - ); - visualizer_rect.right += 1; - visualizer_rect.bottom += 1; - if visualizer_rect.top >= destination.top - && visualizer_rect.left >= destination.left - { - let bg = fb.indexed(IndexedColor::Yellow); - let fg = fb.contrasted(bg); - fb.blend_bg(visualizer_rect, bg); - fb.blend_fg(visualizer_rect, fg); - } + - origin.x; + let top = + destination.top + cursor_visualizer.visual_pos.y - origin.y; + Rect { left, top, right: left + 1, bottom: top + 1 } + }; + + let bg = fb.indexed(IndexedColor::Yellow); + let fg = fb.contrasted(bg); + fb.blend_bg(visualizer_rect, bg); + fb.blend_fg(visualizer_rect, fg); } } From 164dd087ab3c21c210047e1e294872464696d4b8 Mon Sep 17 00:00:00 2001 From: "Dustin L. Howett" Date: Sat, 31 May 2025 11:34:14 -0500 Subject: [PATCH 4/4] Make it not accidentally quadratic --- src/buffer/mod.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/buffer/mod.rs b/src/buffer/mod.rs index 6084d2883da..020d2ac984e 100644 --- a/src/buffer/mod.rs +++ b/src/buffer/mod.rs @@ -1605,6 +1605,7 @@ impl TextBuffer { let mut global_off = cursor_beg.offset; let mut cursor_tab = cursor_beg; + let mut cursor_visualizer = cursor_beg; while global_off < cursor_end.offset { let chunk = self.read_forward(global_off); @@ -1655,11 +1656,11 @@ impl TextBuffer { // Our manually constructed UTF8 is never going to be invalid. Trust. line.push_str(unsafe { str::from_utf8_unchecked(&visualizer_buf) }); + cursor_visualizer = self.cursor_move_to_offset_internal( + cursor_visualizer, + global_off + chunk_off - 1, + ); let visualizer_rect = { - let cursor_visualizer = self.cursor_move_to_offset_internal( - cursor_beg, - global_off + chunk_off - 1, - ); let left = destination.left + self.margin_width + cursor_visualizer.visual_pos.x