aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/textinput.rs
diff options
context:
space:
mode:
authorEmanuel Rylke <ema-fox@web.de>2014-12-20 21:35:54 +0100
committerEmanuel Rylke <ema-fox@web.de>2014-12-21 14:31:15 +0100
commitc732a779eb33f799470214e271f642611ade71d4 (patch)
tree562de2ad16947a0d6a4d0f911316be25bcf5c4dd /components/script/textinput.rs
parenta773bd5c4568f2f33855f9cfe04b4301038429f7 (diff)
downloadservo-c732a779eb33f799470214e271f642611ade71d4.tar.gz
servo-c732a779eb33f799470214e271f642611ade71d4.zip
On left/right keydown place edit_point correctly when there is a selection in TextInput
Fixes #4447
Diffstat (limited to 'components/script/textinput.rs')
-rw-r--r--components/script/textinput.rs20
1 files changed, 15 insertions, 5 deletions
diff --git a/components/script/textinput.rs b/components/script/textinput.rs
index 843838933c2..8e984fe60d6 100644
--- a/components/script/textinput.rs
+++ b/components/script/textinput.rs
@@ -97,15 +97,20 @@ impl TextInput {
self.replace_selection(ch.to_string());
}
- fn replace_selection(&mut self, insert: String) {
- let begin = self.selection_begin.take().unwrap();
+ fn get_sorted_selection(&self) -> (TextPoint, TextPoint) {
+ let begin = self.selection_begin.unwrap();
let end = self.edit_point;
- let (begin, end) = if begin.line < end.line || (begin.line == end.line && begin.index < end.index) {
+ if begin.line < end.line || (begin.line == end.line && begin.index < end.index) {
(begin, end)
} else {
(end, begin)
- };
+ }
+ }
+
+ fn replace_selection(&mut self, insert: String) {
+ let (begin, end) = self.get_sorted_selection();
+ self.selection_begin = None;
let new_lines = {
let prefix = self.lines[begin.line].slice_chars(0, begin.index);
@@ -186,7 +191,12 @@ impl TextInput {
self.selection_begin = Some(self.edit_point);
}
} else {
- self.selection_begin = None;
+ if self.selection_begin.is_some() {
+ let (begin, end) = self.get_sorted_selection();
+ self.edit_point = if adjust < 0 {begin} else {end};
+ self.selection_begin = None;
+ return
+ }
}
if adjust < 0 {