Skip to content

Double-click the margin to create and edit a header or footer (#960) - #1144

Merged
echelon merged 4 commits into
storytold:mainfrom
dkhlapov:issue-960-header-double-click
Oct 14, 2026
Merged

echelon merged 4 commits into
storytold:mainfrom
dkhlapov:issue-960-header-double-click

Conversation

@dkhlapov

@dkhlapov dkhlapov commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

#960: double-click the margin to create and edit a header or footer

Closes #960. In Print Layout, double-clicking the top or bottom margin of a page now creates the header or footer that page shows, if needed, and edits it, as in Word. Different first page and odd/even pages are respected. Before, the double-click only worked when a header already existed.

What changed:

  • Layout: each page records which header/footer it shows, even when there is none (header_footer_zone).
  • Commands: insert.editHeader / insert.editFooter take an optional {"page"} for agents. This also fixes editing the wrong header on a "Different First Page" page. An out-of-range page is an error.
  • Closing: insert.closeHeader removes a newly created header or footer that is still empty, so the docx stays clean.
  • On a later section's page: a new header goes into that page's section.

Tests:

  • edit_header_on_a_page_creates_its_slot (engine: default, first-page and even-page cases, a clean round-trip, out-of-range pages).
  • double_click_margin_creates_header_and_footer (kittest).
  • cargo xtask ci passes.

🤖 Generated with Claude Code

… footer

Double-clicking the top or bottom margin in Print Layout now edits the
header/footer that page shows, creating it (first page, even page or
default slot) when the page has none. insert.editHeader/editFooter take
{"page"}; insert.closeHeader takes away a created one left empty.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dkhlapov
dkhlapov force-pushed the issue-960-header-double-click branch from 57182a0 to 3e52116 Compare October 13, 2026 00:16
@dkhlapov dkhlapov changed the title WIP: [WordCraft] Double click on top of page to create header (#960) Double-click the margin to create and edit a header or footer (#960) Oct 13, 2026
@dkhlapov
dkhlapov marked this pull request as ready for review October 13, 2026 00:16
…ted edit

insert.editHeader/editFooter stay pure and hand creation to the new
mutating insert.createHeader/createFooter; closeHeader removes empty new
ones through insert.removeEmptyHeaders. An empty new header is never
saved, one an undo brings back goes on the next close, and a new header
goes in the first section (linked to later ones, as in Word).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dkhlapov

Copy link
Copy Markdown
Contributor Author

Review follow-ups (a12b772):

  • Making a header or footer by double-click is now a real edit. It goes through new mutating commands insert.createHeader/insert.createFooter/insert.removeEmptyHeaders, so it's refused in a protected document, undoable and recorded in macros. Going into an existing header stays pure.
  • Saving leaves out a new header that's still empty. A header brought back by Undo is cleaned up on the next close.
  • A new header on a later section's page goes into the first section, so it links to every section like Word's default.
  • Tests: creating_a_header_is_an_undoable_protected_edit, an_empty_new_header_is_never_saved and new_header_links_to_previous_and_even_pages_edit_what_they_show. Full CI passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dpkruse

dpkruse commented Oct 14, 2026

Copy link
Copy Markdown

Tested on Windows 11 with a letter that uses Different First Page: a logo and contact details in a borderless 3-column table in the first-page header, and a "Page N" default header on later pages.

Before (0.7.0): double-clicking page 1's header put the caret in the default header, so typing never appeared on page 1.
With this PR (head a3dc2e6, built locally): double-clicking page 1's header edits the first-page header. I typed into one of its table cells and the text saved into the first header part. ✅

Still open (maybe out of scope here): Insert › Header › Edit Header on the ribbon still opens the default header when the cursor is on page 1, so nothing seems to happen and the typing goes into a header that isn't shown. Word opens the first-page header in that case. Headless repro on this branch, with any Different First Page document:

wordcraft-cli run --file test.docx --cmd insert.editHeader --cmd 'text.insert={"text":"X"}' --save out.docx

X lands in the w:type="default" header. With insert.editHeader={"page":0} it lands in first, as expected.

Happy to file the ribbon case as a separate issue if that's easier.

# Conflicts:
#	ROADMAP.md
@echelon
echelon merged commit 44086d0 into storytold:main Oct 14, 2026
0 of 3 checks passed
@echelon

echelon commented Oct 14, 2026

Copy link
Copy Markdown
Member

Thanks for the contribution, @dkhlapov! This has landed in main. If you haven't already, come join us on Discord: https://discord.gg/artcraft

@dkhlapov
dkhlapov deleted the issue-960-header-double-click branch October 15, 2026 19:28
ucin added a commit to rsysapp/wordcraft that referenced this pull request Oct 17, 2026
- Recovery (upstream storytold#518) now expects a crash-recovery copy to keep pictures
  and the parts kept verbatim, so Document::media and ::passthrough serialise
  again (our NamedBytes maps get Serialize and Deserialize; the source package
  of a document read from Word travels with them, so a recovered document
  still compares equal and can still be saved by keeping its file).
- Upstream's new header test (storytold#1144) edits the default header from an even
  page, which its layout draws there. Our layout draws an even page's header
  from the even part only, as Word does (W3 fix 5, tested in edit_mode.rs), so
  the test now says an even page shows none.
- inspect_save: upstream's writer now writes commentsIds.xml and
  commentsExtensible.xml, which the inspector reads as plain XML parts, so a
  regenerated save of a comment reports them. The embed's edit mode adds no
  comments and saves through the preserving writer; the inspector is not
  loosened, the three regenerating-save tests name the two parts.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.

[WordCraft] Double click on top of page to create header

3 participants