aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/textinput.rs
diff options
context:
space:
mode:
authorpaavininanda <paavininanda@gmail.com>2018-02-06 22:33:12 +0530
committerpaavininanda <paavininanda@gmail.com>2018-02-10 17:46:29 +0530
commitb2c1f89b932a72f9e0110c17adde33647e84c902 (patch)
treee07e3491fd5f53d68814ea409a679b656fde00c3 /components/script/textinput.rs
parente19bab84cf43c43930d7493840444a8ee2af1e8b (diff)
downloadservo-b2c1f89b932a72f9e0110c17adde33647e84c902.tar.gz
servo-b2c1f89b932a72f9e0110c17adde33647e84c902.zip
Correct default Selectionstart and SelectionEnd
Diffstat (limited to 'components/script/textinput.rs')
-rw-r--r--components/script/textinput.rs40
1 files changed, 21 insertions, 19 deletions
diff --git a/components/script/textinput.rs b/components/script/textinput.rs
index 4d8479346f3..a4a5d5e8965 100644
--- a/components/script/textinput.rs
+++ b/components/script/textinput.rs
@@ -171,7 +171,7 @@ impl<T: ClipboardProvider> TextInput<T> {
min_length: min_length,
selection_direction: selection_direction,
};
- i.set_content(initial);
+ i.set_content(initial, false);
i
}
@@ -411,9 +411,7 @@ impl<T: ClipboardProvider> TextInput<T> {
return;
}
-
let col = self.lines[self.edit_point.line][..self.edit_point.index].chars().count();
-
self.edit_point.line = target_line as usize;
self.edit_point.index = len_of_first_n_chars(&self.lines[self.edit_point.line], col);
self.assert_ok_selection();
@@ -533,9 +531,9 @@ impl<T: ClipboardProvider> TextInput<T> {
}
/// Remove the current selection and set the edit point to the end of the content.
- pub fn clear_selection_to_limit(&mut self, direction: Direction) {
+ pub fn clear_selection_to_limit(&mut self, direction: Direction, update_text_cursor: bool) {
self.clear_selection();
- self.adjust_horizontal_to_limit(direction, Selection::NotSelected);
+ self.adjust_horizontal_to_limit(direction, Selection::NotSelected, update_text_cursor);
}
pub fn adjust_horizontal_by_word(&mut self, direction: Direction, select: Selection) {
@@ -627,18 +625,20 @@ impl<T: ClipboardProvider> TextInput<T> {
self.perform_horizontal_adjustment(shift, select);
}
- pub fn adjust_horizontal_to_limit(&mut self, direction: Direction, select: Selection) {
+ pub fn adjust_horizontal_to_limit(&mut self, direction: Direction, select: Selection, update_text_cursor: bool) {
if self.adjust_selection_for_horizontal_change(direction, select) {
return
}
- match direction {
- Direction::Backward => {
- self.edit_point.line = 0;
- self.edit_point.index = 0;
- },
- Direction::Forward => {
- self.edit_point.line = &self.lines.len() - 1;
- self.edit_point.index = (&self.lines[&self.lines.len() - 1]).len();
+ if update_text_cursor {
+ match direction {
+ Direction::Backward => {
+ self.edit_point.line = 0;
+ self.edit_point.index = 0;
+ },
+ Direction::Forward => {
+ self.edit_point.line = &self.lines.len() - 1;
+ self.edit_point.index = (&self.lines[&self.lines.len() - 1]).len();
+ }
}
}
}
@@ -728,12 +728,12 @@ impl<T: ClipboardProvider> TextInput<T> {
},
#[cfg(target_os = "macos")]
(None, Key::Up) if mods.contains(KeyModifiers::SUPER) => {
- self.adjust_horizontal_to_limit(Direction::Backward, maybe_select);
+ self.adjust_horizontal_to_limit(Direction::Backward, maybe_select, true);
KeyReaction::RedrawSelection
},
#[cfg(target_os = "macos")]
(None, Key::Down) if mods.contains(KeyModifiers::SUPER) => {
- self.adjust_horizontal_to_limit(Direction::Forward, maybe_select);
+ self.adjust_horizontal_to_limit(Direction::Forward, maybe_select, true);
KeyReaction::RedrawSelection
},
(None, Key::Left) if mods.contains(KeyModifiers::ALT) => {
@@ -840,7 +840,7 @@ impl<T: ClipboardProvider> TextInput<T> {
/// Set the current contents of the text input. If this is control supports multiple lines,
/// any \n encountered will be stripped and force a new logical line.
- pub fn set_content(&mut self, content: DOMString) {
+ pub fn set_content(&mut self, content: DOMString, update_text_cursor: bool) {
self.lines = if self.multiline {
// https://html.spec.whatwg.org/multipage/#textarea-line-break-normalisation-transformation
content.replace("\r\n", "\n")
@@ -850,8 +850,10 @@ impl<T: ClipboardProvider> TextInput<T> {
} else {
vec!(content)
};
- self.edit_point.line = min(self.edit_point.line, self.lines.len() - 1);
- self.edit_point.index = min(self.edit_point.index, self.current_line_length());
+ if update_text_cursor {
+ self.edit_point.line = min(self.edit_point.line, self.lines.len() - 1);
+ self.edit_point.index = min(self.edit_point.index, self.current_line_length());
+ }
self.selection_origin = None;
self.assert_ok_selection();
}