fix whitespace not showing cursor in text input (closes #247)

This commit is contained in:
Stephan Dilly 2020-12-19 21:25:37 +01:00
parent fb17cbd67b
commit 3ff77e0669

View file

@ -11,7 +11,7 @@ use crate::{
use anyhow::Result; use anyhow::Result;
use crossterm::event::{Event, KeyCode, KeyModifiers}; use crossterm::event::{Event, KeyCode, KeyModifiers};
use itertools::Itertools; use itertools::Itertools;
use std::ops::Range; use std::{collections::HashMap, ops::Range};
use tui::{ use tui::{
backend::Backend, backend::Backend,
layout::Rect, layout::Rect,
@ -157,11 +157,20 @@ impl TextInputComponent {
self.get_msg(self.cursor_position..pos) 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_append(
txt, txt,
Text::styled( Text::styled(
"\u{21b5}\n\r", substitute.clone(),
self.theme self.theme
.text(false, false) .text(false, false)
.add_modifier(Modifier::UNDERLINED), .add_modifier(Modifier::UNDERLINED),