Package: ibus-zhuyin / 0.1.0-2

Fix-the-indexing-issue-of-last-page.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
Description: Fix the indexing issue of last page.
Author: Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
Origin: upstream, https://github.com/fourdollars/ibus-zhuyin/commit/d52bdffa8e4181ff6f953304630add2eca03daa3
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/

From d52bdffa8e4181ff6f953304630add2eca03daa3 Mon Sep 17 00:00:00 2001
From: "Shih-Yuan Lee (FourDollars)" <fourdollars@gmail.com>
Date: Wed, 12 Jul 2017 22:17:39 +0800
Subject: [PATCH] Fix the indexing issue of last page.

---
 src/engine.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/engine.c b/src/engine.c
index 2c9ed9b..aba938b 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -30,6 +30,7 @@ struct _IBusZhuyinEngine {
     gint mode;
     gint cursor_pos;
     gint page;
+    gint page_max;
     gint page_size;
     gchar* display[4];
     gchar input[4];
@@ -761,6 +762,10 @@ ibus_zhuyin_preedit_phase (IBusZhuyinEngine *zhuyin,
 
         zhuyin->candidate_member = zhuyin_candidate(stanza, &i);
         zhuyin->candidate_number = i;
+        if (zhuyin->candidate_number % zhuyin->page_size)
+            zhuyin->page_max = zhuyin->candidate_number / zhuyin->page_size;
+        else
+            zhuyin->page_max = zhuyin->candidate_number / zhuyin->page_size - 1;
 
         /* directly commit when only one candidate. */
         if (type == 4 && zhuyin->candidate_number == 1) {
@@ -888,7 +893,7 @@ ibus_zhuyin_candidate_phase (IBusZhuyinEngine *zhuyin,
             ibus_lookup_table_page_up(zhuyin->table);
             zhuyin->page--;
             if (zhuyin->page < 0) {
-                zhuyin->page = (zhuyin->candidate_number + zhuyin->page_size) / (zhuyin->page_size + 1) - 1;
+                zhuyin->page = zhuyin->page_max;
             }
             ibus_engine_update_lookup_table ((IBusEngine *) zhuyin, zhuyin->table, TRUE);
             return TRUE;
@@ -898,7 +903,7 @@ ibus_zhuyin_candidate_phase (IBusZhuyinEngine *zhuyin,
         case IBUS_Down:
             ibus_lookup_table_page_down(zhuyin->table);
             zhuyin->page++;
-            if (zhuyin->page >= (zhuyin->candidate_number + zhuyin->page_size) / (zhuyin->page_size + 1)) {
+            if (zhuyin->page > zhuyin->page_max) {
                 zhuyin->page = 0;
             }
             ibus_engine_update_lookup_table ((IBusEngine *) zhuyin, zhuyin->table, TRUE);
-- 
2.7.4