DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L2376
Version: 1.3-feature


For the left/right arrow key navigation I've got the following
in my sandbox, and obviously they require further cleaning, but
I think these do what you require:

<pre>
/**  Moves the current insert position right one character.*/
int Fl_Text_Display::move_right() {
  int ok = 0;
  while (!ok) {
    if ( mCursorPos >= mBuffer->length() )
      return 0;
    const char *here = buffer()->address( mCursorPos );
    const char *there = fl_utf8fwd(here+1, here, here+6);
    int bytes = there - here;
    insert_position( mCursorPos + bytes );
    int pos = insert_position();
    // FIXME: character is ucs-4
    char c = buffer()->character( pos );
    if (!((c & 0x80) && !(c & 0x40))) ok = 1;
  }
  return 1;
}

/**  Moves the current insert position left one character.*/
int Fl_Text_Display::move_left() {
  int ok = 0;
  while (!ok) {
    if ( mCursorPos <= 0 )
      return 0;
    const char *here = buffer()->address( mCursorPos );
    const char *there = fl_utf8back(here-1, here-6, here);
    int bytes = here - there;
    insert_position( mCursorPos - bytes );
    int pos = insert_position();
    // FIXME: character is ucs-4
    char c = buffer()->character( pos );
    if (!((c & 0x80) && !(c & 0x40))) ok = 1;
  }
  return 1;
}
</pre>

If the pointer already points to a valid ASCII or UTF8 header byte,
then fl_utf8fwd simply returns the same pointer, so you have to
increment it before/as you pass it, hence the here+1. The here+6 is
because the longest possible UTF-8 sequence allowed is six bytes,
although in practice it's four. Similarly for move_left/fl_utf8back.

I'm also looking at your "patch" but I haven't yet seen any before
and after changes in behaviour during my testing, so still looking.
Not sure how UTF-8 sequences affect the parallel "style" buffer...

Any feedback welcome.


Link: http://www.fltk.org/str.php?L2376
Version: 1.3-feature

_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs

Reply via email to