Added a hollow mode to the cursor rendering code, for terminal lost focus

Mikayla Maki created

Change summary

crates/editor/src/element.rs        | 46 +++++++++++++++++++++++++++++-
crates/terminal/src/connected_el.rs |  6 ++--
2 files changed, 47 insertions(+), 5 deletions(-)

Detailed changes

crates/editor/src/element.rs 🔗

@@ -1753,6 +1753,7 @@ pub enum CursorShape {
     Bar,
     Block,
     Underscore,
+    Hollow,
 }
 
 impl Default for CursorShape {
@@ -1808,8 +1809,19 @@ impl Cursor {
                 self.origin + origin + Vector2F::new(0.0, self.line_height - 2.0),
                 vec2f(self.block_width, 2.0),
             ),
+            CursorShape::Hollow => RectF::new(
+                self.origin + origin + Vector2F::new(0.0, self.line_height - 1.0),
+                vec2f(self.block_width, 1.0),
+            ),
         };
 
+        //Draw text under the hollow block if need be
+        if matches!(self.shape, CursorShape::Hollow) {
+            if let Some(block_text) = &self.block_text {
+                block_text.paint(self.origin + origin, bounds, self.line_height, cx);
+            }
+        }
+
         cx.scene.push_quad(Quad {
             bounds,
             background: Some(self.color),
@@ -1817,8 +1829,38 @@ impl Cursor {
             corner_radius: 0.,
         });
 
-        if let Some(block_text) = &self.block_text {
-            block_text.paint(self.origin + origin, bounds, self.line_height, cx);
+        if matches!(self.shape, CursorShape::Hollow) {
+            //Top
+            cx.scene.push_quad(Quad {
+                bounds: RectF::new(
+                    self.origin + origin + Vector2F::new(0.0, -1.0),
+                    vec2f(self.block_width + 1., 1.0),
+                ),
+                background: Some(self.color),
+                border: Border::new(0., Color::black()),
+                corner_radius: 0.,
+            });
+            //Left
+            cx.scene.push_quad(Quad {
+                bounds: RectF::new(self.origin + origin, vec2f(1.0, self.line_height)),
+                background: Some(self.color),
+                border: Border::new(0., Color::black()),
+                corner_radius: 0.,
+            });
+            //Right
+            cx.scene.push_quad(Quad {
+                bounds: RectF::new(
+                    self.origin + origin + vec2f(self.block_width, 0.),
+                    vec2f(1.0, self.line_height),
+                ),
+                background: Some(self.color),
+                border: Border::new(0., Color::black()),
+                corner_radius: 0.,
+            });
+        } else {
+            if let Some(block_text) = &self.block_text {
+                block_text.paint(self.origin + origin, bounds, self.line_height, cx);
+            }
         }
     }
 }

crates/terminal/src/connected_el.rs 🔗

@@ -635,7 +635,7 @@ impl Element for TerminalEl {
             .unwrap()
             .update(cx.app, |terminal, mcx| {
                 terminal.set_size(dimensions);
-                terminal.render_lock(mcx, |content, cursor_text, style| {
+                terminal.render_lock(mcx, |content, cursor_text, blink_mode| {
                     let mut cells = vec![];
                     cells.extend(
                         content
@@ -659,7 +659,7 @@ impl Element for TerminalEl {
                         content.cursor,
                         content.display_offset,
                         cursor_text,
-                        style,
+                        blink_mode,
                     )
                 })
             });
@@ -713,7 +713,7 @@ impl Element for TerminalEl {
                         let (shape, color) = if self.focused {
                             (CursorShape::Block, terminal_theme.colors.cursor)
                         } else {
-                            (CursorShape::Underscore, terminal_theme.colors.foreground)
+                            (CursorShape::Hollow, terminal_theme.colors.foreground)
                         };
 
                         Cursor::new(