diff options
| author | Manolo Gouy <Manolo> | 2016-12-17 07:42:54 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2016-12-17 07:42:54 +0000 |
| commit | 936486cb1ccaba88add3b7caa984cdf841e019f1 (patch) | |
| tree | 7011e04a877a24e8d1c6120b58762ca9b506075d /src/Fl_Text_Buffer.cxx | |
| parent | d0f6ef5d3207d39b5209a608117d3078e40acb39 (diff) | |
Handle non-ASCII characters when selecting a word or moving the cursor by one word.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12149 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Text_Buffer.cxx')
| -rw-r--r-- | src/Fl_Text_Buffer.cxx | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/Fl_Text_Buffer.cxx b/src/Fl_Text_Buffer.cxx index 9efcd6609..1b42234f3 100644 --- a/src/Fl_Text_Buffer.cxx +++ b/src/Fl_Text_Buffer.cxx @@ -825,17 +825,29 @@ int Fl_Text_Buffer::line_end(int pos) const { } +/** Returns whether character at position \p pos is a word separator. + Pos must be at a character boundary. + */ +bool Fl_Text_Buffer::is_word_separator(int pos) const { + int c = char_at(pos); + if (c < 128) { + return !(isalnum(c) || c == '_'); // non alphanumeric ASCII + } + return (c == 0xA0 || // NO-BREAK SPACE + (c >= 0x3000 && c <= 0x301F) // IDEOGRAPHIC punctuation + ); +} + + /* Find the beginning of a word. - NOT UNICODE SAFE. */ int Fl_Text_Buffer::word_start(int pos) const { - // FIXME: character is ucs-4 - while (pos>0 && (isalnum(char_at(pos)) || char_at(pos) == '_')) { + while (pos > 0 && !is_word_separator(pos)) + { pos = prev_char(pos); - } - // FIXME: character is ucs-4 - if (!(isalnum(char_at(pos)) || char_at(pos) == '_')) + } + if (is_word_separator(pos)) pos = next_char(pos); return pos; } @@ -843,11 +855,9 @@ int Fl_Text_Buffer::word_start(int pos) const { /* Find the end of a word. - NOT UNICODE SAFE. */ int Fl_Text_Buffer::word_end(int pos) const { - // FIXME: character is ucs-4 - while (pos < length() && (isalnum(char_at(pos)) || char_at(pos) == '_')) + while (pos < length() && !is_word_separator(pos)) { pos = next_char(pos); } |
