From 934fa91f75eaf5af46ed188dbf3ed50576acb81c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 11 Feb 2013 09:40:33 +0000 Subject: patch [#34192] UTF-8 input in Python interactive console from Shinsuke Irie (irie) --- .../blender/editors/space_console/console_draw.c | 6 +++--- source/blender/editors/space_console/console_ops.c | 24 ++++++++++++++++------ 2 files changed, 21 insertions(+), 9 deletions(-) (limited to 'source/blender/editors/space_console') diff --git a/source/blender/editors/space_console/console_draw.c b/source/blender/editors/space_console/console_draw.c index 22c260de1a1..c195cb39157 100644 --- a/source/blender/editors/space_console/console_draw.c +++ b/source/blender/editors/space_console/console_draw.c @@ -158,9 +158,9 @@ static int console_textview_line_color(struct TextViewContext *tvc, unsigned cha if (tvc->iter_index == 0) { const SpaceConsole *sc = (SpaceConsole *)tvc->arg1; const ConsoleLine *cl = (ConsoleLine *)sc->history.last; - const int prompt_len = strlen(sc->prompt); - const int cursor_loc = cl->cursor + prompt_len; - const int line_len = cl->len + prompt_len; + const int prompt_len = BLI_strlen_utf8(sc->prompt); + const int cursor_loc = BLI_strnlen_utf8(cl->line, cl->cursor) + prompt_len; + const int line_len = BLI_strlen_utf8(cl->line) + prompt_len; int xy[2] = {CONSOLE_DRAW_MARGIN, CONSOLE_DRAW_MARGIN}; int pen[2]; xy[1] += tvc->lheight / 6; diff --git a/source/blender/editors/space_console/console_ops.c b/source/blender/editors/space_console/console_ops.c index 36716aeab95..5eed39a120e 100644 --- a/source/blender/editors/space_console/console_ops.c +++ b/source/blender/editors/space_console/console_ops.c @@ -36,6 +36,7 @@ #include "BLI_listbase.h" #include "BLI_string_cursor_utf8.h" +#include "BLI_string_utf8.h" #include "BLI_string.h" #include "BLI_dynstr.h" #include "BLI_utildefines.h" @@ -393,15 +394,26 @@ static int console_insert_invoke(bContext *C, wmOperator *op, wmEvent *event) { // if (!RNA_struct_property_is_set(op->ptr, "text")) { /* always set from keymap XXX */ if (!RNA_string_length(op->ptr, "text")) { - /* if alt/ctrl/super are pressed pass through */ - if (event->ctrl || event->oskey) { + /* if alt/ctrl/super are pressed pass through except for utf8 character event + * (when input method are used for utf8 inputs, the user may assign key event + * including alt/ctrl/super like ctrl+m to commit utf8 string. in such case, + * the modifiers in the utf8 character event make no sense.) */ + if ((event->ctrl || event->oskey) && !event->utf8_buf[0]) { return OPERATOR_PASS_THROUGH; } else { - char str[2]; - str[0] = event->ascii; - str[1] = '\0'; - + char str[BLI_UTF8_MAX + 1]; + size_t len; + + if (event->utf8_buf[0]) { + len = BLI_str_utf8_size_safe(event->utf8_buf); + memcpy(str, event->utf8_buf, len); + } + else { + /* in theory, ghost can set value to extended ascii here */ + len = BLI_str_utf8_from_unicode(event->ascii, str); + } + str[len] = '\0'; RNA_string_set(op->ptr, "text", str); } } -- cgit v1.2.3