Skip to content

Commit 66d23d7

Browse files
committed
fix:
1 parent 3e92c4a commit 66d23d7

2 files changed

Lines changed: 81 additions & 32 deletions

File tree

indra/llwindow/llopenglview-objc.mm

Lines changed: 59 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#import "llopenglview-objc.h"
2828
#import "llwindowmacosx-objc.h"
2929
#import "llappdelegate-objc.h"
30+
#import <Carbon/Carbon.h>
3031

3132
extern BOOL gHiDPISupport;
3233

@@ -519,11 +520,28 @@ - (void) keyDown:(NSEvent *)theEvent
519520
}
520521

521522
// 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+
}
527545

528546
bool acceptsText = mHasMarkedText ? false : callKeyDown(&eventData, keycode, mModifiers, ch);
529547

@@ -638,12 +656,8 @@ - (BOOL) performDragOperation:(id<NSDraggingInfo>)sender
638656

639657
- (BOOL)hasMarkedText
640658
{
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
647661
return mHasMarkedText;
648662
}
649663

@@ -744,11 +758,24 @@ - (void)setMarkedText:(id)aString selectedRange:(NSRange)selectedRange replaceme
744758

745759
// Notify the composition text update
746760
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+
749772
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;
752779
}
753780
else
754781
{
@@ -940,11 +967,23 @@ - (void) allowMarkedTextInput:(bool)allowed
940967
// Korean input fix: New utility methods
941968
- (BOOL)isKoreanInputActive
942969
{
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;
948987
}
949988

950989
- (void)resetIMEState

indra/llwindow/llwindowmacosx-objc.mm

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include <AppKit/AppKit.h>
2929
#include <Cocoa/Cocoa.h>
30+
#include <Carbon/Carbon.h>
3031
#include <errno.h>
3132
#include "llopenglview-objc.h"
3233
#include "llwindowmacosx-objc.h"
@@ -487,11 +488,23 @@ void setTitleCocoa(NSWindowRef window, const std::string &title)
487488
bool isKoreanInputActive()
488489
{
489490
@autoreleasepool {
490-
NSString *inputSource = [[NSTextInputContext currentInputContext] selectedKeyboardInputSource];
491-
return [inputSource containsString:@"Korean"] ||
492-
[inputSource containsString:@"Hangul"] ||
493-
[inputSource containsString:@"2-Set Korean"] ||
494-
[inputSource containsString:@"390 Hangul"];
491+
BOOL isKorean = NO;
492+
@try {
493+
TISInputSourceRef currentSource = TISCopyCurrentKeyboardInputSource();
494+
if (currentSource) {
495+
NSString *sourceID = (__bridge NSString *)(TISGetInputSourceProperty(currentSource, kTISPropertyInputSourceID));
496+
if (sourceID) {
497+
isKorean = [sourceID containsString:@"Korean"] ||
498+
[sourceID containsString:@"Hangul"] ||
499+
[sourceID containsString:@"2-Set"];
500+
}
501+
CFRelease(currentSource);
502+
}
503+
}
504+
@catch (NSException *e) {
505+
isKorean = NO;
506+
}
507+
return isKorean;
495508
}
496509
}
497510

@@ -531,11 +544,8 @@ void resetIMEState()
531544

532545
bool isIMEComposing()
533546
{
534-
@autoreleasepool {
535-
NSTextInputContext *context = [NSTextInputContext currentInputContext];
536-
if (context && [context respondsToSelector:@selector(hasMarkedText)]) {
537-
return [context hasMarkedText];
538-
}
539-
return false;
540-
}
547+
// Korean input fix: Check if IME is currently composing
548+
// NSTextInputContext doesn't have hasMarkedText method
549+
// We'll rely on our internal state tracking
550+
return hasCompositionText();
541551
}

0 commit comments

Comments
 (0)