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

Code before:
        // 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;

        if let Some(last_vi_cursor) = self.damage.last_vi_cursor.take() {
            self.damage_grid_point(last_vi_cursor.point)
        }

        // Damage Vi cursor if it's present.
        if self.mode.contains(TermMode::VI) {
            self.damage.last_vi_cursor = Some(self.vi_mode_cursor);
            self.damage_vi_cursor();
        }

        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]
    pub fn mark_fully_damaged(&mut self) {
        self.damage.is_fully_damaged = true;
    }

    /// Damage line in a terminal viewport.
    #[inline]
    pub fn damage_line(&mut self, line: usize, left: usize, right: usize) {
        self.damage.damage_line(line, left, right);
    }

    pub fn update_config(&mut self, config: &Config)

Review comment (suggestion):
Comments could be a little more detailed maybe. Just a short line above the `last_vi_cursor` logic that explicitly states what it is for would likely be helpful.

Code after:
    #[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);
        }

        if self.damage.last_selection != selection {
            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;