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.
This commit is contained in:
parent
e93aa9c0fc
commit
e98d27fd8d
Notes:
blender-bot
2023-02-14 10:21:10 +01:00
Referenced by issue #72049, 2.8.2 Console Ctrl + Space shortcut for autocomplete missing.
|
@ -2225,7 +2225,7 @@ def km_text(params):
|
|||
{"properties": [("direction", 'UP')]}),
|
||||
("text.move_lines", {"type": 'DOWN_ARROW', "value": 'PRESS', "shift": True, "ctrl": True},
|
||||
{"properties": [("direction", 'DOWN')]}),
|
||||
("text.indent", {"type": 'TAB', "value": 'PRESS'}, None),
|
||||
("text.indent_or_autocomplete", {"type": 'TAB', "value": 'PRESS'}, None),
|
||||
("text.unindent", {"type": 'TAB', "value": 'PRESS', "shift": True}, None),
|
||||
("text.comment_toggle", {"type": 'SLASH', "value": 'PRESS', "ctrl": True}, None),
|
||||
("text.move", {"type": 'HOME', "value": 'PRESS'},
|
||||
|
@ -2305,7 +2305,6 @@ def km_text(params):
|
|||
{"properties": [("lines", 1)]}),
|
||||
("text.line_break", {"type": 'RET', "value": 'PRESS'}, None),
|
||||
("text.line_break", {"type": 'NUMPAD_ENTER', "value": 'PRESS'}, None),
|
||||
("text.autocomplete", {"type": 'SPACE', "value": 'PRESS', "ctrl": True}, None),
|
||||
("text.line_number", {"type": 'TEXTINPUT', "value": 'ANY', "any": True}, None),
|
||||
op_menu("TEXT_MT_context_menu", {"type": 'RIGHTMOUSE', "value": 'PRESS'}),
|
||||
("text.insert", {"type": 'TEXTINPUT', "value": 'ANY', "any": True}, None),
|
||||
|
@ -2535,7 +2534,6 @@ def km_console(params):
|
|||
{"properties": [("interactive", True)]}),
|
||||
("console.execute", {"type": 'NUMPAD_ENTER', "value": 'PRESS'},
|
||||
{"properties": [("interactive", True)]}),
|
||||
("console.autocomplete", {"type": 'SPACE', "value": 'PRESS', "ctrl": True}, None),
|
||||
("console.copy_as_script", {"type": 'C', "value": 'PRESS', "shift": True, "ctrl": True}, None),
|
||||
("console.copy", {"type": 'C', "value": 'PRESS', "ctrl": True}, None),
|
||||
("console.paste", {"type": 'V', "value": 'PRESS', "ctrl": True}, None),
|
||||
|
@ -2543,7 +2541,7 @@ def km_console(params):
|
|||
("console.select_word", {"type": 'LEFTMOUSE', "value": 'DOUBLE_CLICK'}, None),
|
||||
("console.insert", {"type": 'TAB', "value": 'PRESS', "ctrl": True},
|
||||
{"properties": [("text", '\t')]}),
|
||||
("console.indent", {"type": 'TAB', "value": 'PRESS'}, None),
|
||||
("console.indent_or_autocomplete", {"type": 'TAB', "value": 'PRESS'}, None),
|
||||
("console.unindent", {"type": 'TAB', "value": 'PRESS', "shift": True}, None),
|
||||
op_menu("CONSOLE_MT_context_menu", {"type": 'RIGHTMOUSE', "value": 'PRESS'}),
|
||||
("console.insert", {"type": 'TEXTINPUT', "value": 'ANY', "any": True}, None),
|
||||
|
|
|
@ -1587,7 +1587,7 @@ def km_text(params):
|
|||
{"properties": [("direction", 'UP')]}),
|
||||
("text.move_lines", {"type": 'DOWN_ARROW', "value": 'PRESS', "shift": True, "ctrl": True},
|
||||
{"properties": [("direction", 'DOWN')]}),
|
||||
("text.indent", {"type": 'TAB', "value": 'PRESS'}, None),
|
||||
("text.indent_or_autocomplete", {"type": 'TAB', "value": 'PRESS'}, None),
|
||||
("text.unindent", {"type": 'TAB', "value": 'PRESS', "shift": True}, None),
|
||||
("text.uncomment", {"type": 'D', "value": 'PRESS', "shift": True, "ctrl": True}, None),
|
||||
("text.move", {"type": 'HOME', "value": 'PRESS'},
|
||||
|
@ -1668,7 +1668,6 @@ def km_text(params):
|
|||
("text.line_break", {"type": 'RET', "value": 'PRESS'}, None),
|
||||
("text.line_break", {"type": 'NUMPAD_ENTER', "value": 'PRESS'}, None),
|
||||
op_menu("TEXT_MT_context_menu", {"type": 'RIGHTMOUSE', "value": 'PRESS', "any": True}),
|
||||
("text.autocomplete", {"type": 'SPACE', "value": 'PRESS', "ctrl": True}, None),
|
||||
("text.line_number", {"type": 'TEXTINPUT', "value": 'ANY', "any": True}, None),
|
||||
("text.insert", {"type": 'TEXTINPUT', "value": 'ANY', "any": True}, None),
|
||||
])
|
||||
|
@ -1878,7 +1877,6 @@ def km_console(params):
|
|||
{"properties": [("interactive", True)]}),
|
||||
("console.execute", {"type": 'NUMPAD_ENTER', "value": 'PRESS'},
|
||||
{"properties": [("interactive", True)]}),
|
||||
("console.autocomplete", {"type": 'SPACE', "value": 'PRESS', "ctrl": True}, None),
|
||||
("console.copy_as_script", {"type": 'C', "value": 'PRESS', "shift": True, "ctrl": True}, None),
|
||||
("console.copy", {"type": 'C', "value": 'PRESS', "ctrl": True}, None),
|
||||
("console.paste", {"type": 'V', "value": 'PRESS', "ctrl": True}, None),
|
||||
|
@ -1886,10 +1884,10 @@ def km_console(params):
|
|||
("console.select_word", {"type": 'LEFTMOUSE', "value": 'DOUBLE_CLICK'}, None),
|
||||
("console.insert", {"type": 'TAB', "value": 'PRESS', "ctrl": True},
|
||||
{"properties": [("text", '\t')]}),
|
||||
("console.indent", {"type": 'TAB', "value": 'PRESS'}, None),
|
||||
("console.indent_or_autocomplete", {"type": 'TAB', "value": 'PRESS'}, None),
|
||||
("console.unindent", {"type": 'TAB', "value": 'PRESS', "shift": True}, None),
|
||||
("console.insert", {"type": 'TEXTINPUT', "value": 'ANY', "any": True}, None),
|
||||
op_menu("CONSOLE_MT_context_menu", {"type": 'RIGHTMOUSE', "value": 'PRESS'}),
|
||||
("console.insert", {"type": 'TEXTINPUT', "value": 'ANY', "any": True}, None),
|
||||
])
|
||||
|
||||
return keymap
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
* \{ */
|
||||
|
|
Loading…
Reference in New Issue