imgui icon indicating copy to clipboard operation
imgui copied to clipboard

Marked Text / `SDL_TEXTEDITING` Event / IME Composition support

Open vkedwardli opened this issue 3 years ago • 1 comments

It was briefly discussed in https://github.com/ocornut/imgui/pull/3108

Need to figure out whether need to add markedText support and how. It requires to display the markedText, but not sure with imgui, what's the best way of doing that

As an example, the Lite XL app is handling the Composition perfectly (it is backed by SDL2, composition string, selected range are feed from the SDL_TEXTEDITING event) Nov-10-2022 15-12-44

//  [ ] Platform: SDL2 handling of IME under Windows appears to be broken and it explicitly disable the regular Windows IME. You can restore Windows IME by compiling SDL with SDL_DISABLE_WINDOWS_IME.

The above statement is partially correct, with the SDL_HINT_IME_SHOW_UI, imgui with SDL2 can show the Candidate List, but the Composition is feeding from SDL_TEXTEDITING event, and requires you to draw it. image

With SDL_DISABLE_WINDOWS_IME, Windows will be responsible for drawing the Composition also, but unfortunately other OS e.g. macOS, does not draw it for you.

What would be the preferred approach to implement this? I could try to make a PR

vkedwardli avatar Nov 10 '22 07:11 vkedwardli

Relevant project: github/maildrop/DearImGui-with-IMM32

vkedwardli avatar Nov 11 '22 09:11 vkedwardli

IHMO SDL is putting too much burden on the app with SDL_TEXTEDITING / SDL_TEXTEDITING_EXT but it should be possible to handle. We'd need to draw a blinking caret and mainly design all the IO for it.

I guess it could be a io.AddImeTextEditingEvent(const char* str, int start, int length); or io.AddPlatformImeTextEditingEvent() but we'd need to investigate the data provided by other tech to design the best API. Perhaps safer to pass this in a structure so it may be extended.

Then dear imgui needs to somehow store this data and draw it with a caret.

ocornut avatar Feb 07 '23 18:02 ocornut

IBus makes this an option.

IBus Preferences: image

https://github.com/ibus/ibus/blob/dfad02bb00ecf24a0f3b403c0aa96ad4890bdcb1/data/dconf/org.freedesktop.ibus.gschema.xml#L93-L97

In XTerm, the preedit text is displayed by IBus even if this option is turned on.

https://github.com/ocornut/imgui/assets/74560659/65d13d7c-873e-4d71-8aa2-06544574766a

So there must be some way to display this text.

iacore avatar Jul 29 '23 01:07 iacore

SDL_HINT_IME_SHOW_UI seems to be a Windows-only feature. Not sure what it does.

https://github.com/search?q=repo%3Alibsdl-org%2FSDL%20SDL_HINT_IME_SHOW_UI&type=code

Anyway I've fixed it.

iacore avatar Jul 29 '23 02:07 iacore

@iacore I don't think your PR can fix this issue.

From SDL2 2.0.4 changelog:

Added IBus IME support Added a hint SDL_HINT_IME_INTERNAL_EDITING to control whether IBus should handle text editing internally instead of sending SDL_TEXTEDITING events

SDL_HINT_IME_INTERNAL_EDITING is for IBus only (at that time, but I don't know what other platforms support this).

I've showed what SDL_HINT_IME_SHOW_UI can achieve in the screenshots when discussing about the Windows IME support in current IMGUI/SDL, this issue is not aiming to solve a specific platform (or else I could just make a PR for Windows), but to see what should be done to support all platforms, so I was asking the feasibility on implementing SDL_TEXTEDITING

vkedwardli avatar Aug 03 '23 03:08 vkedwardli