mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Correct default Selectionstart and SelectionEnd
This commit is contained in:
parent
e19bab84cf
commit
b2c1f89b93
8 changed files with 144 additions and 87 deletions
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue