diff options
author | Joe Wilm <joe@jwilm.com> | 2016-12-26 22:52:37 -0500 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2016-12-26 22:56:19 -0500 |
commit | ae470bf68bf27921109890da3d90a5b61fa6a7aa (patch) | |
tree | d9e3d3a90f29471a0fe68a0e3966d95deb3a6f39 /src/selection.rs | |
parent | d28a7344731c4cd913687a893334555feed4e270 (diff) | |
download | alacritty-ae470bf68bf27921109890da3d90a5b61fa6a7aa.tar.gz alacritty-ae470bf68bf27921109890da3d90a5b61fa6a7aa.zip |
Implement copying selection for macOS
Still need automatic loading into selection copy buffer for linux.
Diffstat (limited to 'src/selection.rs')
-rw-r--r-- | src/selection.rs | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/src/selection.rs b/src/selection.rs index 6c927967..a02d94e4 100644 --- a/src/selection.rs +++ b/src/selection.rs @@ -21,7 +21,7 @@ use std::mem; use std::ops::RangeInclusive; -use index::{Location, Column, Side, Linear}; +use index::{Location, Column, Side, Linear, Line}; use grid::ToRange; /// The area selected @@ -94,7 +94,7 @@ impl Selection { pub fn span(&self) -> Option<Span> { match *self { - Selection::Active {ref start, ref end, ref start_side, ref end_side } => { + Selection::Active { ref start, ref end, ref start_side, ref end_side } => { let (front, tail, front_side, tail_side) = if *start > *end { // Selected upward; start/end are swapped (end, start, end_side, start_side) @@ -180,6 +180,43 @@ pub struct Span { } impl Span { + pub fn to_locations(&self, cols: Column) -> (Location, Location) { + match self.ty { + SpanType::Inclusive => (self.front, self.tail), + SpanType::Exclusive => { + (Span::wrap_start(self.front, cols), Span::wrap_end(self.tail, cols)) + }, + SpanType::ExcludeFront => (Span::wrap_start(self.front, cols), self.tail), + SpanType::ExcludeTail => (self.front, Span::wrap_end(self.tail, cols)) + } + } + + fn wrap_start(mut start: Location, cols: Column) -> Location { + if start.col == cols - 1 { + Location { + line: start.line + 1, + col: Column(0), + } + } else { + start.col += 1; + start + } + } + + fn wrap_end(end: Location, cols: Column) -> Location { + if end.col == Column(0) && end.line != Line(0) { + Location { + line: end.line - 1, + col: cols + } + } else { + Location { + line: end.line, + col: end.col - 1 + } + } + } + #[inline] fn exclude_start(start: Linear) -> Linear { start + 1 |