diff options
Diffstat (limited to 'src/Fl_Text_Editor.cxx')
| -rw-r--r-- | src/Fl_Text_Editor.cxx | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/src/Fl_Text_Editor.cxx b/src/Fl_Text_Editor.cxx index 5c2ef5996..880ca844c 100644 --- a/src/Fl_Text_Editor.cxx +++ b/src/Fl_Text_Editor.cxx @@ -34,6 +34,26 @@ #include <FL/Fl_Text_Editor.H> #include <FL/fl_ask.H> +static int utf_len(char c) +{ + if (!(c & 0x80)) return 1; + if (c & 0x40) { + if (c & 0x20) { + if (c & 0x10) { + if (c & 0x08) { + if (c & 0x04) { + return 6; + } + return 5; + } + return 4; + } + return 3; + } + return 2; + } + return 0; +} Fl_Text_Editor::Fl_Text_Editor(int X, int Y, int W, int H, const char* l) : Fl_Text_Display(X, Y, W, H, l) { @@ -198,8 +218,14 @@ int Fl_Text_Editor::kf_ignore(int, Fl_Text_Editor*) { } int Fl_Text_Editor::kf_backspace(int, Fl_Text_Editor* e) { - if (!e->buffer()->selected() && e->move_left()) - e->buffer()->select(e->insert_position(), e->insert_position()+1); + if (!e->buffer()->selected() && e->move_left()) { + int l = 1; + char c = e->buffer()->character(e->insert_position()); + if (c & 0x80 && c & 0x40) { + l = utf_len(c); + } + e->buffer()->select(e->insert_position(), e->insert_position()+l); + } kill_selection(e); e->show_insert_position(); e->set_changed(); @@ -343,8 +369,15 @@ int Fl_Text_Editor::kf_insert(int, Fl_Text_Editor* e) { } int Fl_Text_Editor::kf_delete(int, Fl_Text_Editor* e) { - if (!e->buffer()->selected()) - e->buffer()->select(e->insert_position(), e->insert_position()+1); + if (!e->buffer()->selected()) { + int l = 1; + char c = e->buffer()->character(e->insert_position()); + if (c & 0x80 && c & 0x40) { + l = utf_len(c); + } + e->buffer()->select(e->insert_position(), e->insert_position()+l); + } + kill_selection(e); e->show_insert_position(); e->set_changed(); @@ -399,7 +432,7 @@ int Fl_Text_Editor::handle_key() { // This uses the right-hand ctrl key as a "compose prefix" and returns // the changes that should be made to the text, as a number of // bytes to delete and a string to insert: - int del; + int del = 0; if (Fl::compose(del)) { if (del) buffer()->select(insert_position()-del, insert_position()); kill_selection(this); |
