diff options
Diffstat (limited to 'source/blender/editors/space_console/console_ops.c')
-rw-r--r-- | source/blender/editors/space_console/console_ops.c | 64 |
1 files changed, 38 insertions, 26 deletions
diff --git a/source/blender/editors/space_console/console_ops.c b/source/blender/editors/space_console/console_ops.c index 36716aeab95..74f776549e9 100644 --- a/source/blender/editors/space_console/console_ops.c +++ b/source/blender/editors/space_console/console_ops.c @@ -34,11 +34,12 @@ #include "DNA_userdef_types.h" +#include "BLI_utildefines.h" #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" #include "BLI_math.h" #include "BKE_context.h" @@ -115,7 +116,7 @@ static ConsoleLine *console_history_find(SpaceConsole *sc, const char *str, Cons } /* return 0 if no change made, clamps the range */ -static int console_line_cursor_set(ConsoleLine *cl, int cursor) +static bool console_line_cursor_set(ConsoleLine *cl, int cursor) { int cursor_new; @@ -124,11 +125,11 @@ static int console_line_cursor_set(ConsoleLine *cl, int cursor) else cursor_new = cursor; if (cursor_new == cl->cursor) { - return FALSE; + return false; } cl->cursor = cursor_new; - return TRUE; + return true; } #if 0 // XXX unused @@ -187,7 +188,7 @@ static ConsoleLine *console_scrollback_add(const bContext *C, ConsoleLine *from) } #endif -static ConsoleLine *console_lb_add_str__internal(ListBase *lb, char *str, int own) +static ConsoleLine *console_lb_add_str__internal(ListBase *lb, char *str, bool own) { ConsoleLine *ci = MEM_callocN(sizeof(ConsoleLine), "ConsoleLine Add"); if (own) ci->line = str; @@ -198,11 +199,11 @@ static ConsoleLine *console_lb_add_str__internal(ListBase *lb, char *str, int ow BLI_addtail(lb, ci); return ci; } -ConsoleLine *console_history_add_str(SpaceConsole *sc, char *str, int own) +ConsoleLine *console_history_add_str(SpaceConsole *sc, char *str, bool own) { return console_lb_add_str__internal(&sc->history, str, own); } -ConsoleLine *console_scrollback_add_str(SpaceConsole *sc, char *str, int own) +ConsoleLine *console_scrollback_add_str(SpaceConsole *sc, char *str, bool own) { ConsoleLine *ci = console_lb_add_str__internal(&sc->scrollback, str, own); console_select_offset(sc, ci->len + 1); @@ -275,7 +276,7 @@ static int console_move_exec(bContext *C, wmOperator *op) ConsoleLine *ci = console_history_verify(C); int type = RNA_enum_get(op->ptr, "type"); - int done = FALSE; + bool done = false; int pos; switch (type) { @@ -283,28 +284,28 @@ static int console_move_exec(bContext *C, wmOperator *op) pos = ci->cursor; BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_PREV, - STRCUR_JUMP_ALL); + STRCUR_JUMP_ALL, true); done = console_line_cursor_set(ci, pos); break; case LINE_END: pos = ci->cursor; BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_NEXT, - STRCUR_JUMP_ALL); + STRCUR_JUMP_ALL, true); done = console_line_cursor_set(ci, pos); break; case PREV_CHAR: pos = ci->cursor; BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_PREV, - STRCUR_JUMP_NONE); + STRCUR_JUMP_NONE, true); done = console_line_cursor_set(ci, pos); break; case NEXT_CHAR: pos = ci->cursor; BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_NEXT, - STRCUR_JUMP_NONE); + STRCUR_JUMP_NONE, true); done = console_line_cursor_set(ci, pos); break; @@ -314,14 +315,14 @@ static int console_move_exec(bContext *C, wmOperator *op) pos = ci->cursor; BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_PREV, - STRCUR_JUMP_DELIM); + STRCUR_JUMP_DELIM, true); done = console_line_cursor_set(ci, pos); break; case NEXT_WORD: pos = ci->cursor; BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_NEXT, - STRCUR_JUMP_DELIM); + STRCUR_JUMP_DELIM, true); done = console_line_cursor_set(ci, pos); break; } @@ -389,19 +390,30 @@ static int console_insert_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -static int console_insert_invoke(bContext *C, wmOperator *op, wmEvent *event) +static int console_insert_invoke(bContext *C, wmOperator *op, const 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); } } @@ -550,7 +562,7 @@ static int console_delete_exec(bContext *C, wmOperator *op) pos = ci->cursor; BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_NEXT, - (type == DEL_NEXT_CHAR) ? STRCUR_JUMP_NONE : STRCUR_JUMP_DELIM); + (type == DEL_NEXT_CHAR) ? STRCUR_JUMP_NONE : STRCUR_JUMP_DELIM, true); stride = pos - ci->cursor; if (stride) { memmove(ci->line + ci->cursor, ci->line + ci->cursor + stride, (ci->len - ci->cursor) + 1); @@ -566,7 +578,7 @@ static int console_delete_exec(bContext *C, wmOperator *op) pos = ci->cursor; BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_PREV, - (type == DEL_PREV_CHAR) ? STRCUR_JUMP_NONE : STRCUR_JUMP_DELIM); + (type == DEL_PREV_CHAR) ? STRCUR_JUMP_NONE : STRCUR_JUMP_DELIM, true); stride = ci->cursor - pos; if (stride) { ci->cursor -= stride; /* same as above */ @@ -1030,7 +1042,7 @@ static void console_cursor_set_to_pos(SpaceConsole *sc, ARegion *ar, SetConsoleC } } -static void console_modal_select_apply(bContext *C, wmOperator *op, wmEvent *event) +static void console_modal_select_apply(bContext *C, wmOperator *op, const wmEvent *event) { SpaceConsole *sc = CTX_wm_space_console(C); ARegion *ar = CTX_wm_region(C); @@ -1068,7 +1080,7 @@ static void console_cursor_set_exit(bContext *UNUSED(C), wmOperator *op) MEM_freeN(scu); } -static int console_modal_select_invoke(bContext *C, wmOperator *op, wmEvent *event) +static int console_modal_select_invoke(bContext *C, wmOperator *op, const wmEvent *event) { SpaceConsole *sc = CTX_wm_space_console(C); // ARegion *ar = CTX_wm_region(C); @@ -1089,7 +1101,7 @@ static int console_modal_select_invoke(bContext *C, wmOperator *op, wmEvent *eve return OPERATOR_RUNNING_MODAL; } -static int console_modal_select(bContext *C, wmOperator *op, wmEvent *event) +static int console_modal_select(bContext *C, wmOperator *op, const wmEvent *event) { switch (event->type) { case LEFTMOUSE: |