Repository navigation
Description
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
ItemsSourceto change under it. Kräfte'sStatusOptionsnever 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:
- Kräfte.
ForceRow.StatusandNotesare 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, likeTaskRow'sIsDone. - Aufgaben.
TasksViewModel.Syncrebuilds rows on purpose; its doc comment says fresh rows keep theIsDoneecho 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 ofSyncstays as a backstop. - Funktionen. Reconcile
_allby id first, then reconcile the filteredRolesfrom_all.MarkDuplicatesalready writesfalseexplicitly, so it works on reused rows unchanged. Keep it running after_allis 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 noReseton the tab's collection (subscribe toCollectionChangedand 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/
IsDoneupdates the row without a write-back to the session. - Aufgaben: a test that a due-time change re-sorts by
Move, without aReset. - An acceptance test (
[AvaloniaFact], realForcesView): select a row, raise an unrelatedChanged, 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
- CO-Messung.
BuildingOptions.Clear()(CoMessprotokollViewModel.cs:703) is CO-Messung: rebuilding the Haus list on every change likely closes an open editor #241.MatrixRows.Clear()(:739) is anItemsControlof tiles with no selection or scroll of its own, and CO-Messung: rebuilding the Haus list on every change likely closes an open editor #241 already rules makingBuildMatrixconditional out of scope. - ETB.
EtbViewModel.Synconly ever appends, so it is not part of this problem. It has two smaller flaws, now tracked in perf/ux(etb): Sync is O(n²) on a batch resync, and an edited entry loses its selection #529:- Its doc comment claims "O(n) total per Sync()", but
_all.Insert(0, …)(:95) is O(n) per new entry (O(n²) on a batch resync), and_all.IndexOf(current)(:111) is O(n) per edited entry. Entries[entriesIndex] = updated(:116) is aReplace, which still drops the selection on an edited row.
- Its doc comment claims "O(n) total per Sync()", but
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
fix(atemschutz): stop the Sicherheitstrupp picker clearing itself and…
fix(atemschutz): stop the Sicherheitstrupp picker clearing itself and…
feat(atemschutz): model the Sicherheitstrupp instead of hoping for it (…
[-]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[/+]fix(kraefte): reconcile the Kräfte rows by id instead of rebuilding t…
fix(funktionen): reconcile the Funktionen rows by id instead of rebui…
fix(funktionen): reconcile the Funktionen rows by id instead of rebui…
fix(aufgaben): reconcile the Aufgaben rows by id instead of rebuildin…
fix(aufgaben): reconcile the Aufgaben rows by id instead of rebuildin…