Page MenuHome

Fix: text after the cursor is also displayed before the cursor when inserting IME text on UI button
ClosedPublic

Authored by Yuki Hashimoto (hzuika) on Apr 25 2021, 2:54 PM.

Details

Summary

When inserting text using IME on a button, the character after the cursor is displayed before the cursor.

This bug seems to have occurred during the refactoring of the source code.
https://developer.blender.org/D765?vs=2730&id=2939#toc

In D765 (id 2730)
the original code was

char *str;
size_t len, slen;
len = strlen(but->editstr);
slen = ime->composite_len;
str = MEM_mallocN(sizeof(char) * (slen + len + 1), "drawstr edit buffer");
memcpy(str, but->editstr, sizeof(char) * but->pos);
memcpy(str + but->pos, ime->composite, sizeof(char) * slen);
memcpy(str + but->pos + slen, but->editstr + but->pos, sizeof(char) + (len - but->pos));
str[len + slen] = '\0';
drawstr = drawstr_edit = str;

According to the meaning of original source code, I use the precision specification for BLI_snprintf, and the string will be displayed correctly.

Diff Detail

Repository
rB Blender
Branch
fix_draw_imetext (branched from master)
Build Status
Buildable 14209
Build 14209: arc lint + arc unit

Event Timeline

Yuki Hashimoto (hzuika) requested review of this revision.Apr 25 2021, 2:54 PM
Yuki Hashimoto (hzuika) created this revision.
Yuki Hashimoto (hzuika) edited the summary of this revision. (Show Details)Apr 25 2021, 3:00 PM
Yuki Hashimoto (hzuika) retitled this revision from Fix: text before the cursor is displayed after the cursor when inserting IME text on UI button to Fix: text after the cursor is also displayed before the cursor when inserting IME text on UI button.Apr 25 2021, 3:07 PM
Yuki Hashimoto (hzuika) edited the summary of this revision. (Show Details)
This revision is now accepted and ready to land.Jul 5 2021, 1:28 PM

@Harley Acheson (harley) would you mind committing? :) Thanks!