From 3ff77e0669de001f4368d321fee46002f8085ffb Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Sat, 19 Dec 2020 21:25:37 +0100 Subject: [PATCH] fix whitespace not showing cursor in text input (closes #247) --- src/components/textinput.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/textinput.rs b/src/components/textinput.rs index 8e30582f..f8b7c6c4 100644 --- a/src/components/textinput.rs +++ b/src/components/textinput.rs @@ -11,7 +11,7 @@ use crate::{ use anyhow::Result; use crossterm::event::{Event, KeyCode, KeyModifiers}; use itertools::Itertools; -use std::ops::Range; +use std::{collections::HashMap, ops::Range}; use tui::{ backend::Backend, layout::Rect, @@ -157,11 +157,20 @@ impl TextInputComponent { self.get_msg(self.cursor_position..pos) }); - if cursor_str == "\n" { + let cursor_highlighting = { + let mut h = HashMap::with_capacity(2); + h.insert("\n", "\u{21b5}\n\r"); + h.insert(" ", "\u{00B7}"); + h + }; + + if let Some(substitute) = + cursor_highlighting.get(cursor_str.as_str()) + { txt = text_append( txt, Text::styled( - "\u{21b5}\n\r", + substitute.clone(), self.theme .text(false, false) .add_modifier(Modifier::UNDERLINED),