Fixed uiAttributedString not putting the right position for the last character. Simple case of using the wrong variables.

This commit is contained in:
Pietro Gagliardi 2017-02-10 11:06:37 -05:00
parent 49d36b340c
commit 6fa009a7dd
2 changed files with 2 additions and 5 deletions

View File

@ -207,9 +207,9 @@ void uiAttributedStringInsertAtUnattributed(uiAttributedString *s, const char *s
// and adjust the prior values in the conversion tables
// use <= so the terminating 0 gets updated too
for (i = 0; i <= oldlen - at; i++)
s->u8tou16[at + n8 + i] += n16;
s->u8tou16[at + oldlen + i] += old16len;
for (i = 0; i <= old16len - at16; i++)
s->u16tou8[at16 + n16 + i] += n8;
s->u16tou8[at16 + old16len + i] += oldlen;
// and finally do the attributes
attrlistInsertCharactersUnattributed(s->attrs, at, n8);

View File

@ -424,15 +424,12 @@ double uiDrawTextLayoutByteLocationInLine(uiDrawTextLayout *tl, size_t pos, int
CTLineRef lr;
CFRange range;
printf("= %zd %zd ", pos, tl->nUTF8);
pos = tl->u8tou16[pos];
printf("-> %zd %zd\n", pos, tl->nUTF16);
if (line < 0 || line >= tl->nLines)
return -1;
lr = (CTLineRef) CFArrayGetValueAtIndex(tl->lines, line);
range = CTLineGetStringRange(lr);
// note: >, not >=, because the position at end is valid!
printf("%zd %zd\n", pos, (size_t)(range.location+range.length));
if (pos < range.location || pos > (range.location + range.length))
return -1;
// no point in checking the return; we already validated everything and 0 is a valid return for the first index :/