diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-11-22 12:50:17 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-11-22 12:53:40 +0300 |
commit | e98d27fd8d432650489f973abcdfad4163e87f42 (patch) | |
tree | 16c4515cc74341d2c409d2c997a58fbba4cf2f9d /source/blender/editors/space_text/text_ops.c | |
parent | e93aa9c0fc669d0b09a1159e8ef1e2b9dfcc7320 (diff) |
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.
Diffstat (limited to 'source/blender/editors/space_text/text_ops.c')
-rw-r--r-- | source/blender/editors/space_text/text_ops.c | 35 |
1 files changed, 35 insertions, 0 deletions
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 @@ -1069,6 +1069,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 * \{ */ |