Skip to content

Commit d313601

Browse files
committed
fix: keyboard.text_cursor for selection range
1 parent 4a30ff5 commit d313601

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/nuklear_edit.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,12 +583,23 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
583583
row_height, font, background_color, text_color, nk_false);
584584
}
585585
if (edit->select_start != edit->select_end) {
586+
int glyph_len;
587+
nk_rune unicode;
588+
586589
/* draw selected text */
587590
NK_ASSERT(select_begin_ptr);
588591
if (!select_end_ptr) {
589592
const char *begin = nk_str_get_const(&edit->string);
590593
select_end_ptr = begin + nk_str_len_char(&edit->string);
591594
}
595+
596+
glyph_len = nk_utf_decode(select_begin_ptr, &unicode, (int)(select_end_ptr - select_begin_ptr));
597+
/* In this case, we set the cursor to the first selected character */
598+
kb_text_cursor = nk_rect(
599+
area.x + selection_offset_start.x - edit->scrollbar.x,
600+
area.y + selection_offset_start.y - edit->scrollbar.y,
601+
font->width(font->userdata, font->height, select_begin_ptr, glyph_len), row_height);
602+
592603
nk_edit_draw_text(out, style,
593604
area.x - edit->scrollbar.x,
594605
area.y + selection_offset_start.y - edit->scrollbar.y,

0 commit comments

Comments
 (0)