Skip to content

Commit 3ff77e0

Browse files
author
Stephan Dilly
committed
fix whitespace not showing cursor in text input (closes #247)
1 parent fb17cbd commit 3ff77e0

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/components/textinput.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
use anyhow::Result;
1212
use crossterm::event::{Event, KeyCode, KeyModifiers};
1313
use itertools::Itertools;
14-
use std::ops::Range;
14+
use std::{collections::HashMap, ops::Range};
1515
use tui::{
1616
backend::Backend,
1717
layout::Rect,
@@ -157,11 +157,20 @@ impl TextInputComponent {
157157
self.get_msg(self.cursor_position..pos)
158158
});
159159

160-
if cursor_str == "\n" {
160+
let cursor_highlighting = {
161+
let mut h = HashMap::with_capacity(2);
162+
h.insert("\n", "\u{21b5}\n\r");
163+
h.insert(" ", "\u{00B7}");
164+
h
165+
};
166+
167+
if let Some(substitute) =
168+
cursor_highlighting.get(cursor_str.as_str())
169+
{
161170
txt = text_append(
162171
txt,
163172
Text::styled(
164-
"\u{21b5}\n\r",
173+
substitute.clone(),
165174
self.theme
166175
.text(false, false)
167176
.add_modifier(Modifier::UNDERLINED),

0 commit comments

Comments
 (0)