community icon indicating copy to clipboard operation
community copied to clipboard

There is no way to get event.edit.start and event.edit.length

Open tamo opened this issue 6 years ago • 7 comments

Firstly, Kivy should not ignore event.edit.start and event.edit.length. edit: I misunderstood them ~~They have important meanings for Japanese IME. They indicate the place where the user is editing. I'll try to explain it metaphorically. IME is like a translator. You say "I love you," and a French translator says, "Je vous aime." You'd think, "No, use 'te' instead of 'vous.'" In this case, event.edit.text=="Je vous aime", event.edit.start==3, and event.edit.length==4.~~

You press space key, and the translator (IME) will give you a number of candidates (including "te" in the above case). So secondly, this space key (and other keys while editing) should be ignored by Kivy. It's consumed by IME.

Lastly, honestly speaking, I haven't compiled Kivy myself yet. The only thing I have really used is here: https://osdn.net/users/tamomo/pf/MekikuViewer/scm/blobs/master/IMETextInput.py So, I'm violating Kivy's contribution guideline. I will install Visual C++ and other dependencies next week or later. But I'd like to give you a pull request for now.

Thanks!

tamo avatar Sep 01 '19 13:09 tamo

Thanks for opening your first pull request here! 💖 Please check out our contributing guidelines.

welcome[bot] avatar Sep 01 '19 13:09 welcome[bot]

Hey, I managed to build Kivy with Visual Studio on my machine, sacrificing my sleep. I've just tested it, and it (almost) works.

Bugs:

  1. SDL always returns length==0: https://bugzilla.libsdl.org/show_bug.cgi?id=4782
  2. Kivy's TextInput doesn't allow suggestion_text when len(self.text)==0: I have a workaround in https://osdn.net/users/tamomo/pf/MekikuViewer/scm/blobs/master/IMETextInput.py

So there's nothing wrong in my code so far. ;)

tamo avatar Sep 01 '19 19:09 tamo

Won't this break backwards compatibility for on_textedit? I suppose if there's no other way to do this it's ok, but is this the only way?

matham avatar Sep 01 '19 20:09 matham

Hmm, I should have thought of it more deeply. Sorry to have bothered you. I'll try it out some day again.

tamo avatar Sep 02 '19 05:09 tamo

Closing it, I'd tell you that on_suggestion_text has a bug I fixed in this fork: suggestion_text should appear after cursor_col, but the current code ignores cursor_col. You can cherry-pick the fix.

tamo avatar Sep 02 '19 05:09 tamo

I hope you didn't close it because of my comment. I didn't mean to reject the changes, but rather to see if you could find a way to do it without new parameters to on_textedit. But if there's no other way, this is fine if it fixes a bug.

matham avatar Sep 02 '19 07:09 matham

Thanks for your kind words, Matham. I haven't found another way so far, but I will try someday.

tamo avatar Sep 02 '19 14:09 tamo