parent
1067fa609b
commit
fb37a9cb55
|
@ -132,7 +132,7 @@ impl Selection {
|
||||||
|
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
Selection::Simple { ref region } | Selection::Block { ref region } => {
|
Selection::Simple { ref region } => {
|
||||||
let (start, end) =
|
let (start, end) =
|
||||||
if Selection::points_need_swap(region.start.point, region.end.point) {
|
if Selection::points_need_swap(region.start.point, region.end.point) {
|
||||||
(®ion.end, ®ion.start)
|
(®ion.end, ®ion.start)
|
||||||
|
@ -140,13 +140,26 @@ impl Selection {
|
||||||
(®ion.start, ®ion.end)
|
(®ion.start, ®ion.end)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Empty when single cell with identical sides or two cell with right+left sides
|
// Simple selection is empty when the points are identical
|
||||||
|
// or two adjacent cells have the sides right -> left
|
||||||
start == end
|
start == end
|
||||||
|| (start.side == Side::Left
|
|| (start.side == Side::Left
|
||||||
&& end.side == Side::Right
|
&& end.side == Side::Right
|
||||||
&& start.point.line == end.point.line
|
&& (start.point.line == end.point.line)
|
||||||
&& start.point.col == end.point.col + 1)
|
&& start.point.col == end.point.col + 1)
|
||||||
},
|
},
|
||||||
|
Selection::Block { region: Range { ref start, ref 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 == end.point.col + 1
|
||||||
|
&& start.side == Side::Left
|
||||||
|
&& end.side == Side::Right)
|
||||||
|
|| (end.point.col == start.point.col + 1
|
||||||
|
&& end.side == Side::Left
|
||||||
|
&& start.side == Side::Right)
|
||||||
|
},
|
||||||
Selection::Semantic { .. } | Selection::Lines { .. } => false,
|
Selection::Semantic { .. } | Selection::Lines { .. } => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -589,4 +602,30 @@ mod test {
|
||||||
is_block: false,
|
is_block: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn simple_is_empty() {
|
||||||
|
let mut selection = Selection::simple(Point::new(0, Column(0)), Side::Right);
|
||||||
|
assert!(selection.is_empty());
|
||||||
|
selection.update(Point::new(0, Column(1)), Side::Left);
|
||||||
|
assert!(selection.is_empty());
|
||||||
|
selection.update(Point::new(1, Column(0)), Side::Right);
|
||||||
|
assert!(!selection.is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn block_is_empty() {
|
||||||
|
let mut selection = Selection::block(Point::new(0, Column(0)), Side::Right);
|
||||||
|
assert!(selection.is_empty());
|
||||||
|
selection.update(Point::new(0, Column(1)), Side::Left);
|
||||||
|
assert!(selection.is_empty());
|
||||||
|
selection.update(Point::new(0, Column(1)), Side::Right);
|
||||||
|
assert!(!selection.is_empty());
|
||||||
|
selection.update(Point::new(1, Column(0)), Side::Right);
|
||||||
|
assert!(selection.is_empty());
|
||||||
|
selection.update(Point::new(1, Column(1)), Side::Left);
|
||||||
|
assert!(selection.is_empty());
|
||||||
|
selection.update(Point::new(1, Column(1)), Side::Right);
|
||||||
|
assert!(!selection.is_empty());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ use mio::unix::EventedFd;
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
use std::mem::MaybeUninit;
|
||||||
use std::os::unix::{
|
use std::os::unix::{
|
||||||
io::{AsRawFd, FromRawFd, RawFd},
|
io::{AsRawFd, FromRawFd, RawFd},
|
||||||
process::CommandExt,
|
process::CommandExt,
|
||||||
|
@ -35,7 +36,6 @@ use std::os::unix::{
|
||||||
use std::process::{Child, Command, Stdio};
|
use std::process::{Child, Command, Stdio};
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
use std::mem::MaybeUninit;
|
|
||||||
|
|
||||||
/// Process ID of child process
|
/// Process ID of child process
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in New Issue