Skip to content

LT-22691: Open detail-view context menus on the field the user is in - #1272

Open
mark-sil wants to merge 1 commit into
mainfrom
claude/lt-22691-shiftf10-placement-8dccd6
Open

mark-sil wants to merge 1 commit into
mainfrom
claude/lt-22691-shiftf10-placement-8dccd6

Conversation

@mark-sil

@mark-sil mark-sil commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

In the New UI detail view, a context menu now opens on the field the
user is in. A keyboard-opened menu (Shift+F10 or the Menu key) opens
just below the caret, and a right-click in a value moves focus and the
caret there before the menu opens. Until now, clicking another field
while a menu was open only closed the menu, so the next keyboard menu
opened on the old field again; the value box's own menu opened centred
under the whole field; and a right-click left focus behind, so closing
the menu scrolled the view back to the field the user had left.

The click that closes a detail-view menu now also lands where it was
aimed. A keyboard-opened menu drops from the caret of a text field, as
the WinForms view opens it at the insertion point; a field without a
caret drops it from its bottom-left corner. A right press in a text
value focuses it and moves the caret to the pointer unless it lands
inside the selection, as SimpleRootSite does. A right-click still opens
the menu at the pointer.


Reviewer notes

Start here: Src/Common/FwAvalonia/Detail/DetailMenuFlyout.cs. Configure and FocusOnRightPress hold the whole behaviour; the other files only call them.

Every detail-view context menu goes through DetailMenuFlyout.Configure: the host-built row menus, the value box's own menu, the reversal-entry jump menu and the reference-vector item menu. Multi-string value boxes and reversal entries now take focus on a right press, through the helper the structured-text rows already used.

The question to start with: does letting the dismissing click through break anything? Before, Avalonia swallowed the click that closed a menu; now it reaches the control under it, as a WinForms context menu lets it through. Clicking another field moves focus there. Right-clicking another field opens that field's menu. A second left-click on the "..." button still only closes its menu, as before.

Where to look

  • PlaceUnderCaret / CaretBounds: Avalonia hands the callback the target's bounds in top-level coordinates, so the caret rectangle must be in the same space. Pinned by the caret, wrapped-line, empty-field and right-to-left cases in KeyboardMenuPlacementTests.
  • Right-to-left values rely on Avalonia's positioner mirroring anchor and gravity. Pinned by the right-to-left case.
  • FwMultiWsTextField: the right-press surface is the row panel for a bridged row, whose abbreviation raises the menu too, and the value content otherwise. Pinned by ValueBoxRightClickTests.
  • A right press that moves focus commits the field being left. DataTree holds the re-show while the press or the menu is in flight, as it does for a left click.

Not here: FwChooserField is untouched; its right-click lands separately, and a chooser menu built as a local flyout should wrap it in DetailMenuFlyout.Configure. LT-22915 still removes the value box's local menu; the placement and dismissal stay with the host menus.

Verification: FwAvaloniaTests 1076 passed, 1 skipped (the existing non-headless drag test). The new tests fail with the fix switched off. Manual runs in Sena 3 passed: keyboard placement, the dismissing click, an empty field, right-click focus without scroll-back, and a reversal entry.

Next: approve.

Reading this a year from now

LT-22691 QA found that Shift+F10 in Definition, then a click in Gloss, then Shift+F10 again, opened the menu under the middle of Definition. Two causes: the dismissing click never reached Gloss, and the value box's own menu used Avalonia's default placement, centred below the field. Testing the fix exposed a third: a right-click in a value left focus in the previous field. No working documents were written for this change; the reasoning below is the record.

Decisions, and why
  • The caret, not the field's left edge. SimpleRootSite.ProcessCmdKey opens the Shift+F10 menu at the centre of the selection rectangle. In a wrapped Definition the caret's line is where the user is looking. Targets without a caret (label cell, list item, button) keep the bottom-left drop.
  • PlacementMode.Custom with a placement callback. A right-click makes the flyout use PlacementMode.Pointer, which ignores the callback, so one setting serves both kinds of opening without knowing which one happened.
  • OverlayDismissEventPassThrough. The dismissing click is what the user meant to do next. Swallowing it left focus in the old field. WinForms lets it through: clicking the slice menu icon twice closes and reopens the menu with either button.
  • The "..." button's second left-click keeps closing its menu. WinForms reopens it; closing is the usual toggle and is what this button did before.
  • Right press focus. SimpleRootSite.OnMouseDown switches focus to the clicked view and keeps a range selection the click lands in. Without it, closing the menu returned focus to the field the user had left and scrolled the view back to it.
Paths not taken
  • BottomEdgeAlignedLeft plus offsets to the caret. Avalonia applies HorizontalOffset/VerticalOffset to pointer placement too, so the offsets would shift right-click menus away from the pointer.
  • Fixing only the value box's local menu. LT-22915 removes it, and the host-built menus swallowed the dismissing click the same way.
Evidence

New tests:

  • KeyboardMenuPlacementTests: the reported case on unbound and bridged rows; menu under the caret; under a wrapped value's first line; below an empty field's line; leftward from the caret in a right-to-left value; bottom-left of a non-text target; at the pointer for a right-click.
  • ValueBoxRightClickTests: right-click in another field focuses it with the caret at the pointer; a second right-click in the same field keeps focus there; a bridged row's abbreviation focuses its value; a press inside the selection keeps it.
  • FwReversalEntriesFieldTests.ARightClickOnAnEntry_FocusesIt_WithTheCaretAtThePointer.

With the dismiss pass-through and caret placement switched off, 6 of the 7 original placement tests fail (the right-click case passes either way). With right-press focus switched off, 6 of the 7 right-click tests fail (the keep-selection guard passes either way).

Manual, Sena 3, Lexicon Edit, New UI: entry sana (keyboard menus on Definition, Gloss and Lexeme Form; the dismissing click; the empty Portuguese Definition; right-click focus with no scroll-back; a selection kept across a right-click; the Lexeme Form abbreviation), entry zinji (reversal entry "many"), and the WinForms comparison of the slice menu icon.

Preflight review details

Code Review Summary

Branch: claude/lt-22691-shiftf10-placement-8dccd6
Base: main (c5da1ae)
Date: 2026-12-01
Review model: Claude Opus 5.5
Files changed: 8 (1 commit)

Overview

QA (LT-22691) found that Shift+F10 in the New UI detail view opened the menu on the wrong
field: after a menu opened in Definition, clicking Gloss and pressing Shift+F10 reopened the
menu under Definition, centred under the field. The cause was the dismissing click: Avalonia
swallows the click that light-dismisses a flyout, so focus stayed in Definition. The value
box's own menu also used Avalonia's default placement (centred below the target).

Every detail-view menu now goes through DetailMenuFlyout.Configure: the dismissing click
passes through, and a pointer-less menu drops from the caret of a text box (WinForms opens
it at the insertion point) or from a non-text target's bottom-left corner. During manual
testing the author found that a right-click in a value box left focus in the previous field,
so closing the menu scrolled back there; a right press now focuses the box and moves the
caret to the pointer unless it lands inside the selection, as SimpleRootSite does.

Contract/API Changes

  • New public DetailMenuFlyout.Configure(MenuFlyout); new internal
    DetailMenuFlyout.FocusOnRightPress(Control, TextBox).
  • DetailMenuFlyout.Show no longer sets PlacementMode.BottomEdgeAlignedLeft; every flyout
    from Build uses PlacementMode.Custom with a placement callback.
  • Behaviour: the click that dismisses any detail-view menu now reaches the control under it.

Findings

Critical - Must address before merge

None.

Important - Should address before merge

  • Empty value box could anchor the keyboard menu on its line (fixed during review: a
    zero-height caret falls back to the target's bounds; headless test added)
  • Right-click on a bridged row's writing-system abbreviation left focus elsewhere
    (fixed during review: the right-press handler sits on the row panel for bridged rows;
    headless test added)
  • A second left-click on the "..." button no longer reopens its menu, unlike WinForms
    (author: keep it closing -- the usual toggle; behaviour unchanged by this branch)

Minor - Consider

  • Caret anchor is not clipped to the visible viewport (skipped: the positioner keeps
    the menu on screen; WinForms also opens at a hidden insertion point)
  • Reversal and vector-item menus' Configure call has no placement test (skipped:
    same one-line call as the tested sites)
  • Reversal right-press focus is wired only when the field has a navigation callback
    (skipped: the app always supplies it; previews only)
  • Retypable vector editor keeps its own right-press logic (skipped: it also sets the
    current editor)
  • No right-to-left coverage for the caret anchor (fixed during review: RTL test
    asserts the menu grows leftward from the caret)

Required Validation / Evidence

  • .\test.ps1 -CommentHygiene -TokenHygiene -TestProject "Src/Common/FwAvalonia/FwAvaloniaTests":
    1076 passed, 1 skipped (the existing non-headless drag test).
  • Mutation checks: with the dismiss pass-through and caret placement disabled, 6 of 7
    original placement tests fail; with right-press focus disabled, 6 of 7 right-click tests
    fail (the keep-selection guard passes either way by design).
  • Manual (author, Sena 3): keyboard placement on Definition/Gloss/Lexeme Form, dismiss-click
    focus, empty Definition (Por), right-click focus and no scroll-back on sana, reversal entry
    right-click on zinji, WinForms comparison of the "..." button -- all passed.
  • Jira: LT-22691 (user-visible; ticket exists).

Positive Observations

  • One shared helper serves host-built menus and local flyouts, so the fix survives LT-22915
    removing the value box's local menu.
  • The structured-text right-press logic moved into the shared helper instead of being copied.

Interview Notes

  • Anchor choice: author chose the caret (WinForms parity) over the field's left edge.
  • "..." second left-click: author chose to keep it closing the menu.
  • Right-click focus: author chose to fix it in this PR.

Suggested Review Focus

  • DetailMenuFlyout.Configure -- dismiss pass-through applies to every detail menu
  • DetailMenuFlyout.PlaceUnderCaret / CaretBounds -- top-level coordinates, RTL relies on
    Avalonia's mirroring
  • FwMultiWsTextField right-press surface choice (row panel when bridged)

🤖 Generated with Claude Code


This change is Reviewable

In the New UI detail view, a context menu now opens on the field the
user is in. A keyboard-opened menu (Shift+F10 or the Menu key) opens
just below the caret, and a right-click in a value moves focus and the
caret there before the menu opens. Until now, clicking another field
while a menu was open only closed the menu, so the next keyboard menu
opened on the old field again; the value box's own menu opened centred
under the whole field; and a right-click left focus behind, so closing
the menu scrolled the view back to the field the user had left.

The click that closes a detail-view menu now also lands where it was
aimed. A keyboard-opened menu drops from the caret of a text field, as
the WinForms view opens it at the insertion point; a field without a
caret drops it from its bottom-left corner. A right press in a text
value focuses it and moves the caret to the pointer unless it lands
inside the selection, as SimpleRootSite does. A right-click still opens
the menu at the pointer.

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

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

NUnit Tests

    1 files  ± 0      1 suites  ±0   15m 25s ⏱️ + 3m 55s
7 444 tests +14  7 365 ✅ +14  79 💤 ±0  0 ❌ ±0 
7 453 runs  +14  7 374 ✅ +14  79 💤 ±0  0 ❌ ±0 

Results for commit 909e7d4. ± Comparison against base commit c5da1ae.

This pull request removes 2 and adds 16 tests. Note that renamed tests count towards both.
FwAvaloniaTests.DetailMenuRequestTests ‑ DetailMenuFlyout_AnchoredPlacement_DropsFromTheTargetsBottomLeft
FwAvaloniaTests.DetailMenuRequestTests ‑ DetailMenuFlyout_PointerPlacement_LeavesTheDefault
FwAvaloniaTests.Detail.FwReversalEntriesFieldTests ‑ ARightClickOnAnEntry_FocusesIt_WithTheCaretAtThePointer
FwAvaloniaTests.Detail.KeyboardMenuPlacementTests ‑ ContextMenuKey_AfterClickingAnotherFieldWhileAMenuIsOpen_OpensOnTheClickedField(False)
FwAvaloniaTests.Detail.KeyboardMenuPlacementTests ‑ ContextMenuKey_AfterClickingAnotherFieldWhileAMenuIsOpen_OpensOnTheClickedField(True)
FwAvaloniaTests.Detail.KeyboardMenuPlacementTests ‑ ContextMenuKey_InARightToLeftValue_OpensLeftwardFromTheCaret
FwAvaloniaTests.Detail.KeyboardMenuPlacementTests ‑ ContextMenuKey_InAWrappedValue_OpensUnderTheCaretsLine
FwAvaloniaTests.Detail.KeyboardMenuPlacementTests ‑ ContextMenuKey_InAnEmptyField_OpensBelowItsLine
FwAvaloniaTests.Detail.KeyboardMenuPlacementTests ‑ ContextMenuKey_OpensTheMenuUnderTheCaret(False)
FwAvaloniaTests.Detail.KeyboardMenuPlacementTests ‑ ContextMenuKey_OpensTheMenuUnderTheCaret(True)
FwAvaloniaTests.Detail.KeyboardMenuPlacementTests ‑ PointerlessMenu_OnATargetWithoutACaret_DropsFromItsBottomLeft
FwAvaloniaTests.Detail.KeyboardMenuPlacementTests ‑ RightClickMenu_StillOpensAtThePointer
…

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.83673% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 40.93%. Comparing base (c5da1ae) to head (909e7d4).

Files with missing lines Patch % Lines
Src/Common/FwAvalonia/Detail/DetailMenuFlyout.cs 90.24% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1272   +/-   ##
=======================================
  Coverage   40.93%   40.93%           
=======================================
  Files        1603     1603           
  Lines      360816   360847   +31     
  Branches    42246    42251    +5     
=======================================
+ Hits       147687   147715   +28     
- Misses     183637   183638    +1     
- Partials    29492    29494    +2     
Files with missing lines Coverage Δ
Src/Common/FwAvalonia/Detail/FwFieldControls.cs 88.33% <100.00%> (+<0.01%) ⬆️
...Common/FwAvalonia/Detail/FwReversalEntriesField.cs 90.39% <100.00%> (+0.03%) ⬆️
.../Common/FwAvalonia/Detail/FwStructuredTextField.cs 81.83% <100.00%> (+0.40%) ⬆️
Src/Common/FwAvalonia/Detail/DetailMenuFlyout.cs 93.13% <90.24%> (-2.18%) ⬇️

... and 5 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.

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.

2 participants