|
27 | 27 | #import "llopenglview-objc.h" |
28 | 28 | #import "llwindowmacosx-objc.h" |
29 | 29 | #import "llappdelegate-objc.h" |
| 30 | +#import <Carbon/Carbon.h> |
30 | 31 |
|
31 | 32 | extern BOOL gHiDPISupport; |
32 | 33 |
|
@@ -519,11 +520,28 @@ - (void) keyDown:(NSEvent *)theEvent |
519 | 520 | } |
520 | 521 |
|
521 | 522 | // Korean input fix: Improved input source detection |
522 | | - NSString *inputSource = [[NSTextInputContext currentInputContext] selectedKeyboardInputSource]; |
523 | | - BOOL isKoreanInput = [inputSource containsString:@"Korean"] || |
524 | | - [inputSource containsString:@"Hangul"] || |
525 | | - [inputSource containsString:@"2-Set Korean"] || |
526 | | - [inputSource containsString:@"390 Hangul"]; |
| 523 | + // Use a more reliable method to detect Korean input |
| 524 | + BOOL isKoreanInput = NO; |
| 525 | + @try { |
| 526 | + NSTextInputContext *inputContext = [NSTextInputContext currentInputContext]; |
| 527 | + if (inputContext) { |
| 528 | + // Try to get the current input source |
| 529 | + TISInputSourceRef currentSource = TISCopyCurrentKeyboardInputSource(); |
| 530 | + if (currentSource) { |
| 531 | + NSString *sourceID = (__bridge NSString *)(TISGetInputSourceProperty(currentSource, kTISPropertyInputSourceID)); |
| 532 | + if (sourceID) { |
| 533 | + isKoreanInput = [sourceID containsString:@"Korean"] || |
| 534 | + [sourceID containsString:@"Hangul"] || |
| 535 | + [sourceID containsString:@"2-Set"]; |
| 536 | + } |
| 537 | + CFRelease(currentSource); |
| 538 | + } |
| 539 | + } |
| 540 | + } |
| 541 | + @catch (NSException *e) { |
| 542 | + // Fallback: check if we're not using Roman script |
| 543 | + isKoreanInput = ![(LLAppDelegate*)[NSApp delegate] romanScript]; |
| 544 | + } |
527 | 545 |
|
528 | 546 | bool acceptsText = mHasMarkedText ? false : callKeyDown(&eventData, keycode, mModifiers, ch); |
529 | 547 |
|
@@ -638,12 +656,8 @@ - (BOOL) performDragOperation:(id<NSDraggingInfo>)sender |
638 | 656 |
|
639 | 657 | - (BOOL)hasMarkedText |
640 | 658 | { |
641 | | - // Korean input fix: Also check NSTextInputContext state |
642 | | - NSTextInputContext *context = [self inputContext]; |
643 | | - if (context && [context respondsToSelector:@selector(hasMarkedText)]) |
644 | | - { |
645 | | - return mHasMarkedText || [context hasMarkedText]; |
646 | | - } |
| 659 | + // Korean input fix: Check internal state only |
| 660 | + // NSTextInputContext doesn't have hasMarkedText method |
647 | 661 | return mHasMarkedText; |
648 | 662 | } |
649 | 663 |
|
@@ -744,11 +758,24 @@ - (void)setMarkedText:(id)aString selectedRange:(NSRange)selectedRange replaceme |
744 | 758 |
|
745 | 759 | // Notify the composition text update |
746 | 760 | const wchar_t* wtext = reinterpret_cast<const wchar_t*>(text); |
747 | | - std::vector<int> seg_lengths_vec(segments.seg_lengths.begin(), segments.seg_lengths.end()); |
748 | | - std::vector<bool> standouts_vec(segments.seg_standouts.begin(), segments.seg_standouts.end()); |
| 761 | + // Convert segment info to arrays for C interface |
| 762 | + int* seg_lengths = new int[segments.seg_lengths.size()]; |
| 763 | + bool* standouts = new bool[segments.seg_standouts.size()]; |
| 764 | + |
| 765 | + for (size_t i = 0; i < segments.seg_lengths.size(); i++) { |
| 766 | + seg_lengths[i] = segments.seg_lengths[i]; |
| 767 | + } |
| 768 | + for (size_t i = 0; i < segments.seg_standouts.size(); i++) { |
| 769 | + standouts[i] = segments.seg_standouts[i]; |
| 770 | + } |
| 771 | + |
749 | 772 | callCompositionTextUpdate(wtext, string_length, (int)selectedRange.location, |
750 | | - seg_lengths_vec.data(), (int)seg_lengths_vec.size(), |
751 | | - standouts_vec.data()); |
| 773 | + seg_lengths, (int)segments.seg_lengths.size(), |
| 774 | + standouts); |
| 775 | + |
| 776 | + // Clean up temporary arrays |
| 777 | + delete[] seg_lengths; |
| 778 | + delete[] standouts; |
752 | 779 | } |
753 | 780 | else |
754 | 781 | { |
@@ -940,11 +967,23 @@ - (void) allowMarkedTextInput:(bool)allowed |
940 | 967 | // Korean input fix: New utility methods |
941 | 968 | - (BOOL)isKoreanInputActive |
942 | 969 | { |
943 | | - NSString *inputSource = [[NSTextInputContext currentInputContext] selectedKeyboardInputSource]; |
944 | | - return [inputSource containsString:@"Korean"] || |
945 | | - [inputSource containsString:@"Hangul"] || |
946 | | - [inputSource containsString:@"2-Set Korean"] || |
947 | | - [inputSource containsString:@"390 Hangul"]; |
| 970 | + BOOL isKorean = NO; |
| 971 | + @try { |
| 972 | + TISInputSourceRef currentSource = TISCopyCurrentKeyboardInputSource(); |
| 973 | + if (currentSource) { |
| 974 | + NSString *sourceID = (__bridge NSString *)(TISGetInputSourceProperty(currentSource, kTISPropertyInputSourceID)); |
| 975 | + if (sourceID) { |
| 976 | + isKorean = [sourceID containsString:@"Korean"] || |
| 977 | + [sourceID containsString:@"Hangul"] || |
| 978 | + [sourceID containsString:@"2-Set"]; |
| 979 | + } |
| 980 | + CFRelease(currentSource); |
| 981 | + } |
| 982 | + } |
| 983 | + @catch (NSException *e) { |
| 984 | + isKorean = NO; |
| 985 | + } |
| 986 | + return isKorean; |
948 | 987 | } |
949 | 988 |
|
950 | 989 | - (void)resetIMEState |
|
0 commit comments