Skip to content

Commit 1409c98

Browse files
committed
auto scroll horizontally to avoid highlighted candidate out of viewport
1 parent 31098d3 commit 1409c98

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

uipanel/CandidateBar.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,19 @@ struct CandidateBarView: View {
116116
}
117117
Spacer()
118118
}.frame(
119-
height: barHeightExcludePreedit)
119+
height: barHeightExcludePreedit
120+
)
121+
// Force re-render, otherwise scrolling to the first candidate may fail due to the first isn't rendered.
122+
.id(batch)
120123
}.scrollIndicators(.hidden) // Hide scroll bar as native keyboard.
121124
.padding([.leading], columnGap / 2)
122-
.onChange(of: batch) { _ in
123-
// Use batch instead of candidates because we don't want to reset on loading more.
124-
proxy.scrollTo(0, anchor: .leading)
125+
.onChange(of: [batch, highlighted]) { newValues in
126+
// Watch batch instead of candidates because we don't want to reset on loading more.
127+
let newHighlighted = newValues[1]
128+
// Test in mozc by typing mizu and space through all candidates.
129+
proxy.scrollTo(
130+
newHighlighted,
131+
anchor: newHighlighted == candidates.count - 1 ? .leading : .trailing)
125132
}
126133
}
127134
}

0 commit comments

Comments
 (0)