summaryrefslogtreecommitdiffstats
path: root/widget/src/text_input
diff options
context:
space:
mode:
Diffstat (limited to 'widget/src/text_input')
-rw-r--r--widget/src/text_input/cursor.rs26
-rw-r--r--widget/src/text_input/value.rs13
2 files changed, 20 insertions, 19 deletions
diff --git a/widget/src/text_input/cursor.rs b/widget/src/text_input/cursor.rs
index 9680dfd7..f682b17d 100644
--- a/widget/src/text_input/cursor.rs
+++ b/widget/src/text_input/cursor.rs
@@ -56,7 +56,7 @@ impl Cursor {
State::Selection { start, end } => {
Some((start.min(end), start.max(end)))
}
- _ => None,
+ State::Index(_) => None,
}
}
@@ -65,11 +65,11 @@ impl Cursor {
}
pub(crate) fn move_right(&mut self, value: &Value) {
- self.move_right_by_amount(value, 1)
+ self.move_right_by_amount(value, 1);
}
pub(crate) fn move_right_by_words(&mut self, value: &Value) {
- self.move_to(value.next_end_of_word(self.right(value)))
+ self.move_to(value.next_end_of_word(self.right(value)));
}
pub(crate) fn move_right_by_amount(
@@ -79,7 +79,7 @@ impl Cursor {
) {
match self.state(value) {
State::Index(index) => {
- self.move_to(index.saturating_add(amount).min(value.len()))
+ self.move_to(index.saturating_add(amount).min(value.len()));
}
State::Selection { start, end } => self.move_to(end.max(start)),
}
@@ -89,7 +89,7 @@ impl Cursor {
match self.state(value) {
State::Index(index) if index > 0 => self.move_to(index - 1),
State::Selection { start, end } => self.move_to(start.min(end)),
- _ => self.move_to(0),
+ State::Index(_) => self.move_to(0),
}
}
@@ -108,10 +108,10 @@ impl Cursor {
pub(crate) fn select_left(&mut self, value: &Value) {
match self.state(value) {
State::Index(index) if index > 0 => {
- self.select_range(index, index - 1)
+ self.select_range(index, index - 1);
}
State::Selection { start, end } if end > 0 => {
- self.select_range(start, end - 1)
+ self.select_range(start, end - 1);
}
_ => {}
}
@@ -120,10 +120,10 @@ impl Cursor {
pub(crate) fn select_right(&mut self, value: &Value) {
match self.state(value) {
State::Index(index) if index < value.len() => {
- self.select_range(index, index + 1)
+ self.select_range(index, index + 1);
}
State::Selection { start, end } if end < value.len() => {
- self.select_range(start, end + 1)
+ self.select_range(start, end + 1);
}
_ => {}
}
@@ -132,10 +132,10 @@ impl Cursor {
pub(crate) fn select_left_by_words(&mut self, value: &Value) {
match self.state(value) {
State::Index(index) => {
- self.select_range(index, value.previous_start_of_word(index))
+ self.select_range(index, value.previous_start_of_word(index));
}
State::Selection { start, end } => {
- self.select_range(start, value.previous_start_of_word(end))
+ self.select_range(start, value.previous_start_of_word(end));
}
}
}
@@ -143,10 +143,10 @@ impl Cursor {
pub(crate) fn select_right_by_words(&mut self, value: &Value) {
match self.state(value) {
State::Index(index) => {
- self.select_range(index, value.next_end_of_word(index))
+ self.select_range(index, value.next_end_of_word(index));
}
State::Selection { start, end } => {
- self.select_range(start, value.next_end_of_word(end))
+ self.select_range(start, value.next_end_of_word(end));
}
}
}
diff --git a/widget/src/text_input/value.rs b/widget/src/text_input/value.rs
index cf4da562..46a1f754 100644
--- a/widget/src/text_input/value.rs
+++ b/widget/src/text_input/value.rs
@@ -2,7 +2,7 @@ use unicode_segmentation::UnicodeSegmentation;
/// The value of a [`TextInput`].
///
-/// [`TextInput`]: crate::widget::TextInput
+/// [`TextInput`]: super::TextInput
// TODO: Reduce allocations, cache results (?)
#[derive(Debug, Clone)]
pub struct Value {
@@ -89,11 +89,6 @@ impl Value {
Self { graphemes }
}
- /// Converts the [`Value`] into a `String`.
- pub fn to_string(&self) -> String {
- self.graphemes.concat()
- }
-
/// Inserts a new `char` at the given grapheme `index`.
pub fn insert(&mut self, index: usize, c: char) {
self.graphemes.insert(index, c.to_string());
@@ -131,3 +126,9 @@ impl Value {
}
}
}
+
+impl std::fmt::Display for Value {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.write_str(&self.graphemes.concat())
+ }
+}