Skip to content

Commit 4f60eae

Browse files
authored
scroll mode: configurable max column count and cell width (#49)
1 parent cdc3eb7 commit 4f60eae

File tree

3 files changed

+34
-25
lines changed

3 files changed

+34
-25
lines changed

webpanel/webpanel.cpp

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -157,30 +157,27 @@ WebPanel::WebPanel(Instance *instance)
157157
return keyEvent.filterAndAccept();
158158
}
159159
if (scrollState_ == candidate_window::scroll_state_t::scrolling) {
160-
static const std::vector<
161-
std::pair<Key, candidate_window::scroll_key_action_t>>
162-
selectMap = {
163-
{Key(FcitxKey_1),
164-
candidate_window::scroll_key_action_t::one},
165-
{Key(FcitxKey_2),
166-
candidate_window::scroll_key_action_t::two},
167-
{Key(FcitxKey_3),
168-
candidate_window::scroll_key_action_t::three},
169-
{Key(FcitxKey_4),
170-
candidate_window::scroll_key_action_t::four},
171-
{Key(FcitxKey_5),
172-
candidate_window::scroll_key_action_t::five},
173-
{Key(FcitxKey_6),
174-
candidate_window::scroll_key_action_t::six},
160+
static const std::vector<candidate_window::scroll_key_action_t>
161+
selectActions = {
162+
candidate_window::scroll_key_action_t::one,
163+
candidate_window::scroll_key_action_t::two,
164+
candidate_window::scroll_key_action_t::three,
165+
candidate_window::scroll_key_action_t::four,
166+
candidate_window::scroll_key_action_t::five,
167+
candidate_window::scroll_key_action_t::six,
168+
candidate_window::scroll_key_action_t::seven,
169+
candidate_window::scroll_key_action_t::eight,
170+
candidate_window::scroll_key_action_t::nine,
171+
candidate_window::scroll_key_action_t::zero,
175172
};
176-
for (const auto &pair : selectMap) {
177-
if (key.check(pair.first)) {
178-
if (keyEvent.isRelease()) {
179-
return;
180-
}
181-
window_->scroll_key_action(pair.second);
182-
return keyEvent.filterAndAccept();
173+
if (int i =
174+
key.keyListIndex(*config_.scrollMode->selectCandidate);
175+
i >= 0 && i < selectActions.size()) {
176+
if (keyEvent.isRelease()) {
177+
return;
183178
}
179+
window_->scroll_key_action(selectActions[i]);
180+
return keyEvent.filterAndAccept();
184181
}
185182
const std::vector<std::pair<
186183
Option<KeyList>, candidate_window::scroll_key_action_t>>
@@ -504,8 +501,8 @@ void WebPanel::scroll(int start, int count) {
504501
}
505502

506503
void WebPanel::expand() {
507-
scroll(0, 6 * (*config_.scrollMode->maxRowCount +
508-
1)); // Hard-coded like fcitx5-webview
504+
scroll(0, *config_.scrollMode->maxColumnCount *
505+
(*config_.scrollMode->maxRowCount + 1));
509506
}
510507

511508
void WebPanel::collapse() {

webpanel/webpanel.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ FCITX_CONFIGURATION(
200200
Option<bool> animation{this, "Animation", _("Animation"), true};
201201
Option<int, IntConstrain> maxRowCount{
202202
this, "MaxRowCount", _("Max row count"), 6, IntConstrain(2, 10)};
203+
Option<int, IntConstrain> maxColumnCount{
204+
this, "MaxColumnCount", _("Max column count"), 6, IntConstrain(2, 10)};
203205
Option<KeyList> expand{
204206
this, "Expand", _("Expand"), {Key(FcitxKey_equal), Key(FcitxKey_Down)}};
205207
Option<KeyList> collapse{
@@ -218,6 +220,13 @@ FCITX_CONFIGURATION(
218220
Option<KeyList> pageDown{
219221
this, "PageDown", _("Page down"), {Key(FcitxKey_Page_Down)}};
220222
Option<KeyList> commit{this, "Commit", _("Commit"), {Key(FcitxKey_space)}};
223+
Option<KeyList> selectCandidate{
224+
this,
225+
"SelectCandidate",
226+
_("Select candidate"),
227+
{Key(FcitxKey_1), Key(FcitxKey_2), Key(FcitxKey_3), Key(FcitxKey_4),
228+
Key(FcitxKey_5), Key(FcitxKey_6), Key(FcitxKey_7), Key(FcitxKey_8),
229+
Key(FcitxKey_9), Key(FcitxKey_0)}};
221230
Option<bool> optimizeForHyperKey{this, "OptimizeForHyperKey",
222231
_("Optimize for Hyper key"), true};);
223232

@@ -311,6 +320,9 @@ FCITX_CONFIGURATION(
311320
Option<int, IntConstrain> verticalMinWidth{this, "VerticalMinWidth",
312321
_("Vertical minimum width (px)"),
313322
200, IntConstrain(0, 960)};
323+
Option<int, IntConstrain> scrollCellWidth{this, "ScrollCellWidth",
324+
_("Scroll cell width (px)"), 65,
325+
IntConstrain(40, 100)};
314326
Option<int, IntConstrain> horizontalDividerWidth{
315327
this, "HorizontalDividerWidth", _("Horizontal divider width (px)"), 1,
316328
IntConstrain(0, BORDER_WIDTH_MAX)};);

0 commit comments

Comments
 (0)