diff options
author | Ms2ger <Ms2ger@gmail.com> | 2015-11-03 14:16:55 +0100 |
---|---|---|
committer | Ms2ger <Ms2ger@gmail.com> | 2015-11-04 12:09:11 +0100 |
commit | 6b75078503f25a61084a3e9cae1b7d57de21772f (patch) | |
tree | ddfc15e73be407657f687f55d9c8b7bce5b9596c /components/script/textinput.rs | |
parent | e6aa976462fad0aafb2d59d0a590b69a8c8b5ba9 (diff) | |
download | servo-6b75078503f25a61084a3e9cae1b7d57de21772f.tar.gz servo-6b75078503f25a61084a3e9cae1b7d57de21772f.zip |
Make DOMString a newtype around String, rather than a typedef.
This should make it somewhat easier to experiment with alternative
representations in the future. To reduce churn, this commit leaves the String
field public, though.
Also, this will allow us to use the default String type to represent the IDL
USVString type, which explicitly forbids unpaired surrogates, ans as such is
a better match to the Rust String type.
Diffstat (limited to 'components/script/textinput.rs')
-rw-r--r-- | components/script/textinput.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/components/script/textinput.rs b/components/script/textinput.rs index ce69139d5ab..98b080fd1b8 100644 --- a/components/script/textinput.rs +++ b/components/script/textinput.rs @@ -137,7 +137,7 @@ impl<T: ClipboardProvider> TextInput<T> { if self.selection_begin.is_none() { self.selection_begin = Some(self.edit_point); } - self.replace_selection(s.into()); + self.replace_selection(DOMString(s.into())); } pub fn get_sorted_selection(&self) -> Option<(TextPoint, TextPoint)> { @@ -170,7 +170,7 @@ impl<T: ClipboardProvider> TextInput<T> { }) } - pub fn replace_selection(&mut self, insert: String) { + pub fn replace_selection(&mut self, insert: DOMString) { if let Some((begin, end)) = self.get_sorted_selection() { self.clear_selection(); @@ -181,20 +181,20 @@ impl<T: ClipboardProvider> TextInput<T> { let lines_suffix = &self.lines[end.line + 1..]; let mut insert_lines = if self.multiline { - insert.split('\n').map(|s| s.to_owned()).collect() + insert.split('\n').map(|s| DOMString(s.to_owned())).collect() } else { vec!(insert) }; let mut new_line = prefix.to_owned(); new_line.push_str(&insert_lines[0]); - insert_lines[0] = new_line; + insert_lines[0] = DOMString(new_line); let last_insert_lines_index = insert_lines.len() - 1; self.edit_point.index = insert_lines[last_insert_lines_index].len(); self.edit_point.line = begin.line + last_insert_lines_index; - insert_lines[last_insert_lines_index].push_str(suffix); + insert_lines[last_insert_lines_index].0.push_str(suffix); let mut new_lines = vec!(); new_lines.push_all(lines_prefix); @@ -441,14 +441,14 @@ impl<T: ClipboardProvider> TextInput<T> { content.push('\n'); } } - content + DOMString(content) } /// 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) { self.lines = if self.multiline { - content.split('\n').map(|s| s.to_owned()).collect() + content.split('\n').map(|s| DOMString(s.to_owned())).collect() } else { vec!(content) }; |