wip: fix area calculation bug

This commit is contained in:
Jeremy Wall 2025-02-07 19:16:57 -05:00
parent 8dd6f6d614
commit e798350cd2
2 changed files with 15 additions and 16 deletions

View File

@ -227,13 +227,7 @@ impl Book {
} }
pub fn clear_cell_range(&mut self, sheet: u32, start: Address, end: Address) -> Result<()> { pub fn clear_cell_range(&mut self, sheet: u32, start: Address, end: Address) -> Result<()> {
let area = Area { let area = calculate_area(sheet, start, end);
sheet,
row: start.row as i32,
column: start.col as i32,
width: (end.row - start.row) as i32,
height: (end.col - end.row) as i32,
};
self.model self.model
.range_clear_contents(&area) .range_clear_contents(&area)
.map_err(|s| anyhow!("Unable to clear cell contents {}", s))?; .map_err(|s| anyhow!("Unable to clear cell contents {}", s))?;
@ -254,13 +248,7 @@ impl Book {
} }
pub fn clear_cell_range_all(&mut self, sheet: u32, start: Address, end: Address) -> Result<()> { pub fn clear_cell_range_all(&mut self, sheet: u32, start: Address, end: Address) -> Result<()> {
let area = Area { let area = calculate_area(sheet, start, end);
sheet,
row: start.row as i32,
column: start.col as i32,
width: (end.row - start.row) as i32,
height: (end.col - end.row) as i32,
};
self.model.range_clear_all(&area) self.model.range_clear_all(&area)
.map_err(|s| anyhow!("Unable to clear cell contents {}", s))?; .map_err(|s| anyhow!("Unable to clear cell contents {}", s))?;
Ok(()) Ok(())
@ -584,6 +572,17 @@ impl Book {
} }
} }
fn calculate_area(sheet: u32, start: Address, end: Address) -> Area {
let area = Area {
sheet,
row: start.row as i32,
column: start.col as i32,
height: (end.row - start.row + 1) as i32,
width: (end.col - start.col + 1) as i32,
};
area
}
impl Default for Book { impl Default for Book {
fn default() -> Self { fn default() -> Self {
let mut book = let mut book =

View File

@ -131,7 +131,7 @@ impl<'ws> AppState<'ws> {
} }
} }
// TODO(jwall): This should probably move to a different module. // TODO(jwall): Should we just be using `Area` for this?.
/// The Address in a Table. /// The Address in a Table.
#[derive(Debug, PartialEq, PartialOrd, Ord, Eq, Clone)] #[derive(Debug, PartialEq, PartialOrd, Ord, Eq, Clone)]
pub struct Address { pub struct Address {
@ -539,7 +539,7 @@ impl<'ws> Workspace<'ws> {
self.handle_numeric_prefix(d); self.handle_numeric_prefix(d);
} }
KeyCode::Char('D') => { KeyCode::Char('D') => {
if let Some((start, end)) = self.state.range_select.get_range() { if let Some((start, end)) = dbg!(self.state.range_select.get_range()) {
self.book.clear_cell_range_all( self.book.clear_cell_range_all(
self.state self.state
.range_select .range_select