summaryrefslogtreecommitdiff
path: root/src/Fl_cocoa.mm
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2026-01-19 16:34:50 +0100
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2026-01-19 16:34:50 +0100
commit61e75e4a12f199368f28dd274d83fc4ecd9cfec3 (patch)
tree94c71a1dffe9c6d9ac4a51dbec84561d38828b2c /src/Fl_cocoa.mm
parent59d93554b3aff9614276fec99792807d77b24ee5 (diff)
All platforms use same code to remove context-dependent codepoints from text input.
This commit introduces function fl_utf8_remove_context_dependent() that removes from an UTF-8 string its context-dependent codepoints. Platforms macOS, Wayland and X11 call this function to process UTF-8 text received from a character palette as input to FLTK text. This makes sure FLTK text-editing widgets process textual input equally and consistently across platforms, especially emojis entered via a palette. Platform Windows creates a series of separate system events to input an emoji via the character palette. For this reason, function fl_utf8_remove_context_dependent() is not used by this platform which does internally the same filtering of context- dependent codepoints.
Diffstat (limited to 'src/Fl_cocoa.mm')
-rw-r--r--src/Fl_cocoa.mm17
1 files changed, 2 insertions, 15 deletions
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index eeeedf425..fed978e1e 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -67,6 +67,7 @@ extern "C" {
// external functions
extern void fl_fix_focus();
extern int fl_send_system_handlers(void *e);
+extern int fl_utf8_remove_context_dependent(char *text, int len);
// forward definition of functions in this file
// converting cr lf converter function
@@ -2956,21 +2957,7 @@ static FLTextInputContext* fltextinputcontext_instance = nil;
// 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 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::e_length = fl_utf8_remove_context_dependent(Fl::e_text, Fl::e_length);
Fl::handle(FL_KEYBOARD, target);
Fl::e_length = 0;
}