Skip to content

Field codes: show, edit, update, unlink, lock and step through fields like Word - #349

Merged
echelon merged 2 commits into
storytold:mainfrom
vangel76:feat/339-field-codes
Oct 11, 2026
Merged

echelon merged 2 commits into
storytold:mainfrom
vangel76:feat/339-field-codes

Conversation

@vangel76

@vangel76 vangel76 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

What changed

Word's set of field tools, everything as commands:

  • Show field codes: view.fieldCodes {"value"?: bool} (Alt+F9) shows every field's code in place of its result, as { PAGE } on light grey, like Word's field shading. fields.toggleCode (Shift+F9) switches only the field(s) in the selection. The per-field toggle is a flag on the field (code). It is undoable, never written to files and left out of saved JSON when off.
  • Editing codes: a field is a single object in our model, so the caret can't go inside its code. Instead there's a small Field code popup backed by fields.setCode {"code"}. It sets the instruction and updates fields so the result follows. The popup opens when you double-click a field that shows its code, choose right-click › Edit Field…, or run fields.setCode from the UI without a code. Scripts and agents get an error, never a dialog. I picked this over true inline editing: it needs no new caret or selection model inside an object, and it works the same for every field type.
  • Ctrl+F9 (insert.field without instr) opens Columns, Symbol and Field dialogs #335's Field dialog (now on main), whose Field Codes view takes a typed code. Word inserts an empty { } and puts the caret inside, which our object model can't do yet.
  • F9 (references.updateFields) updates fields as before. The selected fields that were showing their code now show their result again.
  • fields.unlink (Ctrl+Shift+F9) replaces the selected fields with their current text in one undoable step. PAGE/NUMPAGES take their value from the current layout. A range field (e.g. a Zotero citation) loses its markers and keeps its content.
  • fields.lock / fields.unlock (Ctrl+F11 / Ctrl+Shift+F11) set the field's locked flag, and updates skip locked fields. This already round-trips to DOCX as w:fldLock on w:fldChar/w:fldSimple (reader and writer checked, covered by the existing roundtrip test).
  • fields.next / fields.previous (F11 / Shift+F11) select the next or previous field and wrap around.
  • fields.selected is a read-only command that lists the fields in the selection (instruction, locked, range, code), so agents can inspect them.
  • Right-click on a field: Update Field, Edit Field…, Toggle Field Codes. Edit Field… opens the code popup for the selected field (Columns, Symbol and Field dialogs #335's Field dialog is for new fields).
  • F11 is now a recognised key (keys.rs) and also works when the canvas isn't focused.
  • New strings are translated in all 9 catalogs (es, et, ja, pt-br, sr, sr-latn, uk, zh-hans, zh-hant). The parity catalog gains 8 field features (410/442, 92.8%), and docs/ui-parity.md, docs/gaps.md and ROADMAP.md are updated.

Limitation: range fields (citation ADDIN fields) keep showing their result in code view. Lock, unlock, unlink, edit code and next/previous do work on them.

Shortcuts

Keys Command What it does
Alt+F9 view.fieldCodes Show all field codes / results
Shift+F9 fields.toggleCode Toggle codes for the selected field(s)
F9 references.updateFields Update fields; selected ones show results again
Ctrl+F9 insert.field New field (opens the Field dialog, #335)
Ctrl+Shift+F9 fields.unlink Replace fields with their text
Ctrl+F11 fields.lock Lock fields
Ctrl+Shift+F11 fields.unlock Unlock fields
F11 / Shift+F11 fields.next / fields.previous Select next / previous field

Note for #338 (keyboard shortcuts): that PR lists Shift+F9, Alt+F9, Ctrl+Shift+F9 and F11 as "skipped — no command yet". These commands now exist, so whichever PR merges second should drop them from that list. Both PRs add a key to key_name in keys.rs (F11 here, F2/F4 there), which may cause a small merge conflict.

Testing

  • cmd::fields::tests::field_codes_show_in_place_of_results: Alt+F9 draws { AUTHOR }/{ TITLE } in place of the results; Shift+F9 flips only the selected field; F9 shows the result again; undo of the toggle.
  • cmd::fields::tests::edit_lock_unlink_and_walk_fields: F11/Shift+F11 walk the fields and wrap; setCode changes the instruction and the result; a locked field keeps its result through an update and an unlocked one changes; unlink turns the field into text and Undo brings it back; with no field selected the commands return an error and add no undo step.
  • ui-egui field_code_dialogs_open_for_users_only: Ctrl+F9 opens the Field dialog; Edit Field opens the popup prefilled with the selected field's code; programmatic calls error without a dialog.
  • cargo test passes for doc, layout, docx, docbin, pdf, engine (including hostile_params_never_panic) and ui-egui. cargo clippy --all-targets -D warnings passes on those crates, cargo fmt is clean, and cargo xtask layers, assets, wasm and parity all pass.
  • Headless ui_shot: with Alt+F9, "Page { PAGE } of { NUMPAGES }, written on { DATE @ "MMMM d, yyyy" }" draws on grey shading.

Fixes #339

🤖 Generated with Claude Code

@vangel76
vangel76 force-pushed the feat/339-field-codes branch 3 times, most recently from 3243236 to f82e414 Compare October 10, 2026 22:02
@vangel76

Copy link
Copy Markdown
Contributor Author

Rebased onto main after #335 (Columns, Symbol and Field dialogs) merged. Behaviour change: insert.field without a code (Ctrl+F9, Insert › Field…) now opens #335's Field dialog instead of this PR's field-code popup, since both claimed the same command; the popup stays for Edit Field… / fields.setCode / double-click. Test and PR description updated. Duplicate catalog keys ("Field Codes", "Field codes:") now come from #335's entries.

@vangel76
vangel76 force-pushed the feat/339-field-codes branch from f82e414 to fc61600 Compare October 10, 2026 23:15
@vangel76

Copy link
Copy Markdown
Contributor Author

Rebased onto main (after #315/#308/#294). ViewState keeps main's hide_ink/draw next to field_codes; revision tables and the ROADMAP progress log keep both sides. Main's new Estonian catalog got the 9 new field strings. docs/parity-checklist.md regenerated: 410/442 (92.8%); PR body updated.

@vangel76
vangel76 force-pushed the feat/339-field-codes branch 2 times, most recently from cfba122 to 7cc3f1c Compare October 10, 2026 23:58
Show field codes instead of results with View > Field Codes (Alt+F9) or
per field with Toggle Field Codes (Shift+F9); a field showing its code is
drawn as { CODE } on light grey. Edit a field's code in a small popup
(double-click a field showing its code, right-click > Edit Field..., or
fields.setCode), and Ctrl+F9 asks for a new field's code. F9 updates
fields and shows the selected ones' results again.

New commands: fields.unlink (Ctrl+Shift+F9) replaces fields with their
text, fields.lock / fields.unlock (Ctrl+F11 / Ctrl+Shift+F11) keep a
result through updates (already saved as w:fldLock), fields.next /
fields.previous (F11 / Shift+F11) select the next or previous field, and
fields.selected reports the fields in the selection. Range fields
(citations) can be locked, unlinked, edited and stepped through too.

The right-click menu gains Update Field, Edit Field... and Toggle Field
Codes when the selection holds a field. Strings are translated in every
catalog; parity catalog, ui-parity, gaps and roadmap updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vangel76
vangel76 force-pushed the feat/339-field-codes branch from 7cc3f1c to 45d34ad Compare October 11, 2026 08:05
# Conflicts:
#	ROADMAP.md
#	crates/ui-egui/src/i18n/et.tsv
#	docs/gaps.md
#	docs/ui-parity.md
@echelon
echelon merged commit 39ab3b5 into storytold:main Oct 11, 2026
@echelon

echelon commented Oct 11, 2026

Copy link
Copy Markdown
Member

Thanks for the contribution, @vangel76! This is now merged into main. If you haven't already, please come join us on Discord: https://discord.gg/artcraft

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.

Fields: show field codes, unlink, lock and jump between fields

2 participants