From 89a8ceccf719d93df1224dc81f85d2015c2dab4f Mon Sep 17 00:00:00 2001 From: Chris Tate Date: Wed, 25 Mar 2026 11:40:19 -0700 Subject: [PATCH] fix: retain radio/checkbox elements in compact snapshot tree (#1008) compact_tree() checked for "[ref=" to identify lines worth keeping, but radio and checkbox elements render as e.g. [checked=false, ref=e1] where the "[" opens before "checked=", not "ref=". Dropping the leading bracket so the check is just "ref=" fixes the match for all elements with refs. Fixes #1006 Co-authored-by: ctate <366502+ctate@users.noreply.github.com> --- cli/src/native/snapshot.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/cli/src/native/snapshot.rs b/cli/src/native/snapshot.rs index 77c554f..02db790 100644 --- a/cli/src/native/snapshot.rs +++ b/cli/src/native/snapshot.rs @@ -1030,7 +1030,7 @@ fn compact_tree(tree: &str, interactive: bool) -> String { let mut keep = vec![false; lines.len()]; for (i, line) in lines.iter().enumerate() { - if line.contains("[ref=") || line.contains(": ") { + if line.contains("ref=") || line.contains(": ") { keep[i] = true; // Mark ancestors let my_indent = count_indent(line); @@ -1200,6 +1200,26 @@ mod tests { assert!(result.contains("Hello")); } + #[test] + fn test_compact_tree_radio_checkbox() { + // Radio/checkbox lines have attributes before ref (e.g. [checked=false, ref=e1]) + // so "ref=" appears without a leading "[" — compact_tree must still keep them. + let tree = "- form\n - radio \"Single unit\" [checked=false, ref=e1]\n - checkbox \"I agree\" [checked=false, ref=e2]\n - button \"Submit\" [ref=e3]\n"; + let result = compact_tree(tree, true); + assert!( + result.contains("radio \"Single unit\""), + "radio should be kept" + ); + assert!( + result.contains("checkbox \"I agree\""), + "checkbox should be kept" + ); + assert!( + result.contains("button \"Submit\""), + "button should be kept" + ); + } + #[test] fn test_compact_tree_empty_interactive() { let result = compact_tree("- generic\n", true);