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

Code before:
            self.main_split.current_save_as =
                Some(Arc::new((content, view_id, exit)));
            let options =
                FileDialogOptions::new().accept_command(LAPCE_SAVE_FILE_AS);
            ctx.submit_command(druid::commands::SHOW_SAVE_PANEL.with(options));
        }
    }

    fn run_move_command(
        &mut self,
        ctx: &mut EventCtx,
        movement: &lapce_core::movement::Movement,
        count: Option<usize>,
        mods: Modifiers,
    ) -> CommandExecuted {
        if movement.is_jump() && movement != &self.editor.last_movement_new {
            Arc::make_mut(&mut self.editor).save_jump_location(&self.doc);
        }
        Arc::make_mut(&mut self.editor).last_movement_new = movement.clone();

        let register = Arc::make_mut(&mut self.main_split.register);
        let doc = Arc::make_mut(&mut self.doc);
        let view = self.editor.view.clone();
        doc.move_cursor(
            ctx.text(),
            &mut Arc::make_mut(&mut self.editor).cursor,
            movement,
            count.unwrap_or(1),
            mods.shift(),
            &view,
            register,
            &self.config,
        );
        if let Some(snippet) = self.editor.snippet.as_ref() {
            let offset = self.editor.cursor.offset();
            let mut within_region = false;
            for (_, (start, end)) in snippet {
                if offset >= *start && offset <= *end {
                    within_region = true;
                    break;
                }
            }
            if !within_region {
                Arc::make_mut(&mut self.editor).snippet = None;
            }
        }
        self.cancel_completion();
        self.cancel_hover();
        CommandExecuted::Yes
    }


Review comment (suggestion):
Recommend: encapsulating expression of whether an EditCommand is one that inserts a whitespace character.
Something like
```
impl EditCommand {
    fn is_insert_whitespace(&self) _> bool {
        use EditCommand::*;
        match self {
            InsertNewLine
            | InsertTab
            | NewLineAbove
            | NewLineBelow => true,
            _ => false
        }
    }
}
```
Note: I did not check if this compiles.

Rationale: If anything else needs to similarly adapt to whitespace, it'll be handy to expect they have the same behavior. Makes it look more similar to its counterpart in expressing "if not whitespace, then update_completion", which seems like a requirement to check beforehand for 2/3 calls to update_completion.

Significance: Pedantic. I'd recommend accepting this Pull Request with or without this suggestion.

Code after:
    fn run_edit_command(
        &mut self,
        ctx: &mut EventCtx,
        cmd: &EditCommand,
    ) -> CommandExecuted {
        let modal = self.config.lapce.modal && !self.editor.content.is_input();
        let doc = Arc::make_mut(&mut self.doc);
        let register = Arc::make_mut(&mut self.main_split.register);
        let cursor = &mut Arc::make_mut(&mut self.editor).cursor;
        let yank_data =
            if let lapce_core::cursor::CursorMode::Visual { .. } = &cursor.mode {
                Some(cursor.yank(doc.buffer()))
            } else {
                None
            };

        let deltas = doc.do_edit(cursor, cmd, modal, register);

        if !deltas.is_empty() {
            if let Some(data) = yank_data {
                register.add_delete(data);
            }
        }

        match cmd {
            EditCommand::InsertNewLine
            | EditCommand::InsertTab
            | EditCommand::NewLineAbove
            | EditCommand::NewLineBelow => {}
            _ => self.update_completion(ctx, false),
        }
        self.apply_deltas(&deltas);

        CommandExecuted::Yes
    }

    fn run_focus_command(
        &mut self,
        ctx: &mut EventCtx,
        cmd: &FocusCommand,
        count: Option<usize>,
        mods: Modifiers,
    ) -> CommandExecuted {
        use FocusCommand::*;
        match cmd {
            ModalClose => {
                if self.is_palette() {
                    ctx.submit_command(Command::new(
                        LAPCE_COMMAND,
                        LapceCommand {
                            kind: CommandKind::Focus(FocusCommand::ModalClose),