Skip to content

LT-22691: Menus for reference-vector rows in the Avalonia detail view - #1133

Merged
jasonleenaylor merged 2 commits into
mainfrom
LT-22691h
Sep 11, 2026
Merged

jasonleenaylor merged 2 commits into
mainfrom
LT-22691h

Conversation

@mark-sil

@mark-sil mark-sil commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Reference-vector rows (Publication Settings: Subentries, Referenced Complex Forms, Semantic Domains, Publish In, ...) now have support for the label and edit field menus.

  • Items are selectable (to support the move left/right commands).
  • Ctrl+click runs the first jump.
  • Backspace or Delete removes the focused item.
  • Move Left / Move Right on the label menu and the item menu act on the current item.
  • Restore the scroll offset, the vector row's current item, and focus after a re-show.

This change is Reviewable

Reference-vector rows (Publication Settings: Subentries, Referenced
Complex Forms, Semantic Domains, Publish In, ...) now have support
for the label and edit field menus.

- Items are selectable (to support the move left/right commands).
- Ctrl+click runs the first jump.
- Backspace or Delete removes the focused item.
- Move Left / Move Right on the label menu and the item menu act on the
current item.
- Restore the scroll offset, the vector row's current item, and focus
after a re-show.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

NUnit Tests

    1 files  ± 0      1 suites  ±0   12m 35s ⏱️ -14s
6 105 tests +21  6 020 ✅ +21  85 💤 ±0  0 ❌ ±0 
6 114 runs  +21  6 029 ✅ +21  85 💤 ±0  0 ❌ ±0 

Results for commit 50ff014. ± Comparison against base commit cbb5dc2.

This pull request removes 1 and adds 22 tests. Note that renamed tests count towards both.
FwAvaloniaTests.DetailEditorParityTests ‑ ReferenceVector_ReadOnly_HasNothingToDetach
FwAvaloniaTests.DetailEditorParityTests ‑ ReferenceVector_ReadOnly_WiresOnlyTheItemSelectHandlers
FwAvaloniaTests.DetailFocusMemoryTests ‑ CaptureAndRestore_CarryTheVectorRowsCurrentItem_AcrossAViewRebuild
FwAvaloniaTests.DetailFocusMemoryTests ‑ RestoreAfterLayout_FocusesTheCurrentItem_OnlyWhenAskedTo_OrAfterAnItemRemoval
FwAvaloniaTests.DetailFocusMemoryTests ‑ RestoreAfterLayout_KeepsTheScrollOffset_WithNoFocusedEditor_WhenGivenBeforeLayout
FwAvaloniaTests.DetailMenuRequestTests ‑ ClickingAVectorItem_SelectsIt_AndTheLabelMenuRequestCarriesIt
FwAvaloniaTests.DetailMenuRequestTests ‑ ClickingAnotherVectorItem_MovesTheSelection_AndTheHighlight
FwAvaloniaTests.DetailMenuRequestTests ‑ CtrlClickingAVectorItem_RaisesTheDefaultActivation_ForThatItem
FwAvaloniaTests.DetailMenuRequestTests ‑ DeleteOrBackspace_OnAFocusedVectorItem_RemovesIt_ThroughTheEditContext
FwAvaloniaTests.DetailMenuRequestTests ‑ EditableVectorItem_WithAMenuBridge_HasNoLocalRemoveFlyout_AndWithoutOneKeepsIt
FwAvaloniaTests.DetailMenuRequestTests ‑ FocusingAVectorItem_SelectsIt_AndTheContextMenuKey_RaisesTheItemMenuUnderIt
…

♻️ This comment has been updated with latest results.

@codecov-commenter

codecov-commenter commented Sep 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.16935% with 143 lines in your changes missing coverage. Please review.
✅ Project coverage is 38.81%. Comparing base (cbb5dc2) to head (50ff014).

Files with missing lines Patch % Lines
...nia/Hosting/RecordEditView.ReferenceVectorMenus.cs 55.31% 44 Missing and 19 partials ⚠️
Src/Common/FwAvalonia/Detail/DetailFocusMemory.cs 69.00% 16 Missing and 15 partials ⚠️
Src/Common/FwAvalonia/AvaloniaHostControlBase.cs 0.00% 13 Missing and 2 partials ⚠️
...xWorks/Avalonia/Hosting/RecordEditView.Avalonia.cs 0.00% 9 Missing and 1 partial ⚠️
Src/Common/FwAvalonia/Detail/FwFieldControls.cs 92.47% 3 Missing and 4 partials ⚠️
Src/Common/FwAvalonia/Detail/DataTree.cs 85.71% 2 Missing and 2 partials ⚠️
.../Common/FwAvalonia/Preview/DetailPreviewSupport.cs 0.00% 4 Missing ⚠️
...rks/Avalonia/Composer/ComposedDetailEditContext.cs 50.00% 1 Missing and 2 partials ⚠️
Src/FdoUi/FdoUiCore.cs 33.33% 0 Missing and 2 partials ⚠️
Src/Common/FwAvalonia/DetailHostControl.cs 66.66% 0 Missing and 1 partial ⚠️
... and 3 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1133      +/-   ##
==========================================
+ Coverage   38.68%   38.81%   +0.12%     
==========================================
  Files        1516     1517       +1     
  Lines      351405   351857     +452     
  Branches    40421    40510      +89     
==========================================
+ Hits       135929   136556     +627     
+ Misses     186254   186058     -196     
- Partials    29222    29243      +21     
Files with missing lines Coverage Δ
Src/Common/FwAvalonia/Detail/DetailModel.cs 78.16% <100.00%> (+0.21%) ⬆️
Src/Common/FwAvalonia/Detail/SliceFactory.cs 91.66% <100.00%> (+0.10%) ⬆️
...n/FwAvalonia/ViewDefinition/ViewDefinitionModel.cs 89.20% <100.00%> (+0.10%) ⬆️
...ia/ViewDefinition/ViewDefinitionOverrideApplier.cs 93.60% <100.00%> (ø)
...mon/FwAvalonia/ViewDefinition/XmlLayoutImporter.cs 85.98% <100.00%> (+0.08%) ⬆️
Src/xWorks/Avalonia/Composer/DetailComposer.cs 68.50% <100.00%> (+0.94%) ⬆️
Src/xWorks/Avalonia/Hosting/XCoreMenuBridge.cs 79.72% <100.00%> (+0.85%) ⬆️
Src/Common/FwAvalonia/DetailHostControl.cs 69.56% <66.66%> (+12.42%) ⬆️
...mon/FwAvaloniaDialogs/InMemoryDetailEditContext.cs 56.66% <0.00%> (-1.96%) ⬇️
Src/xWorks/Avalonia/DetailEditContextBase.cs 66.23% <0.00%> (-0.88%) ⬇️
... and 10 more

... and 14 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jasonleenaylor jasonleenaylor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing to fix, one question and one nit inline. The fix is a line move.

This review was assisted by Claude Opus 5.

// focus selects too. Items are focusable (a click focuses one) but not tab stops.
var itemIndex = index;
text.Focusable = true;
KeyboardNavigation.SetIsTabStop(text, false);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Items get Focusable = true but IsTabStop false, and I don't see arrow-key handling on the row or Focusable on the StackPanel — so is a mouse click the only way to make an item current? If it is, then Backspace/Delete, the context-menu key and Move Left/Right all need the mouse first, which makes the current keyboard work less valuable.

I could be missing something here, but if Claude and I evaluated it correctly addressing this in a follow up would be good.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your reading is correct. A mouse click, or a programmatic focus call in tests, is the only way to make an item current today. Items are focusable but not tab stops, the row is not focusable, and there is no arrow-key handling. So Backspace and Delete, the context-menu key, and Move Left and Right all need the mouse first.

Worth adding what testing against the legacy view showed: it does not fully work there either. Arrow keys do move between items, but the first item still needs a mouse click, and tabbing into the vector consumes a tab stop while selecting nothing.

So a follow-up should not just reach parity. Tabbing into the row should make an item current, arrows should move between items, and the current item should survive leaving and re-entering the row. There is also a host-level question, since the WinForms host may not forward Tab into the Avalonia pane at all. That is planned as its own PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This issue has been addressed with PR #1160.

if (context == null || !context.TryMoveReferenceItem(field, key, forward))
return;
// The menu took keyboard focus; the re-show hands it to the moved item.
m_avaloniaEntryForm?.FocusVectorItemOnNextShow();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FocusVectorItemOnNextShow() runs unconditionally, but the re-show only happens when the settle below returns clean, and VectorFocusRequested (DataTree.cs:70) has no reset. Validate() is a whole-record rule against current domain state, so on an entry with both the lexeme form and the citation form empty the settle cancels, the move rolls back, no re-show occurs, and the flag stays set on the live DataTree — the next re-show for any unrelated reason then pulls focus into this row. This is a bit of an edge case but the consequences would be really annoying. Moving the call inside the Count == 0 branch should cover it — the re-show can't happen inside Settle() itself: the refresh runner is posted through ScheduleOnUiThread, and during Commit() the session is still open so _isEditing() holds it rather than delivering it.

Worth a test if you agree: DetailObjectCommandExecutionTests already drives MoveReferenceItem over a real cache in SubentriesMoveRight_ThroughTheHost_ReordersTheRow, so a sibling that clears both forms first, asserts the order is unchanged, then checks that an unrelated re-show does not pull focus into the row, is about a dozen lines. The existing focus tests cannot catch it — NewVectorView builds a fresh DataTree per re-show, so the stale-flag case never arises there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find. Fixed in 50ff014: the focus request now sits inside the Count == 0 branch, so a refused move leaves nothing behind. Your reading of the ordering holds up. AvaloniaDetailRefreshController checks _isEditing() on both the notification and the delivery path and suspends rather than delivering while the session is open.

On the test, I wrote it and could not make it discriminate. A rolled-back move fires its own PropChanged, which re-shows the record and replaces the DataTree, so the flag is already gone when the assertion runs. I confirmed that by reverting the fix and re-running: it passes either way. So the symptom is narrower than we both assumed. On the old code focus is pulled into the row on the rollback's own re-show, immediately, rather than waiting for an unrelated one.

There is a second snag. Driving the invalid-record path headlessly pops the rolled-back-edit notification, which blocks an unattended run. I would rather ship no test than one that passes against the bug, but if you can see an assertion that separates the two paths I will add it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went looking for an assertion that separates the two builds and couldn't find one worth having.

The only state that actually differs is VectorFocusRequested on the tree that was live at the gesture — and every route to it from xWorksTests is reflective. m_avaloniaEntryForm and m_detailEditContext are private fields on RecordEditView, DetailHostControl.CurrentContent is protected, and FwAvalonia declares no InternalsVisibleTo at all, so the internal flag isn't visible even to a friend assembly. Asserting the rolled-back order alone passes on both builds, which is the trap you already hit.

Doing it without reflection would mean widening those permanently to enable one corner case. I don't think that trade is worth it here, so: agreed, ship it without the test. Not adding one that passes against the bug was the right call.

{
var field = request.Field;
var index = request.SelectedItemIndex;
var canMove = field.Kind == DetailFieldKind.ReferenceVector && field.CanReorderItems

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsEditable is not consulted here, and not further down either — RegisterReferenceMove gates only on canReorder, so the handler exists and the move would write. Removal is gated on it: the Backspace/Delete handler in FwFieldControls sits under if (editable), which is editContext != null && field.IsEditable.

Not reachable today — CanReorderItems defaults false and is set true only at the four RegisterReferenceMove sites, all composed with isEditable: true — so feel free to wave this off. An && field.IsEditable would just keep the two gestures honest about the same flag.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed not reachable today. All four RegisterReferenceMove call sites compose their row with isEditable: true, so CanReorderItems never turns true on a read-only row.

Taking it rather than waving it off. MoveCommandItem now gates on field.IsEditable too, which covers execution as well, since the item's action is only wired when it is enabled. Leaving removal gated while the move is not is the kind of asymmetry that becomes a real bug the first time a read-only reorderable row exists.

Move Left and Move Right asked the next re-show to focus the moved item
before the settle that decides whether the move committed. A move refused
by the record's required-field validation rolls back and never re-shows on
that path, so the request outlived the gesture that made it.

The request now sits inside the committed branch, so a refused move leaves
nothing behind.

The move also gates on DetailField.IsEditable, the flag the Backspace and
Delete removal already uses. No shipped row reaches the move with that flag
false, so nothing changes today; it keeps the two gestures honest about the
same rule.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@thejambi

Copy link
Copy Markdown
Contributor

Src/Common/FwAvalonia/Detail/DataTree.cs line 518 at r2 (raw file):

			{
				_vectors.Add(vector);
				vector.SelectionChanged += OnVectorSelectionChanged;

Looks like there's no corresponding "-=" to unsubscribe from the OnVectorSelectionChanged action in the RebuildItems method.

@jasonleenaylor jasonleenaylor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. Both points from the last round are fixed, and I checked each against the code rather than the commit message: the focus request now sits behind the settle, and MoveCommandItem gates on IsEditable — which does cover execution, not just enablement, since the item's action is only wired when canMove holds.

The keyboard-reach question is answered and belongs in its own PR, as you said. Worth repeating your point here so it does not get lost: the follow-up should go past legacy parity rather than match it, since the legacy view also needs a click before the arrows do anything.

One follow-up worth filing, unrelated to anything this PR introduced: _labelBlocks gains an entry per row in BuildItem and is never cleared, so it grows on every expand/collapse and ApplyLabelColumnWidth writes MaxWidth to blocks that left the tree long ago. It only writes and never aggregates, so the label width stays correct — it is retained memory rather than a wrong result. Same missing clear is on main, so it predates this branch.

This review was assisted by Claude Opus 5.

if (editor is FwReferenceVectorField vector)
{
_vectors.Add(vector);
vector.SelectionChanged += OnVectorSelectionChanged;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thejambi I dug into this one and I do not think it needs a change to land, though it is a reasonable thing to stop on.

Why it is safe as written: RebuildItems builds fresh editors on every pass — BuildItem calls CreateEditor, which is SliceFactory.Build(...), with no caching or reuse — so each FwReferenceVectorField is subscribed exactly once, at construction. There is no path to a double-subscription, which is the failure a missing -= normally causes. The discarded vectors cannot fire either: they leave the visual tree so no pointer or focus event reaches them, and nothing retains a reference to call SelectItem or ClearSelection on them, since _vectors is cleared and SelectedVector nulled in the same method. And the delegate points from the dead vector at the live tree, not the other way round, so nothing is pinned — the classic leak is a long-lived publisher holding short-lived subscribers, which is the reverse of this.

Where it would belong if you want it anyway, purely so the pairing is visible rather than re-derived by the next reader: in RebuildItems, immediately above the existing _vectors.Clear().

foreach (var vector in _vectors)
    vector.SelectionChanged -= OnVectorSelectionChanged;
_vectors.Clear();

Two caveats if it is picked up. It would only be locally symmetric — it covers vectors dropped by a rebuild, but vectors still live when the whole DataTree goes away are not unsubscribed either way, and the class has no disposal hook at all to put that in. And it is not a convention this file already follows: DataTree.cs has five += and no -=, the other four being lambdas on controls it builds and discards, the same lifetime story as this one. I suspect this line stood out because it is the only one bound to a named method.

@jasonleenaylor jasonleenaylor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasonleenaylor reviewed 27 files and all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on mark-sil).

@jasonleenaylor
jasonleenaylor merged commit 0fa2d6a into main Sep 11, 2026
8 of 9 checks passed
@jasonleenaylor
jasonleenaylor deleted the LT-22691h branch September 11, 2026 20:30
thejambi pushed a commit that referenced this pull request Sep 14, 2026
Brings in LT-22691 (#1133), whose reference-vector row menus land in the same
four places this branch edits. Four conflicts, all resolved by keeping both
sides:

- ComposedDetailEditContext: our ReferenceCreate and their ReferenceMove are
  independent handler fields on the same type.
- DetailComposer: our chooserLinks comment and their canReorder local, and
  both named arguments on the DetailField. Their RegisterReferenceMove call
  below auto-merged, so dropping the local would not compile.
- DetailObjectCommandExecutionTests: both sides appended a test section at the
  same point, with an empty base between them.
- FwFieldControls: their per-item selection and Ctrl+click wiring, then our
  validation styling. Their ItemAutomationId yields the same ".Item." string
  the old expression did, and our styling sets only Foreground, TextDecorations
  and the tooltip, so it cannot collide with their Background-based selection
  highlight.

Git kept our PopupReporting.Wire on the local Remove flyout inside their new
menuRequested-is-null fallback, so the popup-reporting test still holds.

FwAvaloniaTests 744 passed, xWorksTests filter Avalonia 1637 passed, 0 failed.
Comment and token hygiene clean.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
mark-sil added a commit that referenced this pull request Sep 15, 2026
)

DataTree._labelBlocks gained an entry per row in BuildItem and was
never cleared, so it grew on every expand/collapse and held every
TextBlock the view had ever built -- and, through each one, the row
graph it belonged to -- for the life of the view.

Note: This problem was identified by a review of PR #1133, but had
nothing to do with the changes in #1133. The omission predates #1133.

Co-authored-by: Claude Opus 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.

4 participants