Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions crates/buildtools/src/generate.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use gents::FileGroup;
use logisheets_rs::{
AsyncFuncResult, DisplayWindowRequest,
};
use logisheets_rs::{AsyncFuncResult, DisplayWindowRequest};

fn main() {
let path = "packages/web/src/bindings";
Expand Down
1 change: 1 addition & 0 deletions crates/controller/src/api/workbook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ impl Workbook {
value_changed: vec![],
cell_removed: vec![],
style_changed: vec![],
..Default::default()
};
}
self.controller.handle_async_calc_results(tasks, results)
Expand Down
23 changes: 22 additions & 1 deletion crates/controller/src/controller/executor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::{HashMap, HashSet};

use logisheets_base::{errors::BasicError, Addr, CellId, CubeId, RangeId, SheetId};
use logisheets_base::{errors::BasicError, Addr, CellId, ColId, CubeId, RangeId, RowId, SheetId};

use crate::{
async_func_manager::AsyncFuncManager,
Expand Down Expand Up @@ -42,6 +42,11 @@ pub struct Executor<'a> {
pub style_updated: HashSet<(SheetId, CellId)>,
pub dirty_vertices: HashSet<Vertex>,

pub row_inserted: Vec<(SheetId, RowId)>,
pub row_removed: Vec<(SheetId, RowId)>,
pub col_inserted: Vec<(SheetId, ColId)>,
pub col_removed: Vec<(SheetId, ColId)>,

pub sheet_updated: bool,
pub cell_updated: bool, // todo: updated celll
}
Expand Down Expand Up @@ -142,6 +147,10 @@ impl<'a> Executor<'a> {
result.status.field_render_manager = field_render_executor.manager;

result.status.navigator = nav_executor.nav;
result.row_inserted.extend(nav_executor.row_inserted);
result.row_removed.extend(nav_executor.row_removed);
result.col_inserted.extend(nav_executor.col_inserted);
result.col_removed.extend(nav_executor.col_removed);
result.status.range_manager = range_executor.manager;
result.status.cube_manager = cube_executor.manager;

Expand Down Expand Up @@ -200,6 +209,10 @@ impl<'a> Executor<'a> {
cell_updated,
sid_assigner: result.sid_assigner,
style_updated: result.style_updated,
row_inserted: result.row_inserted,
row_removed: result.row_removed,
col_inserted: result.col_inserted,
col_removed: result.col_removed,
})
}

Expand All @@ -220,6 +233,10 @@ impl<'a> Executor<'a> {
dirty_vertices,
sheet_updated,
cell_updated,
row_inserted,
row_removed,
col_inserted,
col_removed,
} = self;
let connector = CalcConnector {
range_manager: &status.range_manager,
Expand Down Expand Up @@ -265,6 +282,10 @@ impl<'a> Executor<'a> {
dirty_vertices: HashSet::new(),
sheet_updated,
cell_updated,
row_inserted,
row_removed,
col_inserted,
col_removed,
})
}

Expand Down
194 changes: 189 additions & 5 deletions crates/controller/src/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ mod executor;
pub mod status;
pub mod style;
use crate::edit_action::{
ActionEffect, CreateSheet, EditAction, PayloadsAction, RecalcCell, SheetCellId, StatusCode,
WorkbookUpdateType,
ActionEffect, CreateSheet, EditAction, PayloadsAction, RecalcCell, SheetCellId, SheetColId,
SheetRowId, StatusCode, WorkbookUpdateType,
};
use crate::errors::{Error, Result};
use crate::file_loader::load_file;
Expand Down Expand Up @@ -194,6 +194,10 @@ impl Controller {
cells_removed: HashSet::new(),
sid_assigner: &self.sid_assigner,
style_updated: HashSet::new(),
row_inserted: vec![],
row_removed: vec![],
col_inserted: vec![],
col_removed: vec![],
};
let result = executor.execute_and_calc(action.clone());
match result {
Expand Down Expand Up @@ -245,6 +249,27 @@ impl Controller {
cell_id: c.1,
})
.collect(),
row_inserted: result
.row_inserted
.into_iter()
.map(|(sheet_id, row_id)| SheetRowId { sheet_id, row_id })
.collect(),
row_removed: result
.row_removed
.into_iter()
.map(|(sheet_id, row_id)| SheetRowId { sheet_id, row_id })
.collect(),
col_inserted: result
.col_inserted
.into_iter()
.map(|(sheet_id, col_id)| SheetColId { sheet_id, col_id })
.collect(),
col_removed: result
.col_removed
.into_iter()
.map(|(sheet_id, col_id)| SheetColId { sheet_id, col_id })
.collect(),
..Default::default()
}
}
Err(e) => {
Expand Down Expand Up @@ -291,6 +316,10 @@ impl Controller {
cells_removed: HashSet::new(),
sid_assigner: &self.sid_assigner,
style_updated: HashSet::new(),
row_inserted: vec![],
row_removed: vec![],
col_inserted: vec![],
col_removed: vec![],
};

let result = executor.execute_and_calc(payloads_action);
Expand Down Expand Up @@ -335,6 +364,27 @@ impl Controller {
cell_id: c.1,
})
.collect(),
row_inserted: result
.row_inserted
.into_iter()
.map(|(sheet_id, row_id)| SheetRowId { sheet_id, row_id })
.collect(),
row_removed: result
.row_removed
.into_iter()
.map(|(sheet_id, row_id)| SheetRowId { sheet_id, row_id })
.collect(),
col_inserted: result
.col_inserted
.into_iter()
.map(|(sheet_id, col_id)| SheetColId { sheet_id, col_id })
.collect(),
col_removed: result
.col_removed
.into_iter()
.map(|(sheet_id, col_id)| SheetColId { sheet_id, col_id })
.collect(),
..Default::default()
}
}
Err(e) => {
Expand Down Expand Up @@ -372,6 +422,10 @@ impl Controller {
sid_assigner: &self.sid_assigner,
cells_removed: HashSet::new(),
style_updated: HashSet::new(),
row_inserted: vec![],
row_removed: vec![],
col_inserted: vec![],
col_removed: vec![],
};
if let Ok(result) = executor.calc() {
ActionEffect {
Expand Down Expand Up @@ -399,6 +453,7 @@ impl Controller {
cell_id: c.1,
})
.collect(),
..Default::default()
}
} else {
ActionEffect::from_err(1)
Expand Down Expand Up @@ -460,9 +515,9 @@ mod tests {

use crate::edit_action::{
Alignment, BlockLineNameFieldUpdate, BlockLineStyleUpdate, CellInput, CellStyleUpdate,
CreateBlock, CreateSheet, DeleteSheet, EditAction, EditPayload, EphemeralCellInput,
HorizontalAlignment, LineStyleUpdate, PayloadsAction, StatusCode, StyleUpdateType,
VerticalAlignment,
CreateBlock, CreateSheet, DeleteCols, DeleteRows, DeleteSheet, EditAction, EditPayload,
EphemeralCellInput, HorizontalAlignment, InsertCols, InsertRows, LineStyleUpdate,
PayloadsAction, StatusCode, StyleUpdateType, VerticalAlignment,
};

use super::Controller;
Expand Down Expand Up @@ -923,4 +978,133 @@ mod tests {
.unwrap();
assert!(matches!(cell.value, CellValue::Number(1.0)));
}

#[test]
fn insert_rows_action_effect() {
let mut wb = Controller::default();
let sheet_idx = 0;
let sheet_id = wb.get_sheet_id_by_idx(sheet_idx).unwrap();

let action = PayloadsAction {
payloads: vec![EditPayload::InsertRows(InsertRows {
sheet_idx,
start: 2,
count: 3,
})],
undoable: true,
init: false,
};
let result = wb.handle_action(EditAction::Payloads(action));

assert_eq!(result.row_inserted.len(), 3);
assert!(result.row_inserted.iter().all(|r| r.sheet_id == sheet_id));
assert!(result.row_removed.is_empty());
assert!(result.col_inserted.is_empty());
assert!(result.col_removed.is_empty());
}

#[test]
fn delete_rows_action_effect() {
let mut wb = Controller::default();
let sheet_idx = 0;
let sheet_id = wb.get_sheet_id_by_idx(sheet_idx).unwrap();

let action = PayloadsAction {
payloads: vec![EditPayload::DeleteRows(DeleteRows {
sheet_idx,
start: 1,
count: 2,
})],
undoable: true,
init: false,
};
let result = wb.handle_action(EditAction::Payloads(action));

assert_eq!(result.row_removed.len(), 2);
assert!(result.row_removed.iter().all(|r| r.sheet_id == sheet_id));
assert!(result.row_inserted.is_empty());
assert!(result.col_inserted.is_empty());
assert!(result.col_removed.is_empty());
}

#[test]
fn insert_cols_action_effect() {
let mut wb = Controller::default();
let sheet_idx = 0;
let sheet_id = wb.get_sheet_id_by_idx(sheet_idx).unwrap();

let action = PayloadsAction {
payloads: vec![EditPayload::InsertCols(InsertCols {
sheet_idx,
start: 0,
count: 2,
})],
undoable: true,
init: false,
};
let result = wb.handle_action(EditAction::Payloads(action));

assert_eq!(result.col_inserted.len(), 2);
assert!(result.col_inserted.iter().all(|c| c.sheet_id == sheet_id));
assert!(result.col_removed.is_empty());
assert!(result.row_inserted.is_empty());
assert!(result.row_removed.is_empty());
}

#[test]
fn delete_cols_action_effect() {
let mut wb = Controller::default();
let sheet_idx = 0;
let sheet_id = wb.get_sheet_id_by_idx(sheet_idx).unwrap();

let action = PayloadsAction {
payloads: vec![EditPayload::DeleteCols(DeleteCols {
sheet_idx,
start: 0,
count: 1,
})],
undoable: true,
init: false,
};
let result = wb.handle_action(EditAction::Payloads(action));

assert_eq!(result.col_removed.len(), 1);
assert!(result.col_removed.iter().all(|c| c.sheet_id == sheet_id));
assert!(result.col_inserted.is_empty());
assert!(result.row_inserted.is_empty());
assert!(result.row_removed.is_empty());
}

#[test]
fn mixed_insert_delete_action_effect() {
let mut wb = Controller::default();
let sheet_idx = 0;
let sheet_id = wb.get_sheet_id_by_idx(sheet_idx).unwrap();

// Insert 2 rows then delete 1 col in a single action
let action = PayloadsAction {
payloads: vec![
EditPayload::InsertRows(InsertRows {
sheet_idx,
start: 0,
count: 2,
}),
EditPayload::DeleteCols(DeleteCols {
sheet_idx,
start: 0,
count: 1,
}),
],
undoable: true,
init: false,
};
let result = wb.handle_action(EditAction::Payloads(action));

assert_eq!(result.row_inserted.len(), 2);
assert_eq!(result.col_removed.len(), 1);
assert!(result.row_inserted.iter().all(|r| r.sheet_id == sheet_id));
assert!(result.col_removed.iter().all(|c| c.sheet_id == sheet_id));
assert!(result.row_removed.is_empty());
assert!(result.col_inserted.is_empty());
}
}
39 changes: 17 additions & 22 deletions crates/controller/src/controller/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,35 +118,31 @@ impl<'a> StyleConverter<'a> {
pub fn convert_style(&self, raw_style: RawStyle) -> Style {
let fill = self.convert_fill(raw_style.fill);
let luminance = match &fill {
Fill::PatternFill(pf) => {
if let Some(color) = &pf.fg_color {
if let (Some(r), Some(g), Some(b)) =
(color.red, color.green, color.blue)
{
get_luminance(r, g, b)
} else {
255.
}
Fill::PatternFill(pf) => {
if let Some(color) = &pf.fg_color {
if let (Some(r), Some(g), Some(b)) = (color.red, color.green, color.blue) {
get_luminance(r, g, b)
} else {
255.
}
} else {
255.
}
Fill::GradientFill(gf) => {
if !gf.stops.is_empty() {
let stop = &gf.stops[0];
let color = &stop.color;
if let (Some(r), Some(g), Some(b)) =
(color.red, color.green, color.blue)
{
get_luminance(r, g, b)
} else {
255.
}
}
Fill::GradientFill(gf) => {
if !gf.stops.is_empty() {
let stop = &gf.stops[0];
let color = &stop.color;
if let (Some(r), Some(g), Some(b)) = (color.red, color.green, color.blue) {
get_luminance(r, g, b)
} else {
255.
}
} else {
255.
}
};
}
};
Style {
font: self.convert_font(raw_style.font, luminance),
fill,
Expand Down Expand Up @@ -412,4 +408,3 @@ mod tests {
println!("{:?}", result.rgb.unwrap())
}
}

Loading
Loading