From bd4ad3e4a0c8e3153d9d3b532d9c572f5aaad897 Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Sat, 24 Jan 2026 16:15:47 +0100 Subject: Let Fl_Text_Editor and Fl_Input handle gracefully composed unicode characters. --- src/Fl_Text_Buffer.cxx | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'src/Fl_Text_Buffer.cxx') diff --git a/src/Fl_Text_Buffer.cxx b/src/Fl_Text_Buffer.cxx index c33e36d3a..907a5cce6 100644 --- a/src/Fl_Text_Buffer.cxx +++ b/src/Fl_Text_Buffer.cxx @@ -1,5 +1,5 @@ // -// Copyright 2001-2023 by Bill Spitzak and others. +// Copyright 2001-2026 by Bill Spitzak and others. // Original code Copyright Mark Edel. Permission to distribute under // the LGPL for the FLTK library granted by Mark Edel. // @@ -2090,14 +2090,8 @@ int Fl_Text_Buffer::prev_char_clipped(int pos) const return 0; IS_UTF8_ALIGNED2(this, (pos)) - - char c; - do { - pos--; - if (pos==0) - return 0; - c = byte_at(pos); - } while ( (c&0xc0) == 0x80); + const char *previous = fl_utf8_previous_composed_char(address(0) + pos, address(0)); + pos = previous - address(0); IS_UTF8_ALIGNED2(this, (pos)) return pos; @@ -2122,8 +2116,8 @@ int Fl_Text_Buffer::prev_char(int pos) const int Fl_Text_Buffer::next_char(int pos) const { IS_UTF8_ALIGNED2(this, (pos)) - int n = fl_utf8len1(byte_at(pos)); - pos += n; + const char *next = fl_utf8_next_composed_char(address(0) + pos, address(0) + mLength); + pos = next - address(0); if (pos>=mLength) return mLength; IS_UTF8_ALIGNED2(this, (pos)) -- cgit v1.2.3