Skip to content

Commit 31098d3

Browse files
committed
page up/down for non-bulk candidates
1 parent fae7969 commit 31098d3

File tree

6 files changed

+42
-13
lines changed

6 files changed

+42
-13
lines changed

uipanel/CandidateBar.swift

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ struct CandidateBarView: View {
8686
}
8787
}.onAppear {
8888
visibleRows.insert(row)
89-
if !scrollEnd && row == rowItemCount.count - 5 {
89+
if pendingScroll >= 0 && !scrollEnd && row == rowItemCount.count - 5 {
9090
loadMoreCandidates(candidates.count, candidateCountInScreen)
9191
}
9292
}.onDisappear {
@@ -107,7 +107,9 @@ struct CandidateBarView: View {
107107
CandidateView(
108108
text: candidate, index: index, highlighted: highlighted
109109
).onAppear {
110-
if !scrollEnd && index == candidates.count - candidateCountInRow {
110+
if pendingScroll >= 0 && !scrollEnd
111+
&& index == candidates.count - candidateCountInRow
112+
{
111113
loadMoreCandidates(candidates.count, candidateCountInRow)
112114
}
113115
}
@@ -150,8 +152,12 @@ struct CandidateBarView: View {
150152
shadow: getShadow(colorScheme),
151153
action: GestureAction(
152154
onTap: {
153-
withAnimation {
154-
proxy.scrollTo(((visibleRows.min() ?? 0) - 1) / 5 * 5, anchor: .top)
155+
if pendingScroll >= 0 {
156+
withAnimation {
157+
proxy.scrollTo(((visibleRows.min() ?? 0) - 1) / 5 * 5, anchor: .top)
158+
}
159+
} else {
160+
page(false)
155161
}
156162
}
157163
)
@@ -169,8 +175,12 @@ struct CandidateBarView: View {
169175
shadow: getShadow(colorScheme),
170176
action: GestureAction(
171177
onTap: {
172-
withAnimation {
173-
proxy.scrollTo(((visibleRows.min() ?? 0) + 1) / 5 * 5 + 5, anchor: .top)
178+
if pendingScroll >= 0 {
179+
withAnimation {
180+
proxy.scrollTo(((visibleRows.min() ?? 0) + 1) / 5 * 5 + 5, anchor: .top)
181+
}
182+
} else {
183+
page(true)
174184
}
175185
}
176186
)

uipanel/VirtualKeyboard.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ViewModel: ObservableObject {
2424
@Published var scrollEnd = false
2525
@Published var rowItemCount = [Int]() // number of candidates in each row
2626
@Published var expanded = false
27-
// Have requested load more candidates starting from this index.
27+
// Have requested load more candidates starting from this index. -1 means not scrollable.
2828
@Published var pendingScroll = 0
2929

3030
@Published var actions = [StatusAreaAction]()
@@ -131,7 +131,7 @@ public struct VirtualKeyboardView: View {
131131

132132
public func setCandidates(
133133
_ auxUp: String, _ preedit: String, _ caret: Int32, _ candidates: [String],
134-
_ highlighted: Int32, _ hasClientPreedit: Bool
134+
_ highlighted: Int32, _ bulk: Bool, _ hasClientPreedit: Bool
135135
) {
136136
if !auxUp.isEmpty || !preedit.isEmpty || !candidates.isEmpty {
137137
setDisplayMode(.candidates)
@@ -152,7 +152,7 @@ public struct VirtualKeyboardView: View {
152152
viewModel.batch = (viewModel.batch + 1) & 0xFFFF
153153
viewModel.scrollEnd = false
154154
viewModel.rowItemCount = calculateLayout(candidates, keyboardWidth * 4 / 5)
155-
viewModel.pendingScroll = 0
155+
viewModel.pendingScroll = bulk ? 0 : -1
156156
}
157157

158158
public func scroll(_ candidates: [String], _ end: Bool) {

uipanel/keyboardui.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ public func showKeyboardAsync(_ clientPtr: UnsafeMutableRawPointer) {
1515

1616
public func setCandidatesAsync(
1717
_ auxUp: String, _ preedit: String, _ caret: Int32, _ candidates: [String],
18-
_ highlighted: Int32, _ hasClientPreedit: Bool
18+
_ highlighted: Int32, _ bulk: Bool, _ hasClientPreedit: Bool
1919
) {
2020
DispatchQueue.main.async {
2121
virtualKeyboardView.setCandidates(
22-
auxUp, preedit, caret, candidates, highlighted, hasClientPreedit)
22+
auxUp, preedit, caret, candidates, highlighted, bulk, hasClientPreedit)
2323
}
2424
}
2525

uipanel/uipanel-public.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ void activateCandidateAction(int index, int id);
77
void selectCandidate(int index);
88
void activateStatusAreaAction(int id);
99
void scroll(int start, int count);
10+
void page(bool next);

uipanel/uipanel.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void UIPanel::update(UserInterfaceComponent component,
6363
highlighted = list->cursorIndex();
6464
}
6565
KeyboardUI::setCandidatesAsync(auxUp, preedit, caret, candidates,
66-
highlighted, hasClientPreedit);
66+
highlighted, false, hasClientPreedit);
6767
break;
6868
}
6969
case UserInterfaceComponent::StatusArea:
@@ -110,7 +110,7 @@ void UIPanel::expand(const std::string &auxUp, const std::string &preedit,
110110
int caret, bool hasClientPreedit) {
111111
auto candidates =
112112
getBulkCandidates(instance_, 0, 72); // Vertically 2 screens.
113-
KeyboardUI::setCandidatesAsync(auxUp, preedit, caret, candidates, 0,
113+
KeyboardUI::setCandidatesAsync(auxUp, preedit, caret, candidates, 0, true,
114114
hasClientPreedit);
115115
}
116116

@@ -120,6 +120,19 @@ void UIPanel::scroll(int start, int count) {
120120
KeyboardUI::scrollAsync(candidates, endReached);
121121
}
122122

123+
void UIPanel::page(bool next) {
124+
auto ic = instance_->mostRecentInputContext();
125+
const auto &list = ic->inputPanel().candidateList();
126+
if (!list)
127+
return;
128+
auto *pageableList = list->toPageable();
129+
if (!pageableList)
130+
return;
131+
next ? pageableList->next() : pageableList->prev();
132+
// UI is responsible for updating UI
133+
ic->updateUserInterface(UserInterfaceComponent::InputPanel);
134+
}
135+
123136
KeyboardUI::StatusAreaAction convertAction(Action *action, InputContext *ic) {
124137
auto children = swift::Array<KeyboardUI::StatusAreaAction>::init();
125138
if (auto *menu = action->menu()) {
@@ -165,6 +178,10 @@ void scroll(int start, int count) {
165178
dispatcher->schedule([start, count] { fcitx::ui->scroll(start, count); });
166179
}
167180

181+
void page(bool next) {
182+
dispatcher->schedule([next] { fcitx::ui->page(next); });
183+
}
184+
168185
std::string getCandidateActions(int index) {
169186
return with_fcitx([index]() -> std::string {
170187
auto ic = instance->mostRecentInputContext();

uipanel/uipanel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class UIPanel final : public VirtualKeyboardUserInterface {
2929
void showVirtualKeyboard() override;
3030
void hideVirtualKeyboard() override {}
3131
void scroll(int start, int count);
32+
void page(bool next);
3233

3334
private:
3435
Instance *instance_;

0 commit comments

Comments
 (0)