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

Code before:
                    || (start.side == Side::Right
                        && end.side == Side::Left
                        && (start.point.line == end.point.line)
                        && start.point.col + 1 == end.point.col)
            },
            SelectionType::Block => {
                let (start, end) = (self.region.start, self.region.end);

                // Block selection is empty when the points' columns and sides are identical
                // or two cells with adjacent columns have the sides right -> left,
                // regardless of their lines
                (start.point.col == end.point.col && start.side == end.side)
                    || (start.point.col + 1 == end.point.col
                        && start.side == Side::Right
                        && end.side == Side::Left)
                    || (end.point.col + 1 == start.point.col
                        && start.side == Side::Left
                        && end.side == Side::Right)
            },
            SelectionType::Semantic | SelectionType::Lines => false,
        }
    }

    /// Check whether selection contains any point in a given range. The start/end of
    /// the range are included.
    pub fn has_points_in_range(&self, range: Range<usize>) -> bool {
        let start = self.region.start.point.line;
        let end = self.region.end.point.line;
        (range.start <= start && start <= range.end) || (range.start <= end && end <= range.end)
    }

    /// Check whether selection contains certain line.
    pub fn contains_line(&self, line: usize) -> bool {
        let start = self.region.start.point.line;
        let end = self.region.end.point.line;
        (start >= line && end <= line) || (end >= line && start <= line)
    }

    /// Expand selection sides to include all cells.
    pub fn include_all(&mut self) {
        let (start, end) = (self.region.start.point, self.region.end.point);
        let (start_side, end_side) = match self.ty {
            SelectionType::Block
                if start.col > end.col || (start.col == end.col && start.line < end.line) =>
            {
                (Side::Right, Side::Left)
            },
            SelectionType::Block => (Side::Left, Side::Right),
            _ if Self::points_need_swap(start, end) => (Side::Right, Side::Left),
            _ => (Side::Left, Side::Right),
        };

Review comment (suggestion):
```suggestion
    #[inline]
    pub fn intersects_range(&self, range: Range<usize>) -> bool {
```

Code after:
                    || (start.side == Side::Right
                        && end.side == Side::Left
                        && (start.point.line == end.point.line)
                        && start.point.col + 1 == end.point.col)
            },
            SelectionType::Block => {
                let (start, end) = (self.region.start, self.region.end);

                // Block selection is empty when the points' columns and sides are identical
                // or two cells with adjacent columns have the sides right -> left,
                // regardless of their lines
                (start.point.col == end.point.col && start.side == end.side)
                    || (start.point.col + 1 == end.point.col
                        && start.side == Side::Right
                        && end.side == Side::Left)
                    || (end.point.col + 1 == start.point.col
                        && start.side == Side::Left
                        && end.side == Side::Right)
            },
            SelectionType::Semantic | SelectionType::Lines => false,
        }
    }

    /// Check whether selection contains any point in a given range.
    pub fn intersects_range<R: RangeBounds<usize>>(&self, range: R) -> bool {
        let mut start = self.region.start.point.line;
        let mut end = self.region.end.point.line;

        if Self::points_need_swap(self.region.start.point, self.region.end.point) {
            mem::swap(&mut start, &mut end);
        }

        let range_start = match range.start_bound() {
            Bound::Included(&range_start) => range_start,
            Bound::Excluded(&range_start) => range_start.saturating_add(1),
            Bound::Unbounded => 0,
        };

        let range_end = match range.end_bound() {
            Bound::Included(&range_end) => range_end,
            Bound::Excluded(&range_end) => range_end.saturating_sub(1),
            Bound::Unbounded => usize::max_value(),
        };

        range_start <= start && range_end >= end
    }

    /// Expand selection sides to include all cells.
    pub fn include_all(&mut self) {
        let (start, end) = (self.region.start.point, self.region.end.point);
        let (start_side, end_side) = match self.ty {