Fix T95932: Auto-close text breaks outliner drag-n-drop

Text inserted via TEXT_OT_insert would always have auto-close
logic applies which interfered any insertion of literal strings
containing brackets.

Now auto-closing brackets is restricted to characters read from
events from the operators invoke functions.
This commit is contained in:
Campbell Barton 2022-04-21 17:50:01 +10:00
parent 4d9ddb4a77
commit c342b3cede
Notes: blender-bot 2023-02-14 06:49:57 +01:00
Referenced by issue #95932, Drag n drop of object from Outliner into Text Editor is broken (when using Auto Close Text Editor Preference)
1 changed files with 14 additions and 6 deletions

View File

@ -3459,12 +3459,6 @@ static int text_insert_exec(bContext *C, wmOperator *op)
while (str[i]) {
code = BLI_str_utf8_as_unicode_step(str, str_len, &i);
done |= txt_add_char(text, code);
if (U.text_flag & USER_TEXT_EDIT_AUTO_CLOSE) {
if (text_closing_character_pair_get(code)) {
done |= txt_add_char(text, text_closing_character_pair_get(code));
txt_move_left(text, false);
}
}
}
}
@ -3484,6 +3478,7 @@ static int text_insert_exec(bContext *C, wmOperator *op)
static int text_insert_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
uint auto_close_char = 0;
int ret;
/* NOTE: the "text" property is always set from key-map,
@ -3510,10 +3505,23 @@ static int text_insert_invoke(bContext *C, wmOperator *op, const wmEvent *event)
}
str[len] = '\0';
RNA_string_set(op->ptr, "text", str);
if (U.text_flag & USER_TEXT_EDIT_AUTO_CLOSE) {
auto_close_char = BLI_str_utf8_as_unicode(str);
}
}
ret = text_insert_exec(C, op);
if ((ret == OPERATOR_FINISHED) && (auto_close_char != 0)) {
const uint auto_close_match = text_closing_character_pair_get(auto_close_char);
if (auto_close_match != 0) {
Text *text = CTX_data_edit_text(C);
txt_add_char(text, auto_close_match);
txt_move_left(text, false);
}
}
/* run the script while editing, evil but useful */
if (ret == OPERATOR_FINISHED && CTX_wm_space_text(C)->live_edit) {
text_run_script(C, NULL);