diff options
author | Yuki Hashimoto <hzuika> | 2021-08-09 07:27:35 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-08-09 07:31:57 +0300 |
commit | 8830cfe5416084caf98fa7c7981a0c337f35548b (patch) | |
tree | 108206076263e06677e51bbca481d69e3371615a /source/blender/editors/curve | |
parent | ff9bc901f43668f27ea36e0d156a916aa08e8877 (diff) |
Fix text object inserting multiple characters with a selection
`bpy.ops.font.text_insert(text="multiple characters")` wasn't working.
When the text is selected does not correctly insert multiple characters.
- When the text was selected from left to right,
the cursor only move one position next to the selected text.
- When the text is selected from right to left,
a part of the selected text remain.
Ref D12161
Diffstat (limited to 'source/blender/editors/curve')
-rw-r--r-- | source/blender/editors/curve/editfont.c | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/source/blender/editors/curve/editfont.c b/source/blender/editors/curve/editfont.c index e43e4194c51..39fb2882e4b 100644 --- a/source/blender/editors/curve/editfont.c +++ b/source/blender/editors/curve/editfont.c @@ -439,37 +439,27 @@ static void text_update_edited(bContext *C, Object *obedit, int mode) WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); } -static int kill_selection(Object *obedit, int ins) /* 1 == new character */ +static int kill_selection(Object *obedit, int ins) /* ins == new character len */ { Curve *cu = obedit->data; EditFont *ef = cu->editfont; int selend, selstart, direction; - int offset = 0; int getfrom; direction = BKE_vfont_select_get(obedit, &selstart, &selend); if (direction) { int size; - if (ins) { - offset = 1; - } if (ef->pos >= selstart) { - ef->pos = selstart + offset; + ef->pos = selstart + ins; } if ((direction == -1) && ins) { - selstart++; - selend++; - } - getfrom = selend + offset; - if (ins == 0) { - getfrom++; - } - size = (ef->len * sizeof(*ef->textbuf)) - (selstart * sizeof(*ef->textbuf)) + - (offset * sizeof(*ef->textbuf)); - memmove(ef->textbuf + selstart, ef->textbuf + getfrom, size); - memmove(ef->textbufinfo + selstart, - ef->textbufinfo + getfrom, - ((ef->len - selstart) + offset) * sizeof(CharInfo)); + selstart += ins; + selend += ins; + } + getfrom = selend + 1; + size = ef->len - selend; /* This is equivalent to: `(ef->len - getfrom) + 1(null)`. */ + memmove(ef->textbuf + selstart, ef->textbuf + getfrom, sizeof(*ef->textbuf) * size); + memmove(ef->textbufinfo + selstart, ef->textbufinfo + getfrom, sizeof(CharInfo) * size); ef->len -= ((selend - selstart) + 1); ef->selstart = ef->selend = 0; } @@ -1650,7 +1640,7 @@ static int insert_text_exec(bContext *C, wmOperator *op) MEM_freeN(inserted_text); MEM_freeN(inserted_utf8); - kill_selection(obedit, 1); + kill_selection(obedit, len); text_update_edited(C, obedit, FO_EDIT); return OPERATOR_FINISHED; |