Skip to content

Commit 89a8cec

Browse files
authored
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>
1 parent 67b5ee1 commit 89a8cec

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

cli/src/native/snapshot.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ fn compact_tree(tree: &str, interactive: bool) -> String {
10301030
let mut keep = vec![false; lines.len()];
10311031

10321032
for (i, line) in lines.iter().enumerate() {
1033-
if line.contains("[ref=") || line.contains(": ") {
1033+
if line.contains("ref=") || line.contains(": ") {
10341034
keep[i] = true;
10351035
// Mark ancestors
10361036
let my_indent = count_indent(line);
@@ -1200,6 +1200,26 @@ mod tests {
12001200
assert!(result.contains("Hello"));
12011201
}
12021202

1203+
#[test]
1204+
fn test_compact_tree_radio_checkbox() {
1205+
// Radio/checkbox lines have attributes before ref (e.g. [checked=false, ref=e1])
1206+
// so "ref=" appears without a leading "[" — compact_tree must still keep them.
1207+
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";
1208+
let result = compact_tree(tree, true);
1209+
assert!(
1210+
result.contains("radio \"Single unit\""),
1211+
"radio should be kept"
1212+
);
1213+
assert!(
1214+
result.contains("checkbox \"I agree\""),
1215+
"checkbox should be kept"
1216+
);
1217+
assert!(
1218+
result.contains("button \"Submit\""),
1219+
"button should be kept"
1220+
);
1221+
}
1222+
12031223
#[test]
12041224
fn test_compact_tree_empty_interactive() {
12051225
let result = compact_tree("- generic\n", true);

0 commit comments

Comments
 (0)