diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-05-20 16:51:57 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-05-20 16:51:57 (GMT) |
commit | 38d1c0b4e30e546ebe17c179e46e99884dcab433 (patch) | |
tree | 626a91a7efdd0b61978a1ff2c0ccf262ada91491 /generic/ttk | |
parent | 51d384bfda7a3eb5a915b19d343c8bb657268d75 (diff) | |
parent | 75d83ece93c7c0f3a2a3c8e3a925b35353ccddeb (diff) | |
download | tk-38d1c0b4e30e546ebe17c179e46e99884dcab433.zip tk-38d1c0b4e30e546ebe17c179e46e99884dcab433.tar.gz tk-38d1c0b4e30e546ebe17c179e46e99884dcab433.tar.bz2 |
Add (and use) new internal function TkUtfAtIndex(), which does the same as Tcl_UtfAtIndex() only it protects against ending in the middle of a 4-byte UTF-8 sequence. This should fix another part of [a179564826] when handling copy-pasted Emoji in Text/Entry (and other) widgets.
Diffstat (limited to 'generic/ttk')
-rw-r--r-- | generic/ttk/ttkEntry.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/generic/ttk/ttkEntry.c b/generic/ttk/ttkEntry.c index 96f3cf2..29f69a1 100644 --- a/generic/ttk/ttkEntry.c +++ b/generic/ttk/ttkEntry.c @@ -339,8 +339,8 @@ EntryFetchSelection( } string = entryPtr->entry.displayString; - selStart = Tcl_UtfAtIndex(string, entryPtr->entry.selectFirst); - selEnd = Tcl_UtfAtIndex(selStart, + selStart = TkUtfAtIndex(string, entryPtr->entry.selectFirst); + selEnd = TkUtfAtIndex(selStart, entryPtr->entry.selectLast - entryPtr->entry.selectFirst); byteCount = selEnd - selStart - offset; if (byteCount > maxBytes) { @@ -458,11 +458,11 @@ ExpandPercents( break; case 'S': /* string to be inserted/deleted, if any */ if (reason == VALIDATE_INSERT) { - string = Tcl_UtfAtIndex(new, index); - stringLength = Tcl_UtfAtIndex(string, count) - string; + string = TkUtfAtIndex(new, index); + stringLength = TkUtfAtIndex(string, count) - string; } else if (reason == VALIDATE_DELETE) { - string = Tcl_UtfAtIndex(entryPtr->entry.string, index); - stringLength = Tcl_UtfAtIndex(string, count) - string; + string = TkUtfAtIndex(entryPtr->entry.string, index); + stringLength = TkUtfAtIndex(string, count) - string; } else { string = ""; stringLength = 0; @@ -812,7 +812,7 @@ InsertChars( const char *value) /* New characters to add */ { char *string = entryPtr->entry.string; - size_t byteIndex = Tcl_UtfAtIndex(string, index) - string; + size_t byteIndex = TkUtfAtIndex(string, index) - string; size_t byteCount = strlen(value); int charsAdded = Tcl_NumUtfChars(value, byteCount); size_t newByteCount = entryPtr->entry.numBytes + byteCount + 1; @@ -866,8 +866,8 @@ DeleteChars( return TCL_OK; } - byteIndex = Tcl_UtfAtIndex(string, index) - string; - byteCount = Tcl_UtfAtIndex(string+byteIndex, count) - (string+byteIndex); + byteIndex = TkUtfAtIndex(string, index) - string; + byteCount = TkUtfAtIndex(string+byteIndex, count) - (string+byteIndex); newByteCount = entryPtr->entry.numBytes + 1 - byteCount; new = ckalloc(newByteCount); |