From e8abfdb0c1d3e918bfaac2077cc7e5332c1cfaf9 Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 18 Oct 2023 22:55:18 +0800 Subject: Fix input method bugs on macos. There are a lot of problems about input methods and we will definitely spend more on this. And the bug made me awkward on today's interview when showing the demo. --- include/cru/platform/gui/InputMethod.h | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'include/cru') diff --git a/include/cru/platform/gui/InputMethod.h b/include/cru/platform/gui/InputMethod.h index 45e11c06..90d6b15a 100644 --- a/include/cru/platform/gui/InputMethod.h +++ b/include/cru/platform/gui/InputMethod.h @@ -21,6 +21,24 @@ struct CompositionText { TextRange selection; }; +/** + * \remarks I think it's time to standatdize this. The most important thing is + * the events. + * + * The events hould be triggered in this way. + * 1. Any time the IME begins to work, CompositionStartEvent is fired. Only + * once. Not triggerred again until CompositionEndEvent is fired. + * 2. Any time composition state changed, maybe user typed more characters, or + * user commit part of composition, CompositionEvent is fired. + * 3. TextEvent is fired when user commit part or whole of the composition. And + * you can use the args to get what characters are committed. So it is where you + * get the real text user want to give you. + * 4. Whenever a commit happens, TextEvent first, followed by CompositionEvent. + * Each for once. So use the TextEvent to get real input and use + * CompositionEvent to update UI. + * 5. When composition stops, a final CompositionEndEvent is fired. Also only + * once. + */ struct IInputMethodContext : virtual IPlatformResource { // Return true if you should draw composition text manually. Return false if // system will take care of that for you. @@ -36,20 +54,13 @@ struct IInputMethodContext : virtual IPlatformResource { virtual CompositionText GetCompositionText() = 0; - // Set the candidate window lefttop. Relative to window lefttop. Use this + // Set the candidate window left-top. Relative to window left-top. Use this // method to prepare typing. virtual void SetCandidateWindowPosition(const Point& point) = 0; - // Triggered when user starts composition. virtual IEvent* CompositionStartEvent() = 0; - - // Triggered when user stops composition. virtual IEvent* CompositionEndEvent() = 0; - - // Triggered every time composition text changes. virtual IEvent* CompositionEvent() = 0; - virtual IEvent* TextEvent() = 0; }; } // namespace cru::platform::gui - -- cgit v1.2.3