From 779552ee7ddbbde1055c7202e16b9a13c3961988 Mon Sep 17 00:00:00 2001 From: teapotd Date: Wed, 1 Apr 2020 11:08:02 +0200 Subject: Form constraints validation --- components/script/textinput.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'components/script/textinput.rs') diff --git a/components/script/textinput.rs b/components/script/textinput.rs index bc4c1c4a6cb..623085ccd19 100644 --- a/components/script/textinput.rs +++ b/components/script/textinput.rs @@ -184,6 +184,9 @@ pub struct TextInput { /// max_length: Option, min_length: Option, + + /// Was last change made by set_content? + was_last_change_by_set_content: bool, } /// Resulting action to be taken by the owner of a text input that is handling an event. @@ -269,6 +272,7 @@ impl TextInput { max_length: max_length, min_length: min_length, selection_direction: selection_direction, + was_last_change_by_set_content: true, }; i.set_content(initial); i @@ -300,6 +304,11 @@ impl TextInput { self.min_length = length; } + /// Was last edit made by set_content? + pub fn was_last_change_by_set_content(&self) -> bool { + self.was_last_change_by_set_content + } + /// Remove a character at the current editing point pub fn delete_char(&mut self, dir: Direction) { if self.selection_origin.is_none() || self.selection_origin == Some(self.edit_point) { @@ -496,6 +505,7 @@ impl TextInput { }; self.lines = new_lines; + self.was_last_change_by_set_content = false; self.clear_selection(); self.assert_ok_selection(); } @@ -1035,6 +1045,7 @@ impl TextInput { vec![content] }; + self.was_last_change_by_set_content = true; self.edit_point = self.edit_point.constrain_to(&self.lines); if let Some(origin) = self.selection_origin { -- cgit v1.2.3