Skip to content

Commit

Permalink
change old format operation
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfig committed Dec 19, 2024
1 parent da179ee commit 556af14
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions quadratic-core/src/values/from_js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ use chrono::{NaiveDate, NaiveDateTime, NaiveTime};

use crate::{
controller::operations::operation::Operation,
grid::{formatting::CellFmtArray, NumericFormat, NumericFormatKind, Sheet},
Pos, RunLengthEncoding,
grid::{
formats::{FormatUpdate, SheetFormatUpdates},
NumericFormat, NumericFormatKind, Sheet,
},
A1Selection, Pos,
};

use super::CellValue;
Expand Down Expand Up @@ -48,7 +51,6 @@ impl CellValue {
sheet: &mut Sheet,
) -> Result<(CellValue, Vec<Operation>)> {
let mut ops = vec![];
let sheet_rect = crate::SheetRect::single_pos(pos, sheet.id);

let cell_value = match js_type {
"text" => {
Expand All @@ -73,12 +75,15 @@ impl CellValue {
.numeric_format
.set(pos, Some(numeric_format.clone()));

ops.push(Operation::SetCellFormats {
sheet_rect,
attr: CellFmtArray::NumericFormat(RunLengthEncoding::repeat(
Some(numeric_format),
1,
)),
ops.push(Operation::SetCellFormatsA1 {
sheet_id: sheet.id,
formats: SheetFormatUpdates::from_selection(
&A1Selection::from_single_cell(pos.to_sheet_pos(sheet.id)),
FormatUpdate {
numeric_format: Some(Some(numeric_format.clone())),
..Default::default()
},
),
});

// We no longer automatically set numeric decimals for
Expand All @@ -97,12 +102,15 @@ impl CellValue {
.formats
.numeric_format
.set(pos, Some(numeric_format.clone()));
ops.push(Operation::SetCellFormats {
sheet_rect,
attr: CellFmtArray::NumericFormat(RunLengthEncoding::repeat(
Some(numeric_format),
1,
)),
ops.push(Operation::SetCellFormatsA1 {
sheet_id: sheet.id,
formats: SheetFormatUpdates::from_selection(
&A1Selection::from_single_cell(pos.to_sheet_pos(sheet.id)),
FormatUpdate {
numeric_format: Some(Some(numeric_format.clone())),
..Default::default()
},
),
});

CellValue::Number(number)
Expand Down

0 comments on commit 556af14

Please sign in to comment.