Repository navigation
LT-22691: Menus for reference-vector rows in the Avalonia detail view - #1133
Conversation
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>
NUnit Tests 1 files ± 0 1 suites ±0 12m 35s ⏱️ -14s 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.♻️ This comment has been updated with latest results. |
jasonleenaylor
left a comment
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
|
Looks like there's no corresponding "-=" to unsubscribe from the OnVectorSelectionChanged action in the RebuildItems method. |
jasonleenaylor
left a comment
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
@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
left a comment
There was a problem hiding this comment.
@jasonleenaylor reviewed 27 files and all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on mark-sil).
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>
) 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>
Reference-vector rows (Publication Settings: Subentries, Referenced Complex Forms, Semantic Domains, Publish In, ...) now have support for the label and edit field menus.
This change is