Implement EditView::important_area

This commit is contained in:
Alexandre Bury 2018-03-22 14:15:57 -07:00
parent a989fd5f80
commit 4778e4de6f

View File

@ -1,6 +1,7 @@
use {Cursive, Printer, With}; use {Cursive, Printer, With};
use direction::Direction; use direction::Direction;
use event::{Callback, Event, EventResult, Key, MouseEvent}; use event::{Callback, Event, EventResult, Key, MouseEvent};
use rect::Rect;
use std::cell::RefCell; use std::cell::RefCell;
use std::rc::Rc; use std::rc::Rc;
use theme::{ColorStyle, Effect}; use theme::{ColorStyle, Effect};
@ -681,4 +682,22 @@ impl View for EditView {
EventResult::Consumed(self.make_edit_cb()) 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))
}
} }