diff --git a/backend/src/grid.rs b/backend/src/grid.rs index b5bef38..ed969a4 100644 --- a/backend/src/grid.rs +++ b/backend/src/grid.rs @@ -23,8 +23,13 @@ impl Grid { &mut self, cell_ref: CellRef, raw_val: String, + do_propagation: bool, + force_propagation: bool, ) -> Result, String> { - if self.cells.contains_key(&cell_ref) && self.cells[&cell_ref].raw() == raw_val { + if self.cells.contains_key(&cell_ref) + && self.cells[&cell_ref].raw() == raw_val + && !force_propagation + { return Ok(Vec::new()); } @@ -43,7 +48,14 @@ impl Grid { if self.cells.contains_key(&cell_ref) { updated_cells = self - .update_exisiting_cell(raw_val, eval, precs, cell_ref)? + .update_exisiting_cell( + raw_val, + eval, + precs, + cell_ref, + do_propagation, + force_propagation, + )? .into_iter() .chain(updated_cells) .collect(); @@ -156,6 +168,8 @@ impl Grid { new_eval: Eval, new_precs: HashSet, cell_ref: CellRef, + do_propagation: bool, + force_propagation: bool, ) -> Result, String> { let (old_precs, old_eval) = match self.cells.get_mut(&cell_ref) { Some(cell) => { @@ -197,7 +211,7 @@ impl Grid { cell.set_precs(new_precs); cell.set_eval(new_eval); - if eval_changed { + if (eval_changed && do_propagation) || force_propagation { self.propagate(cell_ref) } else { Ok(Vec::new()) diff --git a/backend/src/main.rs b/backend/src/main.rs index c6993da..3e7a1ef 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -62,8 +62,16 @@ async fn accept_connection(stream: TcpStream) { MsgType::Set => { let Some(cell_ref) = req.cell else { continue }; let Some(raw) = req.raw else { continue }; + let Some(config) = req.eval_config else { + continue; + }; - match grid.update_cell(cell_ref.clone(), raw.to_owned()) { + match grid.update_cell( + cell_ref.clone(), + raw.to_owned(), + config.do_propagation, + config.force_propagation, + ) { Ok(updates) => { let mut msgs = Vec::new(); @@ -75,6 +83,7 @@ async fn accept_connection(stream: TcpStream) { raw: Some(cell.raw()), eval: Some(cell.eval()), bulk_msgs: None, + eval_config: None, }); } } @@ -88,6 +97,7 @@ async fn accept_connection(stream: TcpStream) { cell: None, raw: None, eval: None, + eval_config: None, bulk_msgs: Some(msgs), msg_type: MsgType::Bulk, }; @@ -103,6 +113,7 @@ async fn accept_connection(stream: TcpStream) { cell: Some(cell_ref), raw: Some(e.to_string()), eval: None, + eval_config: None, bulk_msgs: None, }; let _ = write diff --git a/backend/src/messages.rs b/backend/src/messages.rs index bba7c6c..04b16b1 100644 --- a/backend/src/messages.rs +++ b/backend/src/messages.rs @@ -11,11 +11,18 @@ pub enum MsgType { Bulk, } +#[derive(Serialize, Deserialize, Debug)] +pub struct EvalConfig { + pub do_propagation: bool, + pub force_propagation: bool, +} + #[derive(Serialize, Deserialize, Debug)] pub struct LeadMsg { pub msg_type: MsgType, pub cell: Option, pub raw: Option, pub eval: Option, + pub eval_config: Option, pub bulk_msgs: Option>, } diff --git a/frontend/src/lib/components/grid/cell.svelte b/frontend/src/lib/components/grid/cell.svelte index dbcf0e4..f02c590 100644 --- a/frontend/src/lib/components/grid/cell.svelte +++ b/frontend/src/lib/components/grid/cell.svelte @@ -55,11 +55,22 @@ style="width: {width}; height: {height}" class="relative rounded-none p-1 !transition-none delay-0 duration-0 focus:z-20 focus:shadow-[0_0_0_1px_var(--color-primary)] focus:outline-none" + bind:value={ + () => { + return cell?.raw_val ?? ''; + }, + (v) => { + cell = { + val: cell?.val, + raw_val: v + }; + } + } onblur={(e) => { - cell = { - val: cell?.val, - raw_val: (e.target as HTMLInputElement).value - }; + // cell = { + // val: cell?.val, + // raw_val: (e.target as HTMLInputElement).value + // }; stopediting(); }} /> diff --git a/frontend/src/lib/components/grid/grid.svelte b/frontend/src/lib/components/grid/grid.svelte index d811d5e..46c16db 100644 --- a/frontend/src/lib/components/grid/grid.svelte +++ b/frontend/src/lib/components/grid/grid.svelte @@ -1,6 +1,15 @@ -
- - getActiveCell().raw_val, (raw) => setActiveCellRaw(raw)} - class="relative w-[200px] rounded-none p-1 !transition-none delay-0 duration-0 - focus:z-20 focus:shadow-[0_0_0_1px_var(--color-primary)] focus:outline-none" - > +
+
+ + getActiveCell().raw_val, (raw) => setActiveCellRaw(raw)} + class="relative w-[200px] pl-8" + > +
startEditing(i, j)} - stopediting={stopEditing} + stopediting={() => stopEditing(i, j)} onmousedown={(e) => { handleCellInteraction(i, j, e); }} - bind:cell={() => getCell(i, j), (v) => setCell(i, j, v)} + bind:cell={ + () => getCell(i, j), + (v) => setCell(i, j, v, { do_propagation: false, force_propagation: false }) + } active={active_cell !== null && active_cell[0] === i && active_cell[1] === j} /> {/each} diff --git a/frontend/src/lib/components/grid/messages.ts b/frontend/src/lib/components/grid/messages.ts index 794b8d1..2d7fb39 100644 --- a/frontend/src/lib/components/grid/messages.ts +++ b/frontend/src/lib/components/grid/messages.ts @@ -3,6 +3,7 @@ interface LeadMsg { cell?: CellRef; raw?: string; eval?: Eval; + eval_config?: EvalConfig; bulk_msgs?: Array; } @@ -31,6 +32,11 @@ interface LeadErr { title: string; } +interface EvalConfig { + do_propagation: boolean; + force_propagation: boolean; +} + // Tagged union type Eval = | { literal: Literal }