mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Remove some unnecessary allocations in text input handling.
This commit is contained in:
parent
a3eb253bdc
commit
b1486720e9
1 changed files with 6 additions and 10 deletions
|
@ -134,19 +134,15 @@ impl<T: ClipboardProvider> TextInput<T> {
|
|||
|
||||
/// Insert a character at the current editing point
|
||||
pub fn insert_char(&mut self, ch: char) {
|
||||
if self.selection_begin.is_none() {
|
||||
self.selection_begin = Some(self.edit_point);
|
||||
}
|
||||
self.replace_selection(ch.to_string());
|
||||
self.insert_string(ch.to_string());
|
||||
}
|
||||
|
||||
/// Insert a string at the current editing point
|
||||
fn insert_string(&mut self, s: &str) {
|
||||
// it looks like this could be made performant by avoiding some redundant
|
||||
// selection-related checks, but use the simple implementation for now
|
||||
for ch in s.chars() {
|
||||
self.insert_char(ch);
|
||||
fn insert_string<S: Into<String>>(&mut self, s: S) {
|
||||
if self.selection_begin.is_none() {
|
||||
self.selection_begin = Some(self.edit_point);
|
||||
}
|
||||
self.replace_selection(s.into());
|
||||
}
|
||||
|
||||
pub fn get_sorted_selection(&self) -> (TextPoint, TextPoint) {
|
||||
|
@ -316,7 +312,7 @@ impl<T: ClipboardProvider> TextInput<T> {
|
|||
},
|
||||
Key::V if is_control_key(mods) => {
|
||||
let contents = self.clipboard_provider.clipboard_contents();
|
||||
self.insert_string(&contents);
|
||||
self.insert_string(contents);
|
||||
KeyReaction::DispatchInput
|
||||
},
|
||||
_ if is_printable_key(key) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue