1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-25 14:05:41 -05:00

Remove redundant selection::Region type

The type selection::Region was defined identially to std::ops::Range.
Using something other than range just served to confuse.
This commit is contained in:
Joe Wilm 2017-10-12 20:59:21 -07:00
parent 9fdf77f91a
commit 44f58b81f2

View file

@ -19,6 +19,7 @@
//! when text is added/removed/scrolled on the screen. The selection should
//! also be cleared if the user clicks off of the selection.
use std::cmp::{min, max};
use std::ops::Range;
use index::{Point, Column, RangeInclusive, Side, Linear, Line};
use grid::ToRange;
@ -41,20 +42,20 @@ use grid::ToRange;
pub enum Selection {
Simple {
/// The region representing start and end of cursor movement
region: Region<Anchor>,
region: Range<Anchor>,
},
Semantic {
/// The region representing start and end of cursor movement
region: Region<Point>,
region: Range<Point>,
/// When beginning a semantic selection, the grid is searched around the
/// initial point to find semantic escapes, and this initial expansion
/// marks those points.
initial_expansion: Region<Point>
initial_expansion: Range<Point>
},
Lines {
/// The region representing start and end of cursor movement
region: Region<Point>,
region: Range<Point>,
/// The line under the initial point. This is always selected regardless
/// of which way the cursor is moved.
@ -62,11 +63,6 @@ pub enum Selection {
}
}
pub struct Region<T> {
start: T,
end: T
}
/// A Point and side within that point.
pub struct Anchor {
point: Point,
@ -99,7 +95,7 @@ pub trait Dimensions {
impl Selection {
pub fn simple(location: Point, side: Side) -> Selection {
Selection::Simple {
region: Region {
region: Range {
start: Anchor::new(location, side),
end: Anchor::new(location, side)
}
@ -109,11 +105,11 @@ impl Selection {
pub fn semantic<G: SemanticSearch>(point: Point, grid: &G) -> Selection {
let (start, end) = (grid.semantic_search_left(point), grid.semantic_search_right(point));
Selection::Semantic {
region: Region {
region: Range {
start: point,
end: point,
},
initial_expansion: Region {
initial_expansion: Range {
start: start,
end: end
}
@ -122,7 +118,7 @@ impl Selection {
pub fn lines(point: Point) -> Selection {
Selection::Lines {
region: Region {
region: Range {
start: point,
end: point
},
@ -159,8 +155,8 @@ impl Selection {
}
fn span_semantic<G>(
grid: &G,
region: &Region<Point>,
initial_expansion: &Region<Point>
region: &Range<Point>,
initial_expansion: &Range<Point>
) -> Option<Span>
where G: SemanticSearch + Dimensions
{
@ -192,7 +188,7 @@ impl Selection {
})
}
fn span_lines<G>(grid: &G, region: &Region<Point>, initial_line: &Line) -> Option<Span>
fn span_lines<G>(grid: &G, region: &Range<Point>, initial_line: &Line) -> Option<Span>
where G: Dimensions
{
// First, create start and end points based on initial line and the grid
@ -225,7 +221,7 @@ impl Selection {
})
}
fn span_simple<G: Dimensions>(grid: &G, region: &Region<Anchor>) -> Option<Span> {
fn span_simple<G: Dimensions>(grid: &G, region: &Range<Anchor>) -> Option<Span> {
let start = region.start.point;
let start_side = region.start.side;
let end = region.end.point;