From 76eb518ad44c8007bad1a5847a010a989abf4c39 Mon Sep 17 00:00:00 2001
From: StaffEngineer <velo.app1@gmail.com>
Date: Mon, 11 Sep 2023 00:42:53 +0100
Subject: [PATCH] enable cursor blinking

---
 Cargo.lock                  |  2 +-
 Cargo.toml                  |  2 +-
 examples/font_per_widget.rs |  5 +++--
 src/lib.rs                  | 26 ++++++++++++++++++++++++++
 4 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index e6b4419..61fd581 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -388,7 +388,7 @@ dependencies = [
 
 [[package]]
 name = "bevy_cosmic_edit"
-version = "0.10.0"
+version = "0.10.1"
 dependencies = [
  "arboard",
  "bevy",
diff --git a/Cargo.toml b/Cargo.toml
index a670eb4..f9e4a83 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "bevy_cosmic_edit"
-version = "0.10.0"
+version = "0.10.1"
 edition = "2021"
 license = "MIT OR Apache-2.0"
 description = "Bevy cosmic-text multiline text input"
diff --git a/examples/font_per_widget.rs b/examples/font_per_widget.rs
index 50d0843..c3580c5 100644
--- a/examples/font_per_widget.rs
+++ b/examples/font_per_widget.rs
@@ -249,12 +249,13 @@ fn setup(
 
     let mut attrs_2 = cosmic_text::Attrs::new();
     attrs_2 = attrs_2.family(cosmic_text::Family::Name("Times New Roman"));
+    attrs_2.color_opt = Some(cosmic_text::Color::rgb(0x94, 0x00, 0xD3));
 
     let cosmic_edit_2 = CosmicEditUiBundle {
         cosmic_attrs: CosmicAttrs(AttrsOwned::new(attrs_2)),
         cosmic_metrics: CosmicMetrics {
-            font_size: 14.,
-            line_height: 18.,
+            font_size: 28.,
+            line_height: 36.,
             scale_factor: primary_window.scale_factor() as f32,
         },
         text_position: CosmicTextPosition::Center,
diff --git a/src/lib.rs b/src/lib.rs
index 9f09020..2d836b8 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -389,6 +389,7 @@ impl Plugin for CosmicEditPlugin {
                         .before(cosmic_edit_set_redraw)
                         .before(on_scale_factor_change),
                     cosmic_edit_redraw_buffer.before(on_scale_factor_change),
+                    blink_cursor,
                 ),
             )
             .init_resource::<ActiveEditor>()
@@ -1177,6 +1178,31 @@ fn cosmic_edit_redraw_buffer_ui(
     }
 }
 
+fn blink_cursor(
+    mut visible: Local<bool>,
+    mut timer: Local<Option<Timer>>,
+    time: Res<Time>,
+    mut cosmic_editor_q: Query<(&mut CosmicEditor, &BackgroundColor), Without<ReadOnly>>,
+) {
+    let timer = timer.get_or_insert_with(|| Timer::from_seconds(0.53, TimerMode::Repeating));
+    timer.tick(time.delta());
+    if !timer.just_finished() {
+        return;
+    }
+    *visible = !*visible;
+    for (mut editor, bg_color) in &mut cosmic_editor_q.iter_mut() {
+        let mut cursor = editor.0.cursor();
+        let new_color = if *visible {
+            None
+        } else {
+            Some(bevy_color_to_cosmic(bg_color.0))
+        };
+        cursor.color = new_color;
+        editor.0.set_cursor(cursor);
+        editor.0.buffer_mut().set_redraw(true);
+    }
+}
+
 fn cosmic_edit_redraw_buffer(
     windows: Query<&Window, With<PrimaryWindow>>,
     mut images: ResMut<Assets<Image>>,
-- 
GitLab