mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Implement EditView::important_area
This commit is contained in:
parent
a989fd5f80
commit
4778e4de6f
@ -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))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user