Short circuit when multiple characters are inserted
@@ -30,16 +30,25 @@ pub fn execute<L: BufferDataListener>(
} = self;
let mut selection = cursor.edit_selection(buffer.buffer, tab_width);
+
+ if chars.chars().count() != 1 {
+ let delta =
+ buffer.edit_multiple(&[(&selection, chars)], EditType::InsertChars);
+ let selection =
+ selection.apply_delta(&delta, true, InsertDrift::Default);
+
+ *cursor = Cursor::new(CursorMode::Insert(selection.clone()), None);
+ return None;
+ }
+
+ let mut content = chars.to_string();
let cursor_char =
buffer.buffer.char_at_offset(selection.get_cursor_offset());
- let mut content = chars.to_string();
- if chars.chars().count() == 1 {
let c = chars.chars().next().unwrap();
if !matching_pair_direction(c).unwrap_or(true) {
if cursor_char == Some(c) {
- let selection =
- buffer.buffer.move_cursor_to_right(&selection, 1);
+ let selection = buffer.buffer.move_cursor_to_right(&selection, 1);
*cursor = Cursor::new(CursorMode::Insert(selection), None);
return None;
@@ -50,9 +59,8 @@ pub fn execute<L: BufferDataListener>(
let line_start = buffer.buffer.offset_of_line(line);
if buffer.buffer.slice_to_cow(line_start..offset).trim() == "" {
if let Some(c) = matching_char(c) {
- if let Some(previous_offset) = buffer
- .buffer
- .previous_unmatched(syntax.as_ref(), c, offset)
+ if let Some(previous_offset) =
+ buffer.buffer.previous_unmatched(syntax.as_ref(), c, offset)
{
let previous_line =
buffer.buffer.line_of_offset(previous_offset);
@@ -64,7 +72,6 @@ pub fn execute<L: BufferDataListener>(
}
}
}
- }
let delta =
buffer.edit_multiple(&[(&selection, &content)], EditType::InsertChars);
@@ -72,8 +79,6 @@ pub fn execute<L: BufferDataListener>(
*cursor = Cursor::new(CursorMode::Insert(selection.clone()), None);
- if chars.chars().count() == 1 {
- let c = chars.chars().next().unwrap();
let is_whitespace_or_punct = cursor_char
.map(|c| {
let prop = get_word_property(c);
@@ -83,8 +88,7 @@ pub fn execute<L: BufferDataListener>(
})
.unwrap_or(true);
- if is_whitespace_or_punct && matching_pair_direction(c).unwrap_or(false)
- {
+ if is_whitespace_or_punct && matching_pair_direction(c).unwrap_or(false) {
if let Some(c) = matching_char(c) {
buffer.edit_multiple(
&[(&selection, &c.to_string())],
@@ -92,7 +96,6 @@ pub fn execute<L: BufferDataListener>(
);
}
}
- }
None
}
