Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions demo/sdl3_renderer/nuklear_sdl3_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,20 +319,12 @@ nk_sdl_clipboard_paste(nk_handle usr, struct nk_text_edit *edit)
char *text;
int len;
NK_UNUSED(usr);

/* this function returns empty string on failure, not NULL */
text = SDL_GetClipboardText();
NK_ASSERT(text);

if (text[0] != '\0') {
/* FIXME: there is a bug in Nuklear that affects UTF8 clipboard handling
* "len" should be a buffer length, but due to bug it must be a glyph count
* see: https://github.com/Immediate-Mode-UI/Nuklear/pull/841 */
#if 0
len = nk_strlen(text);
#else
len = SDL_utf8strlen(text);
#endif
nk_textedit_paste(edit, text, len);
}
SDL_free(text);
Expand All @@ -341,27 +333,13 @@ nk_sdl_clipboard_paste(nk_handle usr, struct nk_text_edit *edit)
NK_INTERN void
nk_sdl_clipboard_copy(nk_handle usr, const char *text, int len)
{
const char *ptext;
char *str;
size_t buflen;
int i;
struct nk_sdl* sdl = (struct nk_sdl*)usr.ptr;
NK_ASSERT(sdl);
if (len <= 0 || text == NULL) return;

/* FIXME: there is a bug in Nuklear that affects UTF8 clipboard handling
* "len" is expected to be a buffer length, but due to bug it actually is a glyph count
* see: https://github.com/Immediate-Mode-UI/Nuklear/pull/841 */
#if 0
buflen = len + 1;
NK_UNUSED(ptext);
#else
ptext = text;
for (i = len; i > 0; i--)
(void)SDL_StepUTF8(&ptext, NULL);
buflen = (size_t)(ptext - text) + 1;
#endif

str = sdl->allocator.alloc(sdl->allocator.userdata, 0, buflen);
if (!str) return;
SDL_strlcpy(str, text, buflen);
Expand Down
30 changes: 16 additions & 14 deletions nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -8989,12 +8989,12 @@ nk_str_insert_at_rune(struct nk_str *str, int pos, const char *cstr, int len)
NK_API int
nk_str_insert_text_char(struct nk_str *str, int pos, const char *text, int len)
{
return nk_str_insert_text_utf8(str, pos, text, len);
return nk_str_insert_at_rune(str, pos, text, len) ? len : 0;
}
NK_API int
nk_str_insert_str_char(struct nk_str *str, int pos, const char *text)
{
return nk_str_insert_text_utf8(str, pos, text, nk_strlen(text));
return nk_str_insert_text_char(str, pos, text, nk_strlen(text));
}
NK_API int
nk_str_insert_text_utf8(struct nk_str *str, int pos, const char *text, int len)
Expand Down Expand Up @@ -27239,7 +27239,7 @@ nk_textedit_paste(struct nk_text_edit *state, char const *ctext, int len)
glyphs = nk_utf_len(ctext, len);
if (nk_str_insert_text_char(&state->string, state->cursor, text, len)) {
nk_textedit_makeundo_insert(state, state->cursor, glyphs);
state->cursor += len;
state->cursor += glyphs;
state->has_preferred_x = 0;
return 1;
}
Expand Down Expand Up @@ -28198,17 +28198,19 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
int cut = nk_input_is_key_pressed(in, NK_KEY_CUT);
if ((copy || cut) && (flags & NK_EDIT_CLIPBOARD))
{
int glyph_len;
nk_rune unicode;
const char *text;
int b = edit->select_start;
int e = edit->select_end;

int begin = NK_MIN(b, e);
int end = NK_MAX(b, e);
text = nk_str_at_const(&edit->string, begin, &unicode, &glyph_len);
if (edit->clip.copy)
edit->clip.copy(edit->clip.userdata, text, end - begin);
int begin = NK_MIN(edit->select_start, edit->select_end);
int end = NK_MAX(edit->select_start, edit->select_end);

if (edit->clip.copy) {
int glyph_len;
nk_rune unicode;
const char *text_begin, *text_end;
text_begin = nk_str_at_const(&edit->string, begin, &unicode, &glyph_len);
/*Reuse temporary variables (unicode, glyph_len)*/
text_end = nk_str_at_const(&edit->string, end, &unicode, &glyph_len);

edit->clip.copy(edit->clip.userdata, text_begin, (int)(text_end - text_begin));
}
if (cut && !(flags & NK_EDIT_READ_ONLY)){
nk_textedit_cut(edit);
cursor_follow = nk_true;
Expand Down
24 changes: 13 additions & 11 deletions src/nuklear_edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,17 +278,19 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
int cut = nk_input_is_key_pressed(in, NK_KEY_CUT);
if ((copy || cut) && (flags & NK_EDIT_CLIPBOARD))
{
int glyph_len;
nk_rune unicode;
const char *text;
int b = edit->select_start;
int e = edit->select_end;

int begin = NK_MIN(b, e);
int end = NK_MAX(b, e);
text = nk_str_at_const(&edit->string, begin, &unicode, &glyph_len);
if (edit->clip.copy)
edit->clip.copy(edit->clip.userdata, text, end - begin);
int begin = NK_MIN(edit->select_start, edit->select_end);
int end = NK_MAX(edit->select_start, edit->select_end);

if (edit->clip.copy) {
int glyph_len;
nk_rune unicode;
const char *text_begin, *text_end;
text_begin = nk_str_at_const(&edit->string, begin, &unicode, &glyph_len);
/*Reuse temporary variables (unicode, glyph_len)*/
text_end = nk_str_at_const(&edit->string, end, &unicode, &glyph_len);

edit->clip.copy(edit->clip.userdata, text_begin, (int)(text_end - text_begin));
}
if (cut && !(flags & NK_EDIT_READ_ONLY)){
nk_textedit_cut(edit);
cursor_follow = nk_true;
Expand Down
4 changes: 2 additions & 2 deletions src/nuklear_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ nk_str_insert_at_rune(struct nk_str *str, int pos, const char *cstr, int len)
NK_API int
nk_str_insert_text_char(struct nk_str *str, int pos, const char *text, int len)
{
return nk_str_insert_text_utf8(str, pos, text, len);
return nk_str_insert_at_rune(str, pos, text, len) ? len : 0;
}
NK_API int
nk_str_insert_str_char(struct nk_str *str, int pos, const char *text)
{
return nk_str_insert_text_utf8(str, pos, text, nk_strlen(text));
return nk_str_insert_text_char(str, pos, text, nk_strlen(text));
}
NK_API int
nk_str_insert_text_utf8(struct nk_str *str, int pos, const char *text, int len)
Expand Down
2 changes: 1 addition & 1 deletion src/nuklear_text_editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ nk_textedit_paste(struct nk_text_edit *state, char const *ctext, int len)
glyphs = nk_utf_len(ctext, len);
if (nk_str_insert_text_char(&state->string, state->cursor, text, len)) {
nk_textedit_makeundo_insert(state, state->cursor, glyphs);
state->cursor += len;
state->cursor += glyphs;
state->has_preferred_x = 0;
return 1;
}
Expand Down
Loading