From e98d27fd8d432650489f973abcdfad4163e87f42 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 22 Nov 2019 20:50:17 +1100 Subject: Keymap: use tab key for indent or auto-complete Only indent when there aren't characters before the cursor. This resolves the conflict with Ctrl-Space for view maximize. D6239 by @wbrbr for text editor, based console support on this. --- .../blender/editors/space_console/console_intern.h | 1 + source/blender/editors/space_console/console_ops.c | 40 ++++++++++++++++++++++ .../blender/editors/space_console/space_console.c | 1 + source/blender/editors/space_text/space_text.c | 1 + source/blender/editors/space_text/text_intern.h | 1 + source/blender/editors/space_text/text_ops.c | 35 +++++++++++++++++++ 6 files changed, 79 insertions(+) (limited to 'source') diff --git a/source/blender/editors/space_console/console_intern.h b/source/blender/editors/space_console/console_intern.h index 30f7894ea33..2a5675b9c3b 100644 --- a/source/blender/editors/space_console/console_intern.h +++ b/source/blender/editors/space_console/console_intern.h @@ -51,6 +51,7 @@ void CONSOLE_OT_delete(struct wmOperatorType *ot); void CONSOLE_OT_insert(struct wmOperatorType *ot); void CONSOLE_OT_indent(struct wmOperatorType *ot); +void CONSOLE_OT_indent_or_autocomplete(struct wmOperatorType *ot); void CONSOLE_OT_unindent(struct wmOperatorType *ot); void CONSOLE_OT_history_append(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_console/console_ops.c b/source/blender/editors/space_console/console_ops.c index bc18a6cfb56..591c3cc62f2 100644 --- a/source/blender/editors/space_console/console_ops.c +++ b/source/blender/editors/space_console/console_ops.c @@ -473,6 +473,44 @@ void CONSOLE_OT_insert(wmOperatorType *ot) RNA_def_property_flag(prop, PROP_SKIP_SAVE); } +/* -------------------------------------------------------------------- */ +/** \name Indent or Autocomplete Operator + * \{ */ + +static int console_indent_or_autocomplete_exec(bContext *C, wmOperator *UNUSED(op)) +{ + ConsoleLine *ci = console_history_verify(C); + bool text_before_cursor = ci->cursor != 0 && !ELEM(ci->line[ci->cursor - 1], ' ', '\t'); + if (text_before_cursor) { + WM_operator_name_call(C, "CONSOLE_OT_autocomplete", WM_OP_INVOKE_DEFAULT, NULL); + } + else { + WM_operator_name_call(C, "CONSOLE_OT_indent", WM_OP_EXEC_DEFAULT, NULL); + } + return OPERATOR_FINISHED; +} + +void CONSOLE_OT_indent_or_autocomplete(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Indent or Autocomplete"; + ot->idname = "CONSOLE_OT_indent_or_autocomplete"; + ot->description = "Indent selected text or autocomplete"; + + /* api callbacks */ + ot->exec = console_indent_or_autocomplete_exec; + ot->poll = ED_operator_console_active; + + /* flags */ + ot->flag = 0; +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Indent Operator + * \{ */ + static int console_indent_exec(bContext *C, wmOperator *UNUSED(op)) { SpaceConsole *sc = CTX_wm_space_console(C); @@ -518,6 +556,8 @@ void CONSOLE_OT_indent(wmOperatorType *ot) ot->poll = ED_operator_console_active; } +/** \} */ + static int console_unindent_exec(bContext *C, wmOperator *UNUSED(op)) { SpaceConsole *sc = CTX_wm_space_console(C); diff --git a/source/blender/editors/space_console/space_console.c b/source/blender/editors/space_console/space_console.c index 5cc2f00413a..65a23531963 100644 --- a/source/blender/editors/space_console/space_console.c +++ b/source/blender/editors/space_console/space_console.c @@ -245,6 +245,7 @@ static void console_operatortypes(void) WM_operatortype_append(CONSOLE_OT_insert); WM_operatortype_append(CONSOLE_OT_indent); + WM_operatortype_append(CONSOLE_OT_indent_or_autocomplete); WM_operatortype_append(CONSOLE_OT_unindent); /* for use by python only */ diff --git a/source/blender/editors/space_text/space_text.c b/source/blender/editors/space_text/space_text.c index 088f06e9da8..ae7c3b001e7 100644 --- a/source/blender/editors/space_text/space_text.c +++ b/source/blender/editors/space_text/space_text.c @@ -203,6 +203,7 @@ static void text_operatortypes(void) WM_operatortype_append(TEXT_OT_comment_toggle); WM_operatortype_append(TEXT_OT_unindent); WM_operatortype_append(TEXT_OT_indent); + WM_operatortype_append(TEXT_OT_indent_or_autocomplete); WM_operatortype_append(TEXT_OT_select_line); WM_operatortype_append(TEXT_OT_select_all); diff --git a/source/blender/editors/space_text/text_intern.h b/source/blender/editors/space_text/text_intern.h index ca37e9dcd3f..349682bb131 100644 --- a/source/blender/editors/space_text/text_intern.h +++ b/source/blender/editors/space_text/text_intern.h @@ -137,6 +137,7 @@ void TEXT_OT_convert_whitespace(struct wmOperatorType *ot); void TEXT_OT_comment_toggle(struct wmOperatorType *ot); void TEXT_OT_unindent(struct wmOperatorType *ot); void TEXT_OT_indent(struct wmOperatorType *ot); +void TEXT_OT_indent_or_autocomplete(struct wmOperatorType *ot); void TEXT_OT_line_break(struct wmOperatorType *ot); void TEXT_OT_insert(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index a4608123f19..71e24090aa1 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -1068,6 +1068,41 @@ void TEXT_OT_cut(wmOperatorType *ot) /** \} */ +/* -------------------------------------------------------------------- */ +/** \name Indent or Autocomplete Operator + * \{ */ + +static int text_indent_or_autocomplete_exec(bContext *C, wmOperator *UNUSED(op)) +{ + Text *text = CTX_data_edit_text(C); + TextLine *line = text->curl; + bool text_before_cursor = text->curc != 0 && !ELEM(line->line[text->curc - 1], ' ', '\t'); + if (text_before_cursor && (txt_has_sel(text) == false)) { + WM_operator_name_call(C, "TEXT_OT_autocomplete", WM_OP_INVOKE_DEFAULT, NULL); + } + else { + WM_operator_name_call(C, "TEXT_OT_indent", WM_OP_EXEC_DEFAULT, NULL); + } + return OPERATOR_FINISHED; +} + +void TEXT_OT_indent_or_autocomplete(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Indent or Autocomplete"; + ot->idname = "TEXT_OT_indent_or_autocomplete"; + ot->description = "Indent selected text or autocomplete"; + + /* api callbacks */ + ot->exec = text_indent_or_autocomplete_exec; + ot->poll = text_edit_poll; + + /* flags */ + ot->flag = 0; +} + +/** \} */ + /* -------------------------------------------------------------------- */ /** \name Indent Operator * \{ */ -- cgit v1.2.3