Skip to content

Commit

Permalink
feat(editor)!: Merge DOWN and SPACE key behavior in pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
kanru committed Jul 13, 2024
1 parent 4766ad9 commit a85e3ca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 31 deletions.
30 changes: 4 additions & 26 deletions src/editor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1224,20 +1224,9 @@ impl Selecting {
}
}
fn total_page(&self, editor: &SharedState, dict: &Layered) -> usize {
// MSRV: stable after rust 1.73
fn div_ceil(lhs: usize, rhs: usize) -> usize {
let d = lhs / rhs;
let r = lhs % rhs;
if r > 0 && rhs > 0 {
d + 1
} else {
d
}
}
div_ceil(
self.candidates(editor, dict).len(),
editor.options.candidates_per_page,
)
self.candidates(editor, dict)
.len()
.div_ceil(editor.options.candidates_per_page)
}
fn select(&mut self, editor: &mut SharedState, n: usize) -> Transition {
let offset = self.page_no * editor.options.candidates_per_page + n;
Expand Down Expand Up @@ -1315,7 +1304,7 @@ impl State for Selecting {
shared.cancel_selecting();
self.start_entering()
}
Space => {
Down | Space => {
if self.page_no + 1 < self.total_page(shared, &shared.dict) {
self.page_no += 1;
} else {
Expand All @@ -1330,17 +1319,6 @@ impl State for Selecting {
}
self.spin_absorb()
}
Down => {
match &mut self.sel {
Selector::Phrase(sel) => {
sel.next(&shared.dict);
self.page_no = 0;
}
Selector::Symbol(_sel) => (),
Selector::SpecialSymmbol(_sel) => (),
}
self.spin_absorb()
}
J => {
if shared.com.is_empty() {
return self.spin_ignore();
Expand Down
10 changes: 5 additions & 5 deletions tests/test-bopomofo.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ void test_select_candidate_no_rearward()
type_keystroke_by_string(ctx, "<D>"); /* ㄧˊㄕㄤˋㄌㄞˊ */
ok_candidate(ctx, CAND_1, ARRAY_SIZE(CAND_1));

type_keystroke_by_string(ctx, "<D>"); /* ㄕㄤˋㄌㄞˊ */
type_keystroke_by_string(ctx, "<D>"); /* 移上 */
ok_candidate(ctx, CAND_2, ARRAY_SIZE(CAND_2));

type_keystroke_by_string(ctx, "<D><D>2<E>"); /* select 移上來 */
type_keystroke_by_string(ctx, "<D><L><D>2<E>"); /* select 移上來 */
ok_commit_buffer(ctx, CAND_1[1]);

chewing_delete(ctx);
Expand Down Expand Up @@ -103,7 +103,7 @@ void test_select_candidate_rearward()
type_keystroke_by_string(ctx, "<D>"); /* ㄕㄤˋㄌㄞˊ */
ok_candidate(ctx, CAND_2, ARRAY_SIZE(CAND_2));

type_keystroke_by_string(ctx, "<D><D>2<E>"); /* select 移上來 */
type_keystroke_by_string(ctx, "<D><L><D>2<E>"); /* select 移上來 */
ok_commit_buffer(ctx, CAND_1[1]);

chewing_delete(ctx);
Expand Down Expand Up @@ -468,7 +468,7 @@ void test_select_candidate_second_page_rewind()
chewing_set_candPerPage(ctx, 9);
chewing_set_spaceAsSelection(ctx, 1);
chewing_set_phraseChoiceRearward(ctx, 1);
type_keystroke_by_string(ctx, "zp zp <D><D><R><D>"); /* ㄈㄣ ㄈㄣ */
type_keystroke_by_string(ctx, "zp zp <D><D><R><D><D>"); /* ㄈㄣ ㄈㄣ */
ok_candidate(ctx, CAND, ARRAY_SIZE(CAND));

chewing_delete(ctx);
Expand Down Expand Up @@ -1698,7 +1698,7 @@ void test_KB_HSU_example()
ok_preedit_buffer(ctx, "一隻隻可愛的小花貓");
chewing_clean_preedit_buf(ctx);

type_keystroke_by_string(ctx, "sm sxajdwj<D><D>1xfsxajdgscewfhidxfdwj<D><D>1cd<D><D>1rnd");
type_keystroke_by_string(ctx, "sm sxajdwj<D><D>1xfsxajdgscewfhidxfdwj<D><D>1cd<D>1rnd");
ok_preedit_buffer(ctx, "三歲到五歲的小孩五到十人");
chewing_clean_preedit_buf(ctx);

Expand Down

0 comments on commit a85e3ca

Please sign in to comment.