From 6fa009a7dd31415faeaa7151d72e64d3451e2e9c Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 10 Feb 2017 11:06:37 -0500 Subject: [PATCH] Fixed uiAttributedString not putting the right position for the last character. Simple case of using the wrong variables. --- common/attrstr.c | 4 ++-- darwin/drawtext.m | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/common/attrstr.c b/common/attrstr.c index 03dab8f9..249c086f 100644 --- a/common/attrstr.c +++ b/common/attrstr.c @@ -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); diff --git a/darwin/drawtext.m b/darwin/drawtext.m index 82b99ac3..510164bd 100644 --- a/darwin/drawtext.m +++ b/darwin/drawtext.m @@ -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 :/