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
This commit is contained in:
parent
ff9bc901f4
commit
8830cfe541
|
@ -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++;
|
||||
selstart += ins;
|
||||
selend += ins;
|
||||
}
|
||||
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));
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue