Repository: lapce/lapce
File: lapce-data/src/document.rs (Rust)

Code before:
                    cursor,
                    &mut self.buffer,
                    motion_mode,
                    offset,
                    offset,
                    true,
                    register,
                );
                self.apply_deltas(&deltas);
            }
            cursor.motion_mode = None;
        } else {
            cursor.motion_mode = Some(motion_mode);
        }
    }

    pub fn do_paste(&mut self, cursor: &mut Cursor, data: &RegisterData) {
        let deltas = Editor::do_paste(cursor, &mut self.buffer, data);
        self.apply_deltas(&deltas)
    }

    pub fn styles(&self) -> Option<Arc<Spans<Style>>> {
        let semantic_styles = self.semantic_styles.as_ref();
        let syntax_styles = self.syntax().and_then(|s| s.styles.as_ref());

        if semantic_styles.is_some() && syntax_styles.is_some() {
            let combined_styles = semantic_styles
                .unwrap()
                .merge(syntax_styles.unwrap(), |a, _| a.clone());

            return Some(Arc::new(combined_styles));
        } else if semantic_styles.is_some() {
            return semantic_styles.cloned();
        } else if syntax_styles.is_some() {
            return syntax_styles.cloned();
        }

        None
    }

    fn line_style(&self, line: usize) -> Arc<Vec<LineStyle>> {
        if self.line_styles.borrow().get(&line).is_none() {
            let styles = self.styles();

            let line_styles = styles
                .map(|styles| line_styles(self.buffer.text(), line, &styles))
                .unwrap_or_default();
            self.line_styles
                .borrow_mut()
                .insert(line, Arc::new(line_styles));
        }

Review comment (suggestion):
You should do `match (semantic_styles, syntactic_styles)` here, I think and handle the 4 (maybe 3 if you can merge the two middle cases into an or pattern) branches in the match.

Code after:
                    }
                    cursor.set_insert(selection);
                }
            }
            SelectAll => {
                let new_selection = Selection::region(0, self.buffer.len());
                cursor.set_insert(new_selection);
            }
        }
    }

    pub fn do_motion_mode(
        &mut self,
        cursor: &mut Cursor,
        motion_mode: MotionMode,
        register: &mut Register,
    ) {
        if let Some(m) = &cursor.motion_mode {
            if m == &motion_mode {
                let offset = cursor.offset();
                let deltas = Editor::execute_motion_mode(
                    cursor,
                    &mut self.buffer,
                    motion_mode,
                    offset,
                    offset,
                    true,
                    register,
                );
                self.apply_deltas(&deltas);
            }
            cursor.motion_mode = None;
        } else {
            cursor.motion_mode = Some(motion_mode);
        }
    }

    pub fn do_paste(&mut self, cursor: &mut Cursor, data: &RegisterData) {
        let deltas = Editor::do_paste(cursor, &mut self.buffer, data);
        self.apply_deltas(&deltas)
    }

    pub fn styles(&self) -> Option<&Arc<Spans<Style>>> {
        if let Some(semantic_styles) = self.semantic_styles.as_ref() {
            Some(semantic_styles)
        } else {
            self.syntax().and_then(|s| s.styles.as_ref())
        }
    }

    fn line_style(&self, line: usize) -> Arc<Vec<LineStyle>> {