fully deprecate old single row col methods
This commit is contained in:
committed by
Nicolás Hatcher Andrés
parent
183d04b923
commit
7dc49d5dd7
@@ -26,14 +26,14 @@ fn diff_invariant_insert_rows() {
|
||||
|
||||
let list = last_diff_list(&mut model);
|
||||
assert_eq!(list.len(), 1);
|
||||
match &list[0] {
|
||||
Diff::InsertRows { sheet, row, count } => {
|
||||
assert_eq!(*sheet, 0);
|
||||
assert_eq!(*row, 5);
|
||||
assert_eq!(*count, 3);
|
||||
}
|
||||
_ => panic!("Unexpected diff variant"),
|
||||
assert!(matches!(
|
||||
&list[0],
|
||||
Diff::InsertRows {
|
||||
sheet: 0,
|
||||
row: 5,
|
||||
count: 3
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -44,18 +44,14 @@ fn diff_invariant_insert_columns() {
|
||||
assert!(model.insert_columns(0, 2, 4).is_ok());
|
||||
let list = last_diff_list(&mut model);
|
||||
assert_eq!(list.len(), 1);
|
||||
match &list[0] {
|
||||
assert!(matches!(
|
||||
&list[0],
|
||||
Diff::InsertColumns {
|
||||
sheet,
|
||||
column,
|
||||
count,
|
||||
} => {
|
||||
assert_eq!(*sheet, 0);
|
||||
assert_eq!(*column, 2);
|
||||
assert_eq!(*count, 4);
|
||||
}
|
||||
_ => panic!("Unexpected diff variant"),
|
||||
sheet: 0,
|
||||
column: 2,
|
||||
count: 4
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -280,14 +276,14 @@ fn bulk_insert_rows_undo_redo() {
|
||||
// Check diff structure
|
||||
let list = last_diff_list(&mut model);
|
||||
assert_eq!(list.len(), 1);
|
||||
match &list[0] {
|
||||
Diff::InsertRows { sheet, row, count } => {
|
||||
assert_eq!(*sheet, 0);
|
||||
assert_eq!(*row, 3);
|
||||
assert_eq!(*count, 3);
|
||||
}
|
||||
_ => panic!("Expected InsertRows diff"),
|
||||
assert!(matches!(
|
||||
&list[0],
|
||||
Diff::InsertRows {
|
||||
sheet: 0,
|
||||
row: 3,
|
||||
count: 3
|
||||
}
|
||||
));
|
||||
|
||||
// Undo
|
||||
model.undo().unwrap();
|
||||
@@ -319,18 +315,14 @@ fn bulk_insert_columns_undo_redo() {
|
||||
// Check diff structure
|
||||
let list = last_diff_list(&mut model);
|
||||
assert_eq!(list.len(), 1);
|
||||
match &list[0] {
|
||||
assert!(matches!(
|
||||
&list[0],
|
||||
Diff::InsertColumns {
|
||||
sheet,
|
||||
column,
|
||||
count,
|
||||
} => {
|
||||
assert_eq!(*sheet, 0);
|
||||
assert_eq!(*column, 3);
|
||||
assert_eq!(*count, 3);
|
||||
}
|
||||
_ => panic!("Expected InsertColumns diff"),
|
||||
sheet: 0,
|
||||
column: 3,
|
||||
count: 3
|
||||
}
|
||||
));
|
||||
|
||||
// Undo
|
||||
model.undo().unwrap();
|
||||
@@ -601,12 +593,14 @@ fn bulk_operations_large_count() {
|
||||
// Check diff
|
||||
let list = last_diff_list(&mut model);
|
||||
assert_eq!(list.len(), 1);
|
||||
match &list[0] {
|
||||
Diff::InsertRows { count, .. } => {
|
||||
assert_eq!(*count, 100);
|
||||
}
|
||||
_ => panic!("Expected InsertRows diff"),
|
||||
assert!(matches!(
|
||||
&list[0],
|
||||
Diff::InsertRows {
|
||||
sheet: 0,
|
||||
row: 50,
|
||||
count: 100
|
||||
}
|
||||
));
|
||||
|
||||
// Undo and redo
|
||||
model.undo().unwrap();
|
||||
|
||||
@@ -2007,7 +2007,6 @@ impl UserModel {
|
||||
fn apply_undo_diff_list(&mut self, diff_list: &DiffList) -> Result<(), String> {
|
||||
let mut needs_evaluation = false;
|
||||
for diff in diff_list.iter().rev() {
|
||||
#[allow(deprecated)]
|
||||
match diff {
|
||||
Diff::SetCellValue {
|
||||
sheet,
|
||||
@@ -2087,47 +2086,6 @@ impl UserModel {
|
||||
self.model.cell_clear_all(*sheet, *row, *column)?;
|
||||
}
|
||||
}
|
||||
Diff::InsertRow { sheet, row } => {
|
||||
self.model.delete_rows(*sheet, *row, 1)?;
|
||||
needs_evaluation = true;
|
||||
}
|
||||
Diff::DeleteRow {
|
||||
sheet,
|
||||
row,
|
||||
old_data,
|
||||
} => {
|
||||
needs_evaluation = true;
|
||||
self.model.insert_rows(*sheet, *row, 1)?;
|
||||
let worksheet = self.model.workbook.worksheet_mut(*sheet)?;
|
||||
if let Some(row_data) = old_data.row.clone() {
|
||||
worksheet.rows.push(row_data);
|
||||
}
|
||||
worksheet.sheet_data.insert(*row, old_data.data.clone());
|
||||
}
|
||||
Diff::InsertColumn { sheet, column } => {
|
||||
self.model.delete_columns(*sheet, *column, 1)?;
|
||||
needs_evaluation = true;
|
||||
}
|
||||
Diff::DeleteColumn {
|
||||
sheet,
|
||||
column,
|
||||
old_data,
|
||||
} => {
|
||||
needs_evaluation = true;
|
||||
// inserts an empty column
|
||||
self.model.insert_columns(*sheet, *column, 1)?;
|
||||
// puts all the data back
|
||||
let worksheet = self.model.workbook.worksheet_mut(*sheet)?;
|
||||
for (row, cell) in &old_data.data {
|
||||
worksheet.update_cell(*row, *column, cell.clone())?;
|
||||
}
|
||||
// makes sure that the width and style is correct
|
||||
if let Some(col) = &old_data.column {
|
||||
let width = col.width * constants::COLUMN_WIDTH_FACTOR;
|
||||
let style = col.style;
|
||||
worksheet.set_column_width_and_style(*column, width, style)?;
|
||||
}
|
||||
}
|
||||
Diff::InsertRows { sheet, row, count } => {
|
||||
self.model.delete_rows(*sheet, *row, *count)?;
|
||||
needs_evaluation = true;
|
||||
@@ -2347,7 +2305,6 @@ impl UserModel {
|
||||
fn apply_diff_list(&mut self, diff_list: &DiffList) -> Result<(), String> {
|
||||
let mut needs_evaluation = false;
|
||||
for diff in diff_list {
|
||||
#[allow(deprecated)]
|
||||
match diff {
|
||||
Diff::SetCellValue {
|
||||
sheet,
|
||||
@@ -2404,30 +2361,6 @@ impl UserModel {
|
||||
} => self
|
||||
.model
|
||||
.set_cell_style(*sheet, *row, *column, new_value)?,
|
||||
Diff::InsertRow { sheet, row } => {
|
||||
self.model.insert_rows(*sheet, *row, 1)?;
|
||||
needs_evaluation = true;
|
||||
}
|
||||
Diff::DeleteRow {
|
||||
sheet,
|
||||
row,
|
||||
old_data: _,
|
||||
} => {
|
||||
self.model.delete_rows(*sheet, *row, 1)?;
|
||||
needs_evaluation = true;
|
||||
}
|
||||
Diff::InsertColumn { sheet, column } => {
|
||||
needs_evaluation = true;
|
||||
self.model.insert_columns(*sheet, *column, 1)?;
|
||||
}
|
||||
Diff::DeleteColumn {
|
||||
sheet,
|
||||
column,
|
||||
old_data: _,
|
||||
} => {
|
||||
self.model.delete_columns(*sheet, *column, 1)?;
|
||||
needs_evaluation = true;
|
||||
}
|
||||
Diff::InsertRows { sheet, row, count } => {
|
||||
self.model.insert_rows(*sheet, *row, *count)?;
|
||||
needs_evaluation = true;
|
||||
@@ -2614,6 +2547,4 @@ mod tests {
|
||||
assert_eq!(horizontal(&format!("{a}")), Ok(a));
|
||||
}
|
||||
}
|
||||
|
||||
// (batch diff tests moved to separate file)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#![allow(deprecated)]
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use bitcode::{Decode, Encode};
|
||||
@@ -19,7 +17,6 @@ pub(crate) struct ColumnData {
|
||||
}
|
||||
|
||||
#[derive(Clone, Encode, Decode)]
|
||||
#[allow(deprecated)]
|
||||
pub(crate) enum Diff {
|
||||
// Cell diffs
|
||||
SetCellValue {
|
||||
@@ -90,62 +87,6 @@ pub(crate) enum Diff {
|
||||
row: i32,
|
||||
old_value: Box<Option<Style>>,
|
||||
},
|
||||
/// **DEPRECATED**: Use `InsertRows` with count=1 instead.
|
||||
///
|
||||
/// This variant is kept for backward compatibility to handle old persisted diffs.
|
||||
/// New code should always use `InsertRows` even for single row insertions.
|
||||
#[deprecated(since = "0.5.0", note = "Use InsertRows with count=1 instead")]
|
||||
#[allow(dead_code)]
|
||||
#[allow(deprecated)]
|
||||
InsertRow {
|
||||
#[allow(deprecated)]
|
||||
sheet: u32,
|
||||
#[allow(deprecated)]
|
||||
row: i32,
|
||||
},
|
||||
/// **DEPRECATED**: Use `DeleteRows` with count=1 instead.
|
||||
///
|
||||
/// This variant is kept for backward compatibility to handle old persisted diffs.
|
||||
/// New code should always use `DeleteRows` even for single row deletions.
|
||||
#[deprecated(since = "0.5.0", note = "Use DeleteRows with count=1 instead")]
|
||||
#[allow(dead_code)]
|
||||
#[allow(deprecated)]
|
||||
DeleteRow {
|
||||
#[allow(deprecated)]
|
||||
sheet: u32,
|
||||
#[allow(deprecated)]
|
||||
row: i32,
|
||||
#[allow(deprecated)]
|
||||
old_data: Box<RowData>,
|
||||
},
|
||||
/// **DEPRECATED**: Use `InsertColumns` with count=1 instead.
|
||||
///
|
||||
/// This variant is kept for backward compatibility to handle old persisted diffs.
|
||||
/// New code should always use `InsertColumns` even for single column insertions.
|
||||
#[deprecated(since = "0.5.0", note = "Use InsertColumns with count=1 instead")]
|
||||
#[allow(dead_code)]
|
||||
#[allow(deprecated)]
|
||||
InsertColumn {
|
||||
#[allow(deprecated)]
|
||||
sheet: u32,
|
||||
#[allow(deprecated)]
|
||||
column: i32,
|
||||
},
|
||||
/// **DEPRECATED**: Use `DeleteColumns` with count=1 instead.
|
||||
///
|
||||
/// This variant is kept for backward compatibility to handle old persisted diffs.
|
||||
/// New code should always use `DeleteColumns` even for single column deletions.
|
||||
#[deprecated(since = "0.5.0", note = "Use DeleteColumns with count=1 instead")]
|
||||
#[allow(dead_code)]
|
||||
#[allow(deprecated)]
|
||||
DeleteColumn {
|
||||
#[allow(deprecated)]
|
||||
sheet: u32,
|
||||
#[allow(deprecated)]
|
||||
column: i32,
|
||||
#[allow(deprecated)]
|
||||
old_data: Box<ColumnData>,
|
||||
},
|
||||
InsertRows {
|
||||
sheet: u32,
|
||||
row: i32,
|
||||
|
||||
Reference in New Issue
Block a user