From 4778e4de6f7588cd0c6cbe91bab98114e5319784 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Thu, 22 Mar 2018 14:15:57 -0700 Subject: [PATCH] Implement EditView::important_area --- src/views/edit_view.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/views/edit_view.rs b/src/views/edit_view.rs index 8cdf5bd..7fd1d56 100644 --- a/src/views/edit_view.rs +++ b/src/views/edit_view.rs @@ -1,6 +1,7 @@ use {Cursive, Printer, With}; use direction::Direction; use event::{Callback, Event, EventResult, Key, MouseEvent}; +use rect::Rect; use std::cell::RefCell; use std::rc::Rc; use theme::{ColorStyle, Effect}; @@ -681,4 +682,22 @@ impl View for EditView { EventResult::Consumed(self.make_edit_cb()) } + + fn important_area(&self, _: Vec2) -> Rect { + let char_width = if self.cursor >= self.content.len() { + // Show a space if we're at the end of the content + 1 + } else { + // Otherwise look at the selected character. + self.content[self.cursor..] + .graphemes(true) + .next() + .unwrap() + .width() + }; + + let x = self.content[..self.cursor].width(); + + Rect::from_size((x, 0), (char_width, 1)) + } }