New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TextInput: IME support for textinput #7009
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems mostly fine to me, ideally i'd like to see tests for it, calling window_on_textedit with known values and checking the resulting text is there should be enough. Seems no documentation change is needed, as users don't have to do anything to benefit from the change, so all fine on that side.
Code is clean, short and readable, so props for that.
|
||
def _bind_keyboard(self): | ||
super()._bind_keyboard() | ||
Window.bind(on_textedit=self.window_on_textedit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, maybe this should be at the same place that binds window_on_textinput?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried putting it in focus behavior for a bit, but it seems out of place somehow. I am not sure what else uses that superclass though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at FocusBehavior, it's a keyboard
instance that dispatch on_key_*
and on_textinput
events, so on_textedit
should be added to Keyboard
? Then you bind to on_textedit
on keyboard instance and not to Window
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but keyboards don't do IME events, it's the window/OS.
kivy/uix/textinput.py
Outdated
== self._imo_composition | ||
): # should always be true | ||
remove_old_imo_text = ( | ||
text[:pcc - len(self._imo_composition)] + text[pcc:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since you reuse that value, and the expression makes lines too long, it could be worth declaring it as len_imo
or something like this before the test.
kivy/uix/textinput.py
Outdated
@@ -2585,6 +2587,55 @@ def keyboard_on_textinput(self, window, text): | |||
self.delete_selection() | |||
self.insert_text(text, False) | |||
|
|||
# current imo composition in progress by the IME system, or '' if nothing | |||
_imo_composition = StringProperty("") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove ""
as empty string is a default value for StringProperty
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer being explicit over implicit here.
Added a test, which caught the _lines=[] case. Please check if it's handled correctly. |
See #6898
One bug persists, which is pressing an arrow key in the middle of a composition, which causes misplaced characters.
However this is unusual, desktop only, currently present in kivy as a bug, and seems to be caused by SDL.