Skip to content

Commit 532dc30

Browse files
authored
Fix checkboxes by using deterministic widget IDs instead of random ones to make the diffing easier (#3457)
* Move diffing to trait * Add deterministic widget ids * Cleanup
1 parent 90c91db commit 532dc30

File tree

4 files changed

+245
-50
lines changed

4 files changed

+245
-50
lines changed

editor/src/messages/layout/layout_message_handler.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use graphene_std::raster::color::Color;
55
use graphene_std::text::Font;
66
use graphene_std::vector::style::{FillChoice, GradientStops};
77
use serde_json::Value;
8+
use std::collections::HashMap;
89

910
#[derive(ExtractField)]
1011
pub struct LayoutMessageContext<'a> {
@@ -470,10 +471,18 @@ impl LayoutMessageHandler {
470471
fn diff_and_send_layout_to_frontend(
471472
&mut self,
472473
layout_target: LayoutTarget,
473-
new_layout: Layout,
474+
mut new_layout: Layout,
474475
responses: &mut VecDeque<Message>,
475476
action_input_mapping: &impl Fn(&MessageDiscriminant) -> Option<KeysGroup>,
476477
) {
478+
// Step 1: Collect CheckboxId mappings from new layout
479+
let mut checkbox_map = HashMap::new();
480+
new_layout.collect_checkbox_ids(layout_target, &mut Vec::new(), &mut checkbox_map);
481+
482+
// Step 2: Replace all IDs in new layout with deterministic ones
483+
new_layout.replace_widget_ids(layout_target, &mut Vec::new(), &checkbox_map);
484+
485+
// Step 3: Diff with deterministic IDs
477486
let mut widget_diffs = Vec::new();
478487

479488
self.layouts[layout_target as usize].diff(new_layout, &mut Vec::new(), &mut widget_diffs);

0 commit comments

Comments
 (0)