Index: src/drawtext.cxx =================================================================== --- src/drawtext.cxx (revision 4647) +++ src/drawtext.cxx (working copy) @@ -726,7 +726,7 @@ void fltk::measure(float (*getwidth)(const char*, int), const char* str, float& w, float& h, Flags flags) { - h = split(str, w, h, flags, getwidth); + h = split(str, (int)w, (int)h, flags, getwidth); w = max_x; setfont(normal_font, normal_size); } Index: src/TextEditor.cxx =================================================================== --- src/TextEditor.cxx (revision 4647) +++ src/TextEditor.cxx (working copy) @@ -32,6 +32,7 @@ #include #include #include +#include using namespace fltk; static void revert(Style* s) {} @@ -201,8 +202,22 @@ } int TextEditor::kf_backspace(int, TextEditor* 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 insertPosition = e->insert_position(); + int lineStartPos, visLineNum; + if (e->position_to_line(insertPosition, &visLineNum)) + lineStartPos = e->mLineStarts[ visLineNum ]; + else { + lineStartPos = e->line_start(insertPosition); + } + char *line = e->buffer()->line_text(insertPosition); + char *end = line+strlen(line); + const char *curr = line+insertPosition-lineStartPos; + const char *next = utf8fwd(curr+1, curr, end); + free(line); + if (*curr) insertPosition += (next-curr); + e->buffer()->select(e->insert_position(), insertPosition); + } kill_selection(e); e->show_insert_position(); e->set_changed(); @@ -344,8 +359,22 @@ } int TextEditor::kf_delete(int, TextEditor* e) { - if (!e->buffer()->selected()) - e->buffer()->select(e->insert_position(), e->insert_position()+1); + if (!e->buffer()->selected()) { + int insertPosition = e->insert_position(); + int lineStartPos, visLineNum; + if (e->position_to_line(insertPosition, &visLineNum)) + lineStartPos = e->mLineStarts[ visLineNum ]; + else { + lineStartPos = e->line_start(insertPosition); + } + char *line = e->buffer()->line_text(insertPosition); + char *end = line+strlen(line); + const char *curr = line+insertPosition-lineStartPos; + const char *next = utf8fwd(curr+1, curr, end); + free(line); + if (*curr) insertPosition += (next-curr); + e->buffer()->select(e->insert_position(), insertPosition); + } kill_selection(e); e->show_insert_position(); e->set_changed(); Index: src/TextDisplay.cxx =================================================================== --- src/TextDisplay.cxx (revision 4647) +++ src/TextDisplay.cxx (working copy) @@ -1549,6 +1549,7 @@ charLen = (nextStr - currStr); memcpy(expandedChar, currStr, charLen); expandedChar[charLen] = 0; + utf8 = true; } style = position_style( lineStartPos, lineLen, charIndex, outIndex + dispIndexOffset); @@ -1846,11 +1847,22 @@ if (X < text_area.x() - 1 || X > text_area.x() + text_area.w()) return; - /* For cursors other than the block, make them around 2/3 of a character - width, rounded to an even number of pixels so that X will draw an - odd number centered on the stem at x. */ - cursorWidth = 4; //(fontWidth/3) * 2; - left = X - cursorWidth / 2; + int lineStartPos, visLineNum; + if (position_to_line( mCursorPos, &visLineNum)) + lineStartPos = mLineStarts[ visLineNum ]; + else { + lineStartPos = buffer()->line_start( mCursorPos); + } + char *line = buffer()->line_text(mCursorPos); + int lineLen = vline_length(visLineNum); + const char *curr = line+mCursorPos-lineStartPos; + const char *next = utf8fwd(curr+1, curr, line+lineLen); + int charStyle = position_style( lineStartPos, lineLen, mCursorPos-lineStartPos, 0); + if (*curr != 0) + fontWidth = string_width(curr, next-curr, charStyle); + free(line); + cursorWidth = fontWidth; + left = X; right = left + cursorWidth; /* Create segments and draw cursor */ @@ -3162,6 +3174,13 @@ buffer()->line_end(dragPos)+1); } } + if (focused()) { + int spot_x, spot_y; + if (position_to_xy( mCursorPos, &spot_x, &spot_y)) { + transform(spot_x, spot_y); + fl_set_spot(textfont(), this, spot_x, spot_y); + } + } } int TextDisplay::handle(int event) {