cut
This commit is contained in:
@@ -83,6 +83,28 @@ impl Clipboard {
|
|||||||
}
|
}
|
||||||
self.last_paste_cell = (low_x, low_y);
|
self.last_paste_cell = (low_x, low_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn clipboard_cut(&mut self, start: (usize, usize), end: (usize, usize), from: &mut Grid) {
|
||||||
|
let (x1, y1) = start;
|
||||||
|
let (x2, y2) = end;
|
||||||
|
|
||||||
|
let (low_x, hi_x) = if x1 < x2 { (x1, x2) } else { (x2, x1) };
|
||||||
|
let (low_y, hi_y) = if y1 < y2 { (y1, y2) } else { (y2, y1) };
|
||||||
|
|
||||||
|
// size the clipboard appropriately
|
||||||
|
self.clipboard.clear();
|
||||||
|
// clone data into clipboard
|
||||||
|
for x in low_x..=hi_x {
|
||||||
|
let mut col = Vec::new();
|
||||||
|
for y in low_y..=hi_y {
|
||||||
|
let a = from.get_cell_raw(x, y);
|
||||||
|
col.push(a.clone());
|
||||||
|
from.set_cell_raw::<CellType>((x,y), None);
|
||||||
|
}
|
||||||
|
self.clipboard.push(col);
|
||||||
|
}
|
||||||
|
self.last_paste_cell = (low_x, low_y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -182,16 +182,9 @@ impl Mode {
|
|||||||
// TODO visual copy, paste, etc
|
// TODO visual copy, paste, etc
|
||||||
let (x2, y2) = app.grid.cursor();
|
let (x2, y2) = app.grid.cursor();
|
||||||
|
|
||||||
let (low_x, hi_x) = if x1 < x2 { (x1, x2) } else { (x2, x1) };
|
|
||||||
let (low_y, hi_y) = if y1 < y2 { (y1, y2) } else { (y2, y1) };
|
|
||||||
|
|
||||||
match key {
|
match key {
|
||||||
'd' => {
|
'd' | 'x' => {
|
||||||
for x in low_x..=hi_x {
|
app.clipboard.clipboard_cut((x1,y1), (x2,y2), &mut app.grid);
|
||||||
for y in low_y..=hi_y {
|
|
||||||
app.grid.set_cell_raw::<CellType>((x, y), None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
app.mode = Mode::Normal
|
app.mode = Mode::Normal
|
||||||
}
|
}
|
||||||
'y' => {
|
'y' => {
|
||||||
@@ -237,7 +230,7 @@ impl Mode {
|
|||||||
// delete cell under cursor
|
// delete cell under cursor
|
||||||
("d", ' ') | ("d", 'w') => {
|
("d", ' ') | ("d", 'w') => {
|
||||||
let loc = app.grid.cursor();
|
let loc = app.grid.cursor();
|
||||||
app.grid.set_cell_raw::<CellType>(loc, None);
|
app.clipboard.clipboard_cut(loc, loc, &mut app.grid);
|
||||||
app.mode = Mode::Normal;
|
app.mode = Mode::Normal;
|
||||||
}
|
}
|
||||||
// go to top of row
|
// go to top of row
|
||||||
|
|||||||
Reference in New Issue
Block a user