Repository: lapce/lapce
File: lapce-core/src/editor.rs (Rust)

Code before:
            } else {
                let c = s.chars().next().unwrap();
                let matching_pair_type = matching_pair_direction(c);

                // The main edit operations
                let mut edits = vec![];

                // "Late edits" - characters to be inserted after particular regions
                let mut edits_after = vec![];

                let mut selection = selection.clone();
                for (idx, region) in selection.regions_mut().iter_mut().enumerate() {
                    let offset = region.end;
                    let cursor_char = buffer.char_at_offset(offset);
                    let prev_offset = buffer.move_left(offset, Mode::Normal, 1);
                    let prev_cursor_char = if prev_offset < offset {
                        buffer.char_at_offset(prev_offset)
                    } else {
                        None
                    };

                    // when text is selected, and [,{,(,'," is inserted
                    // wrap the text with that char and its corresponding closing pair
                    if region.start != region.end
                        && (matching_pair_type.is_some() || c == '"' || c == '\'')
                        && ((matching_pair_type.unwrap_or(false))
                            || c == '"'
                            || c == '\'')
                    {
                        edits.push((
                            Selection::region(region.min(), region.min()),
                            c.to_string(),
                        ));
                        edits_after.push((
                            idx,
                            match c {
                                '"' => '"',
                                '\'' => '\'',
                                _ => matching_char(c).unwrap(),
                            },
                        ));
                        continue;
                    }

                    if auto_closing_matching_pairs {
                        if (c == '"' || c == '\'') && cursor_char == Some(c) {
                            // Skip the closing character
                            let new_offset =
                                buffer.next_grapheme_offset(offset, 1, buffer.len());

                            *region = SelRegion::caret(new_offset);

Review comment (suggestion):
You can replace 

```
(matching_pair_type.is_some() || c == '"' || c == '\'')
                        && ((matching_pair_type.unwrap_or(false))
                            || c == '"'
                            || c == '\'')
```

with 

```
matching_pair_type == Some(true) || c == '"' ||  == '\''
```

Code after:
                deltas.push((delta, inval_lines, edits));
                cursor.mode = CursorMode::Insert(selection);
            } else {
                let c = s.chars().next().unwrap();
                let matching_pair_type = matching_pair_direction(c);

                // The main edit operations
                let mut edits = vec![];

                // "Late edits" - characters to be inserted after particular regions
                let mut edits_after = vec![];

                let mut selection = selection.clone();
                for (idx, region) in selection.regions_mut().iter_mut().enumerate() {
                    let offset = region.end;
                    let cursor_char = buffer.char_at_offset(offset);
                    let prev_offset = buffer.move_left(offset, Mode::Normal, 1);
                    let prev_cursor_char = if prev_offset < offset {
                        buffer.char_at_offset(prev_offset)
                    } else {
                        None
                    };

                    // when text is selected, and [,{,(,'," is inserted
                    // wrap the text with that char and its corresponding closing pair
                    if region.start != region.end && matching_pair_type == Some(true)
                        || c == '"'
                        || c == '\''
                    {
                        edits.push((
                            Selection::region(region.min(), region.min()),
                            c.to_string(),
                        ));
                        edits_after.push((
                            idx,
                            match c {
                                '"' => '"',
                                '\'' => '\'',
                                _ => matching_char(c).unwrap(),
                            },
                        ));
                        continue;
                    }

                    if auto_closing_matching_pairs {
                        if (c == '"' || c == '\'') && cursor_char == Some(c) {
                            // Skip the closing character
                            let new_offset =
                                buffer.next_grapheme_offset(offset, 1, buffer.len());

                            *region = SelRegion::caret(new_offset);