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

Code before:
                // 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(&self, range: RangeInclusive<usize>) -> 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, range_end) = range.into_inner();

        range.start <= selection.end && range.end >= selection.start
    }

    /// 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),
        };

        self.region.start.side = start_side;
        self.region.end.side = end_side;
    }

    /// Convert selection to grid coordinates.
    pub fn to_range<T>(&self, term: &Term<T>) -> Option<SelectionRange> {
        let grid = term.grid();
        let num_cols = grid.num_cols();


Review comment (suggestion):
```suggestion
        range_end >= start && range_start <= end
```

Code after:
                // 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 {
            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),
        };