Repository: alacritty/alacritty
File: alacritty_terminal/src/term/mod.rs (Rust)

Code before:

        // Early return if the entire terminal is damaged.
        if self.damage.is_fully_damaged {
            self.damage.last_cursor = self.grid.cursor.point;
            self.damage.last_selection = selection;
            return TermDamage::Full;
        }

        // Add information about old cursor position and new one if they are not the same, so we
        // cover everything that was produced by `Term::input`.
        if self.damage.last_cursor != self.grid.cursor.point {
            // Cursor cooridanates are always inside viewport even if you have `display_offset`.
            let point =
                Point::new(self.damage.last_cursor.line.0 as usize, self.damage.last_cursor.column);
            self.damage.damage_point(point);
        }

        // Always damage current cursor.
        self.damage_cursor();
        self.damage.last_cursor = self.grid.cursor.point;

        // Vi mode doesn't update the terminal content, thus only last vi cursor position and a
        // new one should be damaged.
        if let Some(last_vi_cursor_point) = self.damage.last_vi_cursor_point.take() {
            self.damage.damage_point(last_vi_cursor_point)
        }

        // Damage Vi cursor if it's present.
        if self.mode.contains(TermMode::VI) {
            let vi_cursor_point = self.grid_point_to_viewport(self.vi_mode_cursor.point);
            self.damage.last_vi_cursor_point = Some(vi_cursor_point);
            self.damage.damage_point(vi_cursor_point);
        }

        if self.damage.last_selection != selection {
            let display_offset = self.grid().display_offset();
            for selection in self.damage.last_selection.into_iter().chain(selection) {
                self.damage.damage_selection(selection, display_offset, self.columns());
            }
        }
        self.damage.last_selection = selection;

        TermDamage::Partial(TermDamageIterator::new(&self.damage.lines))
    }

    /// Resets the terminal damage information.
    pub fn reset_damage(&mut self) {
        self.damage.reset(self.columns());
    }

    #[inline]

Review comment (suggestion):
```suggestion
        // Vi mode doesn't update the terminal content, thus only last vi cursor position and the
        // new one should be damaged.
        if let Some(last_vi_cursor_point) = self.damage.last_vi_cursor_point.take() {
            self.damage.damage_point(last_vi_cursor_point)
        }
```

Code after:
            title: None,
            title_stack: Vec::new(),
            selection: None,
            damage,
        }
    }

    #[must_use]
    pub fn damage(&mut self, selection: Option<SelectionRange>) -> TermDamage<'_> {
        // Ensure the entire terminal is damaged after entering insert mode.
        // Leaving is handled in the ansi handler.
        if self.mode.contains(TermMode::INSERT) {
            self.mark_fully_damaged();
        }

        // Early return if the entire terminal is damaged.
        if self.damage.is_fully_damaged {
            self.damage.last_cursor = self.grid.cursor.point;
            self.damage.last_selection = selection;
            return TermDamage::Full;
        }

        // Add information about old cursor position and new one if they are not the same, so we
        // cover everything that was produced by `Term::input`.
        if self.damage.last_cursor != self.grid.cursor.point {
            // Cursor cooridanates are always inside viewport even if you have `display_offset`.
            let point =
                Point::new(self.damage.last_cursor.line.0 as usize, self.damage.last_cursor.column);
            self.damage.damage_point(point);
        }

        // Always damage current cursor.
        self.damage_cursor();
        self.damage.last_cursor = self.grid.cursor.point;

        // Vi mode doesn't update the terminal content, thus only last vi cursor position and the
        // new one should be damaged.
        if let Some(last_vi_cursor_point) = self.damage.last_vi_cursor_point.take() {
            self.damage.damage_point(last_vi_cursor_point)
        }

        let display_offset = self.grid().display_offset();

        // Damage Vi cursor if it's present.
        if self.mode.contains(TermMode::VI) {
            let vi_cursor_point =
                point_to_viewport(display_offset, self.vi_mode_cursor.point).unwrap();
            self.damage.last_vi_cursor_point = Some(vi_cursor_point);
            self.damage.damage_point(vi_cursor_point);
        }