Skip to content

ux: rebuilding Kräfte, Funktionen and Aufgaben on every change drops selection and focus #294

Closed

Description

@DeepDiver1975

Rewritten 2026-10-01 against main (7735486). The original (from the 2026-09-09 review of 35d86e1) listed five view-models. One of them is fixed, and two need more than "do what ETB does".

The problem

session.Changed fires for any mutation anywhere in the incident: this device's save in any tab, or a change pushed from a joined device. Three tabs answer it by throwing their whole collection away and rebuilding it:

Tab Where What the rebuild does
Kräfte ForcesViewModel.RefreshForces → Forces.Clear() (ForcesViewModel.cs:245) new ForceRows every time
Funktionen RolesViewModel.RefreshRoles → _all.Clear() (:157), then ApplyFilter → Roles.Clear() (:223) two collections, the visible one filtered by ShowAllRoles
Aufgaben TasksViewModel.Sync → Rows.Clear() (:403) new TaskRows, sorted by SortForDisplay (:396)

Clear() raises a Reset, so Avalonia tears down and re-realises every row container. Whatever lived in those containers goes with it: the selected row, the scroll offset, and keyboard focus.

Confirmed in the real app (2026-09-30, desktop build of 1decf1e, real X11 popups rather than headless):

  • Change a Kräfte row's STATUS from the grid. The value is saved, and the row's selection highlight vanishes.
  • Press Down right afterwards. The STATUS combo no longer has focus: the key moves the DataGrid's cell cursor instead of changing the status.
  • Control: the same test on the add form's STATUS combo, which is never rebuilt, keeps focus, and Down changes its value. So the focus loss comes from the rebuild, not from ComboBox defaults.
  • No freeze and no stranded popup, even with 10 rapid changes. The feat(atemschutz): model the Sicherheitstrupp instead of hoping for it #408 freeze needed the combo's own ItemsSource to change under it. Kräfte's StatusOptions never changes; only the row around it is rebuilt.

The code already works around the symptom instead of fixing it. ForcesView.axaml (and RolesView's Handynummer) push text fields on LostFocus because "the row rebuilds on each commit, threw focus out of the box after every character" (#33).

Already done: Atemschutz. ScbaViewModel.RefreshTrupps (:1008) reconciles by id and updates in place since #408. Its doc comment cites this issue. Use it as the model.

What to do

Reconcile instead of rebuild: match rows by id, update the matching ones in place, and remove or insert only the difference. Follow ScbaViewModel.RefreshTrupps, not EtbViewModel.Sync (see "Out of scope"). Each tab has its own trap:

  1. Kräfte. ForceRow.Status and Notes are two-way. OnStatusChanged → PushStatusNotes() (:129) writes to the session. Updating a reused row from the incident must not echo that value back as a new write, or a remote change bounces back as a local edit. Add an echo guard, like TaskRow's IsDone.
  2. Aufgaben. TasksViewModel.Sync rebuilds rows on purpose; its doc comment says fresh rows keep the IsDone echo guard "trivially safe". Reusing rows gives that guarantee up, so the guard has to hold for an in-place update. The list is also sorted (SortForDisplay) and filtered (Filter), so the reconcile has to move rows, not only add and remove them (ObservableCollection.Move). The selection-by-id carry-over at the end of Sync stays as a backstop.
  3. Funktionen. Reconcile _all by id first, then reconcile the filtered Roles from _all. MarkDuplicates already writes false explicitly, so it works on reused rows unchanged. Keep it running after _all is complete, as its comment requires.

Once a tab no longer rebuilds, its UpdateSourceTrigger=LostFocus workaround can stay. It is also the fix for #33's write-per-keystroke, so it is not only a workaround.

Verify

  • Per tab, a view-model test: raise an unrelated Changed (for example, add an ETB entry) and assert no Reset on the tab's collection (subscribe to CollectionChanged and count). Then assert that a real add, removal and edit still show up.
  • Kräfte and Aufgaben: a test that a remote change to a row's Status/IsDone updates the row without a write-back to the session.
  • Aufgaben: a test that a due-time change re-sorts by Move, without a Reset.
  • An acceptance test ([AvaloniaFact], real ForcesView): select a row, raise an unrelated Changed, and assert that the same row is still selected. The headless focus check is optional, since headless focus is unreliable. The manual Down-key probe above is the real-app check.
make test PROJECT=tests/LageBuch.AppLogic.Tests FILTER="Name~Forces|Name~Roles|Name~Tasks"
make test PROJECT=tests/LageBuch.Acceptance.Tests FILTER=Name~Forces

Kräfte, Funktionen and Aufgaben can land as three separate PRs.

Out of scope

Difficulty: medium, because of the echo guards and the sorted reconcile in Aufgaben.


Before you open the PR, please skim CONTRIBUTING.md: commits need DCO sign-off (git commit -s), a cryptographic signature and a Conventional Commit subject. Changes under src/ need a changelog entry as a new file changelog.d/+<slug>.fixed.md (Changelog entries); CI fails the PR otherwise.

Activity

  1. changed the title [-]perf/ux: Clear()+re-add on every Changed resets selection and scroll in Kräfte, Atemschutz, Aufgaben, Funktionen[/-] [+]ux: rebuilding Kräfte, Funktionen and Aufgaben on every change drops selection and focus[/+] on Oct 1, 2026
  2. added
    bugSomething isn't working
    and removed
    enhancementNew feature or request
    on Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions