Skip to content

fix(connection-form): move host selection to adjacent row after delete#1294

Merged
datlechin merged 1 commit into
mainfrom
fix/issue-1293-mongo-host-list-selection
May 16, 2026
Merged

fix(connection-form): move host selection to adjacent row after delete#1294
datlechin merged 1 commit into
mainfrom
fix/issue-1293-mongo-host-list-selection

Conversation

@datlechin
Copy link
Copy Markdown
Member

Summary

Fixes #1293 — MongoDB multi-host editor: after deleting a host row, the remaining rows could not be selected until the form lost and regained focus.

HostListFieldRow.removeSelected() cleared selectedId to an empty Set immediately after mutating entries. SwiftUI's List(selection:) does not recover its internal selection state cleanly when both the items array and the selection binding flip in the same update, so subsequent clicks on the remaining rows fell through.

Fix

Mirror NSTableView HIG: when a row is removed, move selection to the row that takes its place (or the new last row if the deleted row was last). The new HostListSelection.nextSelection(afterRemoving:from:) helper does the arithmetic; removeSelected() calls it before mutating entries.

Behavior matrix:

Before delete Selected After delete
[a, b, c] {b} selection moves to c
[a, b, c] {c} selection moves to b
[a, b] {a} selection moves to b
[a, b, c] {b, c} selection moves to a
[a] {a} placeholder added, selection empty

Tests

HostListSelectionTests covers all five matrix rows plus stale-selection (removedIds contains a UUID that no longer exists) and no-op cases.

Test plan

  • xcodebuild test -only-testing:TableProTests/HostListSelectionTests green
  • Manual: MongoDB connection form, add 3 hosts, select row 3, click , then click row 2 — row 2 highlights immediately, no focus shuffle needed
  • Manual: select multiple rows, delete, surviving row stays selectable
  • Manual: delete the only row, placeholder appears, no crash

@datlechin datlechin merged commit 381b459 into main May 16, 2026
2 checks passed
@datlechin datlechin deleted the fix/issue-1293-mongo-host-list-selection branch May 16, 2026 13:39
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.

连接hosts无法正确选中

1 participant