Enable ApplePressAndHoldEnabled

Fixes https://github.com/libsdl-org/SDL/issues/3622
This commit is contained in:
Sam Lantinga 2024-12-06 17:33:10 -08:00
parent 900627f7fc
commit caf0348b26
2 changed files with 14 additions and 8 deletions

View file

@ -110,7 +110,7 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
NSDictionary *appDefaults = [[NSDictionary alloc] initWithObjectsAndKeys: NSDictionary *appDefaults = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithBool:momentumScrollSupported], @"AppleMomentumScrollSupported", [NSNumber numberWithBool:momentumScrollSupported], @"AppleMomentumScrollSupported",
[NSNumber numberWithBool:NO], @"ApplePressAndHoldEnabled", [NSNumber numberWithBool:YES], @"ApplePressAndHoldEnabled",
[NSNumber numberWithBool:YES], @"ApplePersistenceIgnoreState", [NSNumber numberWithBool:YES], @"ApplePersistenceIgnoreState",
nil]; nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults]; [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];

View file

@ -59,11 +59,10 @@
- (void)insertText:(id)aString replacementRange:(NSRange)replacementRange - (void)insertText:(id)aString replacementRange:(NSRange)replacementRange
{ {
// TODO: Make use of replacementRange?
const char *str; const char *str;
DEBUG_IME(@"insertText: %@", aString); DEBUG_IME(@"insertText: %@ replacementRange: (%d, %d)", aString,
(int)replacementRange.location, (int)replacementRange.length);
/* Could be NSString or NSAttributedString, so we have /* Could be NSString or NSAttributedString, so we have
* to test and convert it before return as SDL event */ * to test and convert it before return as SDL event */
@ -81,6 +80,12 @@
// Deliver the raw key event that generated this text // Deliver the raw key event that generated this text
[self sendPendingKey]; [self sendPendingKey];
if ((int)replacementRange.location != -1) {
// We're replacing the last character
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, 0, SDL_SCANCODE_BACKSPACE, true);
SDL_SendKeyboardKey(0, SDL_GLOBAL_KEYBOARD_ID, 0, SDL_SCANCODE_BACKSPACE, false);
}
SDL_SendKeyboardText(str); SDL_SendKeyboardText(str);
} }
@ -131,8 +136,9 @@
SDL_SendEditingText([aString UTF8String], SDL_SendEditingText([aString UTF8String],
(int)selectedRange.location, (int)selectedRange.length); (int)selectedRange.location, (int)selectedRange.length);
DEBUG_IME(@"setMarkedText: %@, (%d, %d)", _markedText, DEBUG_IME(@"setMarkedText: %@, (%d, %d) replacement range (%d, %d)", _markedText,
selectedRange.location, selectedRange.length); (int)selectedRange.location, (int)selectedRange.length,
(int)replacementRange.location, (int)replacementRange.length);
} }
- (void)unmarkText - (void)unmarkText
@ -158,7 +164,7 @@
} }
DEBUG_IME(@"firstRectForCharacterRange: (%d, %d): windowHeight = %g, rect = %@", DEBUG_IME(@"firstRectForCharacterRange: (%d, %d): windowHeight = %g, rect = %@",
aRange.location, aRange.length, windowHeight, (int)aRange.location, (int)aRange.length, windowHeight,
NSStringFromRect(rect)); NSStringFromRect(rect));
rect = [window convertRectToScreen:rect]; rect = [window convertRectToScreen:rect];
@ -168,7 +174,7 @@
- (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange - (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange
{ {
DEBUG_IME(@"attributedSubstringFromRange: (%d, %d)", aRange.location, aRange.length); DEBUG_IME(@"attributedSubstringFromRange: (%d, %d)", (int)aRange.location, (int)aRange.length);
return nil; return nil;
} }