Skip to content

Records an undo step for a change of the current layer, colour, lineweight or linetype - #3555

Merged
HakanSeven12 merged 2 commits into
HakanSeven12:mainfrom
travisjhughes:undo-current-properties
Nov 24, 2026
Merged

HakanSeven12 merged 2 commits into
HakanSeven12:mainfrom
travisjhughes:undo-current-properties

Conversation

@travisjhughes

@travisjhughes travisjhughes commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Change summary

With nothing selected, the layer, colour, lineweight and linetype controls of the Properties palette and of the ribbon set the current value of the drawing ($CLAYER, $CECOLOR, $CELWEIGHT, $CELTYPE). That change added no undo step.

So UNDO after such a change did two wrong things: it kept the new value, and it took back the step before it. A user who drew a line, changed the current layer and pressed Ctrl+Z lost the line and kept the layer.

The reference application takes back each of the four changes with UNDO (tested there by hand).

With this change each of the four is one undo step.

What specifically changed

Two commits: the fix, then its test.

  • src/app/update/command/properties.rs: on_ribbon_layer_changed, on_ribbon_color_changed, on_ribbon_lineweight_changed and on_ribbon_linetype_changed call push_undo_snapshot before they change the header. The Properties palette calls the same functions when nothing is selected.
  • src/app/update/dispatch.rs, Message::PropLwChanged: with nothing selected it wrote the header itself. It now calls on_ribbon_lineweight_changed, as the other three palette messages do.
  • src/app/undo_sweep_tests.rs: current_value_cases (8 cases: the four values, from the palette and from the ribbon) and the test every_change_of_a_current_value_is_undone_and_redone_exactly.

Why

  • The user loses work that they did not want to undo, and has no sign of the cause.
  • The undo sweep tested these messages only with an object selected.

Testing

On main 32e30c8b3.

  • New test (1, with 8 cases): each case must add one undo step, UNDO must give back the document exactly (as a DXF save writes it), and REDO must give the changed document again.
  • The test fails without the fix, for all 8 cases: "Nothing selected: palette layer: 0 undo steps" and "UNDO: line 135 (after "8"): "0", then "Walls"".
  • Before and after (cargo test --workspace --locked --no-fail-fast, cargo check --workspace --all-targets, clippy, the wasm32 check, rustfmt on the changed files, the golden file): 7,882 passed and 0 failed before; 7,883 passed and 0 failed after. The 1 new test is the only difference. Warnings, the wasm32 check, clippy, rustfmt and the golden file are the same.
  • Fault injection with cargo mutants on the diff: 20 mutants, all 20 did not compile, so the run says nothing.
  • By hand, put back after the run: with only the old lineweight handler of the palette back, the case "palette lineweight" fails and the other 7 pass.

Not covered

  • The typed forms have the same fault and are not changed here: CLAYER Walls, -LAYER S Walls, CECOLOR 1 and -LINETYPE S Continuous each add 0 undo steps (I ran them through the same sweep check). They set the header in other functions.
  • The other ways to set the current layer: "Set current" in the layer palette, LAYMCUR, a restored layer state, and a plugin.
  • Confirmation on the screen. The test sends the messages of the palette and the ribbon. I did not use the controls in the app.

Impact to Contributors

None.

#3553 (the undo record guard) is built on this branch, so the two can merge in either order.

Co-Authored-By: Claude

…eight or linetype

With nothing selected, the ribbon and the Properties palette set the
current value of the drawing and added no undo step. UNDO then kept the
new value and took back the step before it.

The four functions now call push_undo_snapshot before the change. The
lineweight message of the palette calls on_ribbon_lineweight_changed, as
the other three palette messages call their functions.

Co-Authored-By: Claude
8 cases in the undo sweep: the current layer, colour, lineweight and
linetype, from the Properties palette and from the ribbon, with nothing
selected.

Co-Authored-By: Claude
@HakanSeven12
HakanSeven12 merged commit e30377e into HakanSeven12:main Nov 24, 2026
6 checks passed
@travisjhughes
travisjhughes deleted the undo-current-properties branch November 24, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants