mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-24 01:46:31 +00:00
Add mouse support to EditView
This commit is contained in:
parent
0150ebfc9e
commit
aaf41f3ec4
@ -95,13 +95,20 @@ where
|
|||||||
prefix(iter.rev(), width, delimiter)
|
prefix(iter.rev(), width, delimiter)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes the length (number of bytes) and width of a suffix that fits in the given `width`.
|
/// Computes a suffix that fits in the given `width`.
|
||||||
///
|
///
|
||||||
/// Breaks between any two graphemes.
|
/// Breaks between any two graphemes.
|
||||||
pub fn simple_suffix(text: &str, width: usize) -> Prefix {
|
pub fn simple_suffix(text: &str, width: usize) -> Prefix {
|
||||||
suffix(text.graphemes(true), width, "")
|
suffix(text.graphemes(true), width, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Computes the longest prefix of the given text that fits in the given width.
|
||||||
|
///
|
||||||
|
/// Breaks between any two graphemes.
|
||||||
|
pub fn simple_prefix(text: &str, width: usize) -> Prefix {
|
||||||
|
prefix(text.graphemes(true), width, "")
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use utils;
|
use utils;
|
||||||
|
@ -8,7 +8,7 @@ use std::rc::Rc;
|
|||||||
use theme::{ColorStyle, Effect};
|
use theme::{ColorStyle, Effect};
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
use unicode_width::UnicodeWidthStr;
|
use unicode_width::UnicodeWidthStr;
|
||||||
use utils::simple_suffix;
|
use utils::{simple_prefix, simple_suffix};
|
||||||
use vec::Vec2;
|
use vec::Vec2;
|
||||||
use view::View;
|
use view::View;
|
||||||
|
|
||||||
@ -571,6 +571,20 @@ impl View for EditView {
|
|||||||
cb(s, &content);
|
cb(s, &content);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Event::Mouse {
|
||||||
|
event: MouseEvent::Press(_),
|
||||||
|
position,
|
||||||
|
offset,
|
||||||
|
} if position.fits_in_rect(offset, (self.last_length, 1)) =>
|
||||||
|
{
|
||||||
|
position.checked_sub(offset).map(|position| {
|
||||||
|
self.cursor = self.offset
|
||||||
|
+ simple_prefix(
|
||||||
|
&self.content[self.offset..],
|
||||||
|
position.x,
|
||||||
|
).length;
|
||||||
|
});
|
||||||
|
}
|
||||||
_ => return EventResult::Ignored,
|
_ => return EventResult::Ignored,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user