FIX: When cut and paste to a different sheet origin is removed
Fixes #193
This commit is contained in:
committed by
Nicolás Hatcher Andrés
parent
a5919d837f
commit
e098105531
@@ -99,7 +99,7 @@ fn cut_paste() {
|
||||
|
||||
// paste in cell D4 (4, 4)
|
||||
model
|
||||
.paste_from_clipboard((1, 1, 2, 2), ©.data, true)
|
||||
.paste_from_clipboard(0, (1, 1, 2, 2), ©.data, true)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(model.get_cell_content(0, 4, 4), Ok("42".to_string()));
|
||||
@@ -119,6 +119,26 @@ fn cut_paste() {
|
||||
assert_eq!(model.get_cell_content(0, 2, 2), Ok("".to_string()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cut_paste_different_sheet() {
|
||||
let mut model = UserModel::new_empty("model", "en", "UTC").unwrap();
|
||||
model.set_user_input(0, 1, 1, "42").unwrap();
|
||||
|
||||
model.set_selected_range(1, 1, 1, 1).unwrap();
|
||||
let copy = model.copy_to_clipboard().unwrap();
|
||||
model.new_sheet().unwrap();
|
||||
model.set_selected_sheet(1).unwrap();
|
||||
model.set_selected_cell(4, 4).unwrap();
|
||||
|
||||
// paste in cell D4 (4, 4) of Sheet2
|
||||
model
|
||||
.paste_from_clipboard(0, (1, 1, 1, 1), ©.data, true)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(model.get_cell_content(1, 4, 4), Ok("42".to_string()));
|
||||
assert_eq!(model.get_cell_content(0, 1, 1), Ok("".to_string()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn copy_paste_internal() {
|
||||
let mut model = UserModel::new_empty("model", "en", "UTC").unwrap();
|
||||
@@ -152,7 +172,7 @@ fn copy_paste_internal() {
|
||||
|
||||
// paste in cell D4 (4, 4)
|
||||
model
|
||||
.paste_from_clipboard((1, 1, 2, 2), ©.data, false)
|
||||
.paste_from_clipboard(0, (1, 1, 2, 2), ©.data, false)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(model.get_cell_content(0, 4, 4), Ok("42".to_string()));
|
||||
|
||||
@@ -39,6 +39,7 @@ pub struct ClipboardCell {
|
||||
pub struct Clipboard {
|
||||
pub(crate) csv: String,
|
||||
pub(crate) data: ClipboardData,
|
||||
pub(crate) sheet: u32,
|
||||
pub(crate) range: (i32, i32, i32, i32),
|
||||
}
|
||||
|
||||
@@ -1520,6 +1521,7 @@ impl UserModel {
|
||||
Ok(Clipboard {
|
||||
csv,
|
||||
data,
|
||||
sheet,
|
||||
range: (row_start, column_start, row_end, column_end),
|
||||
})
|
||||
}
|
||||
@@ -1527,6 +1529,7 @@ impl UserModel {
|
||||
/// Paste text that we copied
|
||||
pub fn paste_from_clipboard(
|
||||
&mut self,
|
||||
source_sheet: u32,
|
||||
source_range: ClipboardTuple,
|
||||
clipboard: &ClipboardData,
|
||||
is_cut: bool,
|
||||
@@ -1617,17 +1620,17 @@ impl UserModel {
|
||||
let old_value = self
|
||||
.model
|
||||
.workbook
|
||||
.worksheet(sheet)?
|
||||
.worksheet(source_sheet)?
|
||||
.cell(row, column)
|
||||
.cloned();
|
||||
|
||||
diff_list.push(Diff::CellClearContents {
|
||||
sheet,
|
||||
sheet: source_sheet,
|
||||
row,
|
||||
column,
|
||||
old_value: Box::new(old_value),
|
||||
});
|
||||
self.model.cell_clear_contents(sheet, row, column)?;
|
||||
self.model.cell_clear_contents(source_sheet, row, column)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user