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

Code before:
                true
            } else {
                let mode = editor_data.editor.cursor.get_mode();
                let old_mode = old_editor_data.editor.cursor.get_mode();
                let offset = editor_data.editor.cursor.offset();
                let old_offset = old_editor_data.editor.cursor.offset();
                let (line, col) =
                    editor_data.doc.buffer().offset_to_line_col(offset);
                let (old_line, old_col) =
                    old_editor_data.doc.buffer().offset_to_line_col(old_offset);
                mode != old_mode || line != old_line || col != old_col
            };

            if reset {
                self.cursor_blink_timer = ctx.request_timer(
                    Duration::from_millis(data.config.editor.blink_interval),
                    None,
                );
                *editor_data.editor.last_cursor_instant.borrow_mut() =
                    Instant::now();
                ctx.request_paint();
            }
        }

        if data.config.editor.autosave_interval > 0
            && *data.focus == self.view_id
            && *old_data.focus != self.view_id
        {
            self.autosave_timer = ctx.request_timer(
                Duration::from_millis(data.config.editor.autosave_interval),
                None,
            );
        }

        if old_data.config.lapce.modal != data.config.lapce.modal
            && !editor_data.doc.content().is_input()
        {
            if !data.config.lapce.modal {
                ctx.submit_command(Command::new(
                    LAPCE_COMMAND,
                    LapceCommand {
                        kind: CommandKind::Edit(EditCommand::InsertMode),
                        data: None,
                    },
                    Target::Widget(self.view_id),
                ));
            } else {
                ctx.submit_command(Command::new(
                    LAPCE_COMMAND,
                    LapceCommand {
                        kind: CommandKind::Edit(EditCommand::NormalMode),

Review comment (suggestion):
Shouldn't the timer be triggered when the document is changed rather than focus changed? 

So

 ```
editor_data.doc.rev() != old_editor_data.doc.rev()
```

Code after:
                true
            } else {
                let mode = editor_data.editor.cursor.get_mode();
                let old_mode = old_editor_data.editor.cursor.get_mode();
                let offset = editor_data.editor.cursor.offset();
                let old_offset = old_editor_data.editor.cursor.offset();
                let (line, col) =
                    editor_data.doc.buffer().offset_to_line_col(offset);
                let (old_line, old_col) =
                    old_editor_data.doc.buffer().offset_to_line_col(old_offset);
                mode != old_mode || line != old_line || col != old_col
            };

            if reset {
                self.cursor_blink_timer = ctx.request_timer(
                    Duration::from_millis(data.config.editor.blink_interval),
                    None,
                );
                *editor_data.editor.last_cursor_instant.borrow_mut() =
                    Instant::now();
                ctx.request_paint();
            }
        }

        if data.config.editor.autosave_interval > 0
            && editor_data.doc.rev() != old_editor_data.doc.rev()
        {
            self.autosave_timer = ctx.request_timer(
                Duration::from_millis(data.config.editor.autosave_interval),
                None,
            );
        }

        if old_data.config.lapce.modal != data.config.lapce.modal
            && !editor_data.doc.content().is_input()
        {
            if !data.config.lapce.modal {
                ctx.submit_command(Command::new(
                    LAPCE_COMMAND,
                    LapceCommand {
                        kind: CommandKind::Edit(EditCommand::InsertMode),
                        data: None,
                    },
                    Target::Widget(self.view_id),
                ));
            } else {
                ctx.submit_command(Command::new(
                    LAPCE_COMMAND,
                    LapceCommand {
                        kind: CommandKind::Edit(EditCommand::NormalMode),
                        data: None,