Skip to content

Commit

Permalink
fix: cursor color not being reset when input is empty and there isnt …
Browse files Browse the repository at this point in the history
…a placeholder or suggestion
  • Loading branch information
Vulpesx committed Apr 27, 2024
1 parent 633308d commit b97ea56
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ 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
Expand All @@ -338,11 +339,14 @@ impl<'a> Input<'a> {
}
return Ok(input);
}

let cursor_idx = self.get_char_idx(&input, self.cursor);
write!(out, "{}", &input[..cursor_idx])?;

if cursor_idx < input.len() {
out.set_color(&self.theme.real_cursor_color(None))?;
write!(out, "{}", &input[cursor_idx..cursor_idx + 1])?;
out.reset()?;
}
if cursor_idx + 1 < input.len() {
out.reset()?;
Expand Down Expand Up @@ -370,10 +374,12 @@ impl<'a> Input<'a> {
} else if cursor_idx >= input.len() {
out.set_color(&self.theme.real_cursor_color(None))?;
write!(out, " ")?;
out.reset()?;
}
} else if cursor_idx >= input.len() {
out.set_color(&self.theme.real_cursor_color(None))?;
write!(out, " ")?;
out.reset()?;
}

Ok(input)
Expand Down

0 comments on commit b97ea56

Please sign in to comment.