From e52422e60cb9265936b53ae27a0ee159416221db Mon Sep 17 00:00:00 2001 From: culler Date: Wed, 23 Oct 2019 03:43:42 +0000 Subject: Add update idletasks for the text. Replace non-BMP characters by 0xfffd when pasting. --- library/text.tcl | 7 ++++--- macosx/tkMacOSXClipboard.c | 23 ++++++++++++++++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/library/text.tcl b/library/text.tcl index 7525588..c4e3388 100644 --- a/library/text.tcl +++ b/library/text.tcl @@ -403,11 +403,13 @@ bind Text <> { dict set ::tk::Priv(IMETextMark) "%W" [%W index insert] } bind Text <> { - %W tag add IMEmarkedtext [dict get $::tk::Priv(IMETextMark) "%W"] insert + %W tag add IMEmarkedtext [dict get $::tk::Priv(IMETextMark) "%W"] insert %W tag configure IMEmarkedtext -underline on + update idletasks } bind Text <> { - %W delete IMEmarkedtext.first IMEmarkedtext.last + %W delete IMEmarkedtext.first IMEmarkedtext.last + update idletasks } # Macintosh only bindings: @@ -1226,4 +1228,3 @@ proc ::tk::TextScanDrag {w x y} { $w scan dragto $x $y } } - diff --git a/macosx/tkMacOSXClipboard.c b/macosx/tkMacOSXClipboard.c index 6cbcdf6..116525f 100644 --- a/macosx/tkMacOSXClipboard.c +++ b/macosx/tkMacOSXClipboard.c @@ -130,6 +130,7 @@ TkSelGetSelection( && selection == dispPtr->clipboardAtom && (target == XA_STRING || target == dispPtr->utf8Atom)) { NSString *string = nil; + NSString *clean; NSPasteboard *pb = [NSPasteboard generalPasteboard]; NSString *type = [pb availableTypeFromArray:[NSArray arrayWithObject: NSStringPboardType]]; @@ -137,7 +138,27 @@ TkSelGetSelection( if (type) { string = [pb stringForType:type]; } - result = proc(clientData, interp, string ? [string UTF8String] : ""); + if (string) { + /* + * Replace all non-BMP characters by the replacement character 0xfffd. + * This is a workaround until Tcl supports TCL_UTF_MAX > 3. + */ + int i, j, len = [string length]; + CFRange all = CFRangeMake(0, len); + UniChar *buffer = ckalloc(len*sizeof(UniChar)); + CFStringGetCharacters((CFStringRef) string, all, buffer); + for (i = 0, j = 0 ; j < len ; i++, j++) { + if (CFStringIsSurrogateHighCharacter(buffer[j])) { + buffer[i] = 0xfffd; + j++; + } else { + buffer[i] = buffer[j]; + } + } + clean = (NSString *)CFStringCreateWithCharacters(NULL, buffer, i); + ckfree(buffer); + } + result = proc(clientData, interp, [clean UTF8String]); } else { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "%s selection doesn't exist or form \"%s\" not defined", -- cgit v0.12