Merge lp:~cosmos-door/unity/fix-preedit-663776 into lp:unity

Proposed by Mitsuya Shibata on 2011-09-14
Status: Merged
Merged at revision: 1665
Proposed branch: lp:~cosmos-door/unity/fix-preedit-663776
Merge into: lp:unity
Diff against target: 73 lines (+37/-0)
1 file modified
plugins/unityshell/src/IMTextEntry.cpp (+37/-0)
To merge this branch: bzr merge lp:~cosmos-door/unity/fix-preedit-663776
Reviewer Review Type Date Requested Status
Neil J. Patel (community) 2011-09-14 Approve on 2011-09-29
Review via email: mp+75350@code.launchpad.net

Description of the change

Fix unvisible pre-edit text in Dash with iBus.
https://bugs.launchpad.net/ubuntu-translations/+bug/663776/comments/77

How to reproduce:
1. Open Dash.
2. Startup Input Method(in Japanese, press Ctrl+Space)
  -> emit signal "preedit-start"
3. Type 'a', preedit text should be render, but dont
  -> emit signal "preedit-changed"
4. Press Enter, preedit text is fixed
  -> emit signal "commit", and render text in Dash

In code:
OnCommit signal handler call SetText, then text is rendered.
However OnPreeditChanged signal handler do nothing.

This branch add code to render preedit text in OnPreeditChanged.
And at OnCommit, remove preedit text, and reset cursor position.

To post a comment you must log in.
Mitsuya Shibata (cosmos-door) wrote :

Please refer comments since #71 in LP: #663776

Neil J. Patel (njpatel) wrote :

Excellent work, approved (with additional fixes so we don't do the tab-to-switch-lenses when im is active).

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/unityshell/src/IMTextEntry.cpp'
2--- plugins/unityshell/src/IMTextEntry.cpp 2011-09-11 16:51:43 +0000
3+++ plugins/unityshell/src/IMTextEntry.cpp 2011-09-14 13:39:38 +0000
4@@ -178,6 +178,10 @@
5 if (eventType != NUX_KEYDOWN)
6 return false;
7
8+ /* If IM is active, de-activate Copy & Paste */
9+ if (im_active_)
10+ return true;
11+
12 if (((keyval == NUX_VK_x) && ctrl && !shift) ||
13 ((keyval == NUX_VK_DELETE) && shift && !ctrl))
14 {
15@@ -238,6 +242,17 @@
16 {
17 LOG_DEBUG(logger) << "Commit: " << str;
18 DeleteSelection();
19+
20+ /* remove preedit text and set cursor to previous position */
21+ if (preedit_cursor_) {
22+ std::string new_text = GetText();
23+ new_text.replace(cursor_, preedit_cursor_, "");
24+ int cursor = cursor_;
25+ SetText(new_text.c_str());
26+ SetCursor(cursor);
27+ preedit_cursor_ = 0;
28+ }
29+
30 if (str)
31 {
32 std::string new_text = GetText();
33@@ -260,12 +275,24 @@
34 LOG_DEBUG(logger) << "Preedit changed: " << preedit;
35
36 preedit_string = preedit.Str();
37+
38+ if (strlen(preedit.Str().c_str())) {
39+ DeleteSelection();
40+ std::string new_text = GetText();
41+ new_text.replace(cursor_, preedit_cursor_, preedit.Str());
42+ int cursor = cursor_;
43+ SetText(new_text.c_str());
44+ SetCursor(cursor);
45+ preedit_cursor_ = preedit.Str().length();
46+ UpdateCursorLocation();
47+ }
48 }
49
50 void IMTextEntry::OnPreeditStart(GtkIMContext* context)
51 {
52 preedit_string = "";
53 im_active_ = true;
54+ preedit_cursor_ = 0;
55
56 LOG_DEBUG(logger) << "Preedit start";
57 }
58@@ -276,6 +303,16 @@
59 im_active_ = false;
60 gtk_im_context_reset(im_context_);
61
62+ /* remove preedit text and set cursor to previous position */
63+ if (preedit_cursor_) {
64+ std::string new_text = GetText();
65+ new_text.replace(cursor_, preedit_cursor_, "");
66+ int cursor = cursor_;
67+ SetText(new_text.c_str());
68+ SetCursor(cursor);
69+ preedit_cursor_ = 0;
70+ }
71+
72 LOG_DEBUG(logger) << "Preedit ended";
73 }
74