fix(task-21): layout_create, layout_set_current and viewport_create mark the headless document dirty — the close refusal and the saved row now see them, and each gets an undo step

document_close's promise (never drop unsaved work unless told to) and the
`saved` row of document_list are only as good as _DocState.dirty, and three
headless mutators never set it: a new layout tab, the $TILEMODE / active
layout write, and a paper-space VIEWPORT all changed the file yet closed
without refusal, reported discarded_changes: False, and were absent on disk.
COM refused the same sequence (Saved is AutoCAD's DBMOD), so the two engines
disagreed. Each now calls _mark_dirty() after its write, which also pushes
the undo snapshot every other mutator already has.

The regression test runs the save -> mutate -> list/close/undo/redo -> close
with save sequence for all three and checks the change reached the file.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FKFStjEFzpGyLq5bMpWxTd
This commit is contained in:
Umut CAN
2026-09-17 23:37:21 +03:00
co-authored by Claude Opus 5
parent b1c93cdd2a
commit 31daac022f
2 changed files with 93 additions and 0 deletions
+6
View File
@@ -2035,6 +2035,7 @@ class EzdxfBackend(AutoCADBackend):
if existing is not None:
return {"ok": False, "error": f"Layout already exists: {existing}"}
doc.layouts.new(wanted)
self._mark_dirty()
return {"ok": True, "layout": wanted}
return await self._async(_sync)
@@ -2056,6 +2057,10 @@ class EzdxfBackend(AutoCADBackend):
# Stored in the canonical spelling so _msp and _resync_space
# compare against one form.
self._current_space = resolved
# $TILEMODE and the active-layout binding are persisted state:
# the file on disk differs from the document after this, so the
# close refusal and the ``saved`` row must know about it.
self._mark_dirty()
return {"ok": True, "current": resolved}
return await self._async(_sync)
@@ -2273,6 +2278,7 @@ class EzdxfBackend(AutoCADBackend):
view_center_point=(view_center_x, view_center_y),
view_height=view_height,
)
self._mark_dirty()
return {
"ok": True,
"handle": viewport.dxf.handle,