From f27e236478c2f6ae2305ddf1e429137eb02f37f5 Mon Sep 17 00:00:00 2001
From: Vulpesx <potaytochipgamer@gmail.com>
Date: Sat, 27 Apr 2024 16:48:48 +1000
Subject: [PATCH] fix: cursor rendering after placeholder

---
 src/input.rs | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/src/input.rs b/src/input.rs
index db08474..28376eb 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -297,11 +297,11 @@ impl<'a> Input<'a> {
         }
         out.reset()?;
 
-        if !self.placeholder.is_empty() && self.input.is_empty() {
-            out.set_color(&self.theme.input_placeholder)?;
-            write!(out, "{}", &self.placeholder)?;
-            out.reset()?;
-        }
+        // if !self.placeholder.is_empty() && self.input.is_empty() {
+        //     out.set_color(&self.theme.input_placeholder)?;
+        //     write!(out, "{}", &self.placeholder)?;
+        //     out.reset()?;
+        // }
 
         self.render_input(&mut out)?;
 
@@ -324,6 +324,20 @@ impl<'a> Input<'a> {
             true => self.input.chars().map(|_| '*').collect::<String>(),
             false => self.input.to_string(),
         };
+        if !self.placeholder.is_empty() && self.input.is_empty() {
+            out.set_color(
+                &self
+                    .theme
+                    .real_cursor_color(Some(&self.theme.input_placeholder)),
+            )?;
+            write!(out, "{}", &self.placeholder[..1])?;
+            if self.placeholder.len() > 1 {
+                out.set_color(&self.theme.input_placeholder)?;
+                write!(out, "{}", &self.placeholder[1..])?;
+                out.reset()?;
+            }
+            return Ok(input);
+        }
         let cursor_idx = self.get_char_idx(&input, self.cursor);
         write!(out, "{}", &input[..cursor_idx])?;
         if cursor_idx < input.len() {