GnuCash
Contact   Instructions
Bug 797329 - Using Japanese IME to enter transactions results in unexpected field jumps
Summary: Using Japanese IME to enter transactions results in unexpected field jumps
Status: RESOLVED FIXED
Alias: None
Product: GnuCash
Classification: Unclassified
Component: MacOS (show other bugs)
Version: 3.5
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: macos
QA Contact: macos
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-07-29 10:39 EDT by justusw
Modified: 2021-09-23 18:45 EDT (History)
2 users (show)

See Also:


Attachments
This is where the text lands after pressing Enter (29.38 KB, image/png)
2019-07-29 10:39 EDT, justusw
no flags Details
Cursor position during IME selection screen (91.89 KB, image/png)
2020-05-19 23:48 EDT, justusw
no flags Details

Description justusw 2019-07-29 10:39:24 EDT
Created attachment 373337 [details]
This is where the text lands after pressing Enter

Here's what I'm doing:

1. I select "Blank" to enter a new transaction.
2. I navigate to the Description field of the new transaction
3. I enable my Japanese IME by selecting the "Hiragana" keyboard layout
4. In Romaji I type, e.g., famiri-ma-to, which the IME suggests I can convert toファミリーマート (Family Mart)
5. I press enter to select the suggestion

Now, I expected that

6. The entered value will be replaced by the suggested value and I can continue editing the description (This is the default behavior for IMEs on any OS)

But in reality, what happens is that

6. Before the IME has the chance to convert the text, GnuCash jumps to the next field, and
7. The IME inserts the description into the Action instead (I'm editing transaction in Transaction Journal mode)

It seems like the "Press Enter Key" event bubbles up incorrectly from the IME to GnuCash. The same holds true for pressing the arrow keys, Tab, and so on. All these key presses are incorrectly caught by GnuCash.

I use macOS Mojave 10.14.3 (18D109), and GnuCash Version: 3.5

This bug prevents me from using GnuCash in Japanese.
Build ID: 3.5+(2019-03-30), installed using Homebrew Cask
Comment 1 John Ralls 2019-07-29 10:55:31 EDT
This is probably a dupe of bug 797264; it's at least closely related.
Comment 2 justusw 2019-07-29 10:58:11 EDT
Thanks for your swift reply. If you have any patch I can try out, please let me know. I kind of wish I knew how to fix it myself!
Comment 3 John Ralls 2020-05-04 23:28:49 EDT
I've completely reworked the input method handling so that GnuCash doesn't get in the way anymore. There's one possibly serious consequence: Quickfill (aka autocomplete) can't see the input until you commit the input. This will especially affect account selection. It also seems to stop the hot-keys (+. -, [, ], etc.) from working in the Hiragana IM but not any of the Chinese ones. I haven't tried Korean.

I'm a bit hampered in testing and therefore working on these because I can't read the Japanese output and don't really know how to get it to enter those hot-key characters.

The changes will appear in the Windows and Flatpak nightlies, but there won't be a MacOS bundle until 3.903 is released at the end of the month--unless you say that you've got time to test before then, in which case I'll build one for you.
Comment 4 justusw 2020-05-05 00:01:53 EDT
(In reply to John Ralls from comment #3)
> I've completely reworked the input method handling so that GnuCash doesn't
> get in the way anymore. There's one possibly serious consequence: Quickfill
> (aka autocomplete) can't see the input until you commit the input. This will
> especially affect account selection. It also seems to stop the hot-keys (+.
> -, [, ], etc.) from working in the Hiragana IM but not any of the Chinese
> ones. I haven't tried Korean.
> 
> I'm a bit hampered in testing and therefore working on these because I can't
> read the Japanese output and don't really know how to get it to enter those
> hot-key characters.
> 
> The changes will appear in the Windows and Flatpak nightlies, but there
> won't be a MacOS bundle until 3.903 is released at the end of the
> month--unless you say that you've got time to test before then, in which
> case I'll build one for you.

If you need any help with testing, I'd me more than happy to help. I'm on macOS Catalina (10.15.4) right now.
Comment 5 John Ralls 2020-05-05 00:16:48 EDT
Super. I'll bundle up a build tomorrow and stick it on Sourceforge for you.
Comment 6 John Ralls 2020-05-05 14:11:38 EDT
https://sourceforge.net/projects/gnucash/files/Development/Gnucash-Intel-3.902-test-ime-1.dmg/download

The SHA-256 is 469584c2b75bb057d2241727688165025f4f9414c08ca9480067cbdd7b96aca5

Note that there's some weirdness in the account picker that's not related to the IM changes: If you enter text that doesn't match the drop-down goes blank. The only way to get it to repopulate is to remove all of the text from the field and start over, but if you back out the non-matching text and enter matching text it will appear to fill in the entry without bringing back the dropdown contents, but when you tab out the value won't be saved because nothing is selected in the dropdown. That originated in the typeahead search enhancements from last mont and I'm starting on fixing it now.
Comment 7 justusw 2020-05-19 03:11:54 EDT
(In reply to John Ralls from comment #6)
> https://sourceforge.net/projects/gnucash/files/Development/Gnucash-Intel-3.
> 902-test-ime-1.dmg/download
> 
> The SHA-256 is
> 469584c2b75bb057d2241727688165025f4f9414c08ca9480067cbdd7b96aca5
> 
> Note that there's some weirdness in the account picker that's not related to
> the IM changes: If you enter text that doesn't match the drop-down goes
> blank. The only way to get it to repopulate is to remove all of the text
> from the field and start over, but if you back out the non-matching text and
> enter matching text it will appear to fill in the entry without bringing
> back the dropdown contents, but when you tab out the value won't be saved
> because nothing is selected in the dropdown. That originated in the
> typeahead search enhancements from last mont and I'm starting on fixing it
> now.

Thanks for the upload. I just tried it, but couldn't get it to run (App would appear in Dock and then immediately disappear).

Running directly in shell (MacOS/Gnucash bin) gave me this:

=====
(process:75053): gnc.gui-WARNING **: 16:03:01.232: [mac_find_close_country()] Apple Locale is set to a value en_JP not supported by the C runtime

(process:75053): gnc.gui-WARNING **: 16:03:01.234: [mac_find_close_country()] Using ja_JP instead.

(process:75053): gnc.gui-WARNING **: 16:03:01.237: [mac_set_languages()] Language list: en:en_JP:C:ja_JP:ko_JP:de_JP:zh_CN:zh_CN


This is a development version. It may or may not work.
Report bugs and other problems to gnucash-devel@gnucash.org
You can also lookup and file bug reports at https://bugs.gnucash.org
To find the last stable version, please refer to https://www.gnucash.org/
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

Current thread 0x0000000111937dc0 (most recent call first):
fish: '/Users/justusperlwitz/Applicati…' terminated by signal SIGABRT (Abort)
===========

Looks like it's python related (I saw a python 3 dlib) and perhaps the required files are missing (e.g. encodings/__init__.py)
Comment 8 John Ralls 2020-05-19 13:08:03 EDT
Damn. I made a fresh one without Python: https://sourceforge.net/projects/gnucash/files/Development/Gnucash-Intel-3.902-test-ime-2.dmg/download
Comment 9 justusw 2020-05-19 23:47:25 EDT
Thanks for the new build. It works quite well! Almost feels native. Awesome job!

On a few occasions, it would enter the text twice, for example when I prepare to enter text, the IME selection screen pops up, and I switch focus to a different window (I think expected behavior would be to enter the text only once.

I could also notice that the cursor doesn't follow the input words and only jumps ahead once IME input is finished. I'm attaching a screenshot of how that looks like to this issue if that's OK.

All-in-all, this makes Gnucash much more usable! I wish I knew how to contribute to this project so that I can help with the fine tuning. But I also understand that some of this might be gtk related?
Comment 10 justusw 2020-05-19 23:48:25 EDT
Created attachment 373701 [details]
Cursor position during IME selection screen
Comment 11 John Ralls 2020-05-20 00:05:32 EDT
Good to know that it's forward progress.

I'm afraid that I'm not able to interpret the screen shot. I can't read more than a couple of words in Japanese and I can't intelligently use the IM. You'll need to tell me exactly what romaji to type, what characters to expect in the IM box and what should be appearing and isn't (or what is appearing and shouldn't) in the register. The bug tracker can handle unicode so you can type or paste Japanese into it.

The way to distinguish between GnuCash problems and Gtk problems is to try to use the IM in a dialog box. The Account Editor and Transfer Dialog are readily available from the menus, and the Transfer Dialog has an accelerator (it's command-T when typing in ASCII) though I can't get the accelerators to work when the IM is turned on. If it works differently in the Register and the dialog then it's a GnuCash problem; if it works the same it's a Gtk problem. However, I'm also a maintainer for Gtk so if I can figure out a Gtk IM problem I can fix that too.

Yes, I'd also think that text getting entered twice is unexpected behavior. ;-) Does it happen when you switch away from the GnuCash control or when you switch back? Is that for other GnuCash windows, other apps, or both?
Comment 12 justusw 2020-05-20 00:47:49 EDT
(In reply to John Ralls from comment #11)
> Good to know that it's forward progress.
> 
> I'm afraid that I'm not able to interpret the screen shot. I can't read more
> than a couple of words in Japanese and I can't intelligently use the IM.
> You'll need to tell me exactly what romaji to type, what characters to
> expect in the IM box and what should be appearing and isn't (or what is
> appearing and shouldn't) in the register. The bug tracker can handle unicode
> so you can type or paste Japanese into it.
> 
> The way to distinguish between GnuCash problems and Gtk problems is to try
> to use the IM in a dialog box. The Account Editor and Transfer Dialog are
> readily available from the menus, and the Transfer Dialog has an accelerator
> (it's command-T when typing in ASCII) though I can't get the accelerators to
> work when the IM is turned on. If it works differently in the Register and
> the dialog then it's a GnuCash problem; if it works the same it's a Gtk
> problem. However, I'm also a maintainer for Gtk so if I can figure out a Gtk
> IM problem I can fix that too.
> 
> Yes, I'd also think that text getting entered twice is unexpected behavior.
> ;-) Does it happen when you switch away from the GnuCash control or when you
> switch back? Is that for other GnuCash windows, other apps, or both?

You're right :) Sorry, I should have made a screen recording in the first place. If you have some time, could you look at this? https://youtu.be/KUDBtnPXNlo

I do two things in the video:

1) Enter text "akasata" (it's the first 4 syllables in the kana alphabet) in Find Transaction (watch how | cursor moves) and switch focus between desktop and app
2) Enter text "akasata" in random ledger (watch how | cursor moves before & after pressing enter) and switch focus between desktop and app

Observations:
1) Here I'm able to duplicate text by switching focus, given that I haven't "committed" (or converted) the raw input. The cursor follows correctly.
2) Here, I'm able to triplicate text, and I've also observed that the cursor doesn't follow the pending input.

So assuming that the Find dialog uses the GTK functionality, we can assume it's a GTK problem, according to what you've described before.

Then, the cursor not following in the ledger appears to be a GnuCash problem, but honestly I can absolutely live with that. It still feels "buggy" to me, as it deviates from common UI behavior.

Aside from CJK languages, there is another way to observe and replicate this, and I assume this will be easier for non CJK speakers. On macOS, dead keys are usually option+e/u/a (depending on kb layout). When, for example, trying to type ü, the keyboard input sequence is option+u, u.

1) When I do this here in Firefox typing this text, the cursor will have already wandered right after typing option+u, and my input will look like this: "¨|". Then, typing u will make the input look like this: "ü|" (with the pipe representing the cursor position.
2) Aside from the find dialog, or other more native GTK UIs in Gnucash, the Gnucash behavior with typing U umlaut is: "|" -> "|¨" -> "ü|"

It's like the cursor is "unaware" of the pending input and decides to wait until all input is finalized.

Sorry for the confusion and I hope this can clear it up. Let me know if you have any other questions :)
Comment 13 John Ralls 2020-05-23 19:51:36 EDT
OK, now I understand about the cursor. Interesting about the dead keys, I'd never noticed that (there are actually 5 on a US keyboard: `, e, i, n, and u).

Most of my work on this for the last couple of weeks has been on getting the cursor and selections to behave right.

Has quickfill ever worked well enough in Japanese to be of any use to you? It's mostly disabled now because it would interfere with the IM character prediction.
Comment 14 John Ralls 2020-05-26 18:24:17 EDT
> It's like the cursor is "unaware" of the pending input and decides to wait until all input is finalized.

That turned out to be exactly correct, but it took some major code-diving in the Gtk sources to figure out how to fix it. Fixed now, please take 3.903 for a spin after we release it this weekend.

Note You need to log in before you can comment on or make changes to this bug.