diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2026-01-18 18:04:06 +0100 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2026-01-18 18:04:06 +0100 |
| commit | f3cbce2e92c6088e7bb062d7094a7e6b23fbdb56 (patch) | |
| tree | 3336d99ba756727fa8d404a3dc1a92481ceed048 /src/Fl_cocoa.mm | |
| parent | 20157f7caa497274b2ab278009c8d13836dd5143 (diff) | |
Emoji input: remove context-dependent unicode points from output of emoji palette.
The character palette allowing to input emojis in text generates in some cases a series
of unicode points to represent a single emoji. These series contain various kinds of
unicode points with context-dependent meaning. This commit prevents such context-
dependent unicodepoints from being inserted in FLTK text because FLTK text edition
mechanism is not ready to handle properly context dependency in edited UTF-8 text.
Diffstat (limited to 'src/Fl_cocoa.mm')
| -rw-r--r-- | src/Fl_cocoa.mm | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index 51eeced51..eeeedf425 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -2954,8 +2954,23 @@ static FLTextInputContext* fltextinputcontext_instance = nil; BOOL has_text_key = Fl::e_keysym <= '~' || Fl::e_keysym == FL_Iso_Key || (Fl::e_keysym >= FL_KP && Fl::e_keysym <= FL_KP_Last && Fl::e_keysym != FL_KP_Enter); // insertText sent during handleEvent of a key without text cannot be processed in a single FL_KEYBOARD event. - // Occurs with deadkey followed by non-text key + // Occurs with deadkey followed by non-text key. Occurs also with emoji palette. if (!in_key_event || !has_text_key) { + if (fl_utf_nb_char((const uchar*)Fl::e_text, Fl::e_length) > 1) { + // Some emojis are expressed by a series of Unicode points + const char *p = Fl::e_text, *end = Fl::e_text + Fl::e_length; + int len; + while (p < end) { // loop over all unicode points of the series + unsigned u = fl_utf8decode(p, end, &len); // extract one such unicode point + if ((u >= 0xFE00 && u <= 0xFE0F) // variation selectors + || u == 0x200D // zero-width joiner + || (u >= 0x1F3FB && u <= 0x1F3FF) // EMOJI MODIFIERS FITZPATRICK TYPE + ) { // remove context-dependent unicode points + memmove((void*)p, p + len, (end - (p+len)) + 1); + Fl::e_length -= len; end -= len; + } else p += len; // keep other unicode points + } + } Fl::handle(FL_KEYBOARD, target); Fl::e_length = 0; } |
