From 6a2c73d0e0ea710f2b6acfaad2b6a6551f807352 Mon Sep 17 00:00:00 2001 From: bansheerubber Date: Fri, 5 Jun 2020 08:58:34 -0700 Subject: [PATCH 1/5] sketch of move_cursor_to commands --- native/src/widget/text_input.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index e3a5355b..9e7d504a 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -683,6 +683,22 @@ impl State { pub fn cursor(&self) -> Cursor { self.cursor } + + /// Moves the [`Cursor`] of the [`TextInput`] to the front of the input text. + /// + /// [`Cursor`]: struct.Cursor.html + /// [`TextInput`]: struct.TextInput.html + pub fn move_cursor_to_front(&mut self) { + self.cursor.move_to(0); + } + + /// Moves the [`Cursor`] of the [`TextInput`] to the end of the input text. + /// + /// [`Cursor`]: struct.Cursor.html + /// [`TextInput`]: struct.TextInput.html + pub fn move_cursor_to_end(&mut self) { + self.cursor.move_to(5000); + } } // TODO: Reduce allocations From 0d119aa73197d545f12d95e5a2549a68d3067de9 Mon Sep 17 00:00:00 2001 From: bansheerubber Date: Fri, 5 Jun 2020 09:08:36 -0700 Subject: [PATCH 2/5] added value to move_cursor_to_end --- native/src/widget/text_input.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index 9e7d504a..0dbcc3d6 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -696,8 +696,8 @@ impl State { /// /// [`Cursor`]: struct.Cursor.html /// [`TextInput`]: struct.TextInput.html - pub fn move_cursor_to_end(&mut self) { - self.cursor.move_to(5000); + pub fn move_cursor_to_end(&mut self, value: &String) { + self.cursor.move_to(value.len()); } } From 98cf9c455a201fec3069f415ce2ddf5e88def242 Mon Sep 17 00:00:00 2001 From: bansheerubber Date: Fri, 5 Jun 2020 09:19:46 -0700 Subject: [PATCH 3/5] added move_cursor_to --- native/src/widget/text_input.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index 0dbcc3d6..c821247f 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -699,6 +699,14 @@ impl State { pub fn move_cursor_to_end(&mut self, value: &String) { self.cursor.move_to(value.len()); } + + /// Moves the [`Cursor`] of the [`TextInput`] to an arbitrary location. + /// + /// [`Cursor`]: struct.Cursor.html + /// [`TextInput`]: struct.TextInput.html + pub fn move_cursor_to(&mut self, position: usize) { + self.cursor.move_to(position); + } } // TODO: Reduce allocations From 19c07da86f6481244577f30262d250df25f43c39 Mon Sep 17 00:00:00 2001 From: bansheerubber Date: Fri, 5 Jun 2020 09:57:18 -0700 Subject: [PATCH 4/5] fixed formatting --- native/src/widget/text_input.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index c821247f..9d6afffb 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -685,7 +685,7 @@ impl State { } /// Moves the [`Cursor`] of the [`TextInput`] to the front of the input text. - /// + /// /// [`Cursor`]: struct.Cursor.html /// [`TextInput`]: struct.TextInput.html pub fn move_cursor_to_front(&mut self) { @@ -693,7 +693,7 @@ impl State { } /// Moves the [`Cursor`] of the [`TextInput`] to the end of the input text. - /// + /// /// [`Cursor`]: struct.Cursor.html /// [`TextInput`]: struct.TextInput.html pub fn move_cursor_to_end(&mut self, value: &String) { @@ -701,7 +701,7 @@ impl State { } /// Moves the [`Cursor`] of the [`TextInput`] to an arbitrary location. - /// + /// /// [`Cursor`]: struct.Cursor.html /// [`TextInput`]: struct.TextInput.html pub fn move_cursor_to(&mut self, position: usize) { From 5260b3072ac0426489a16ab435dc9d533c5ed081 Mon Sep 17 00:00:00 2001 From: bansheerubber Date: Mon, 8 Jun 2020 10:00:25 -0700 Subject: [PATCH 5/5] implemented hecrj's suggestion --- native/src/widget/text_input.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index 9d6afffb..24085606 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -696,8 +696,8 @@ impl State { /// /// [`Cursor`]: struct.Cursor.html /// [`TextInput`]: struct.TextInput.html - pub fn move_cursor_to_end(&mut self, value: &String) { - self.cursor.move_to(value.len()); + pub fn move_cursor_to_end(&mut self) { + self.cursor.move_to(usize::MAX); } /// Moves the [`Cursor`] of the [`TextInput`] to an arbitrary location.