Cleanup calls to unmarkText

This commit is contained in:
Kovid Goyal 2021-11-11 20:39:55 +05:30
parent a1ca607f35
commit e65aee4533
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -1222,7 +1222,7 @@ is_ascii_control_char(char x) {
const int mods = translateFlags(flags);
const uint32_t key = translateKey(keycode, true);
const bool process_text = !window->ns.textInputFilterCallback || window->ns.textInputFilterCallback(key, mods, keycode, flags) != 1;
[self unmarkText];
[[markedText mutableString] setString:@""];
_glfw.ns.text[0] = 0;
GLFWkeyevent glfw_keyevent = {.key = key, .native_key = keycode, .action = GLFW_PRESS, .mods = mods};
if (!_glfw.ns.unicodeData) {
@ -1278,7 +1278,7 @@ is_ascii_control_char(char x) {
}
}
if (is_ascii_control_char(_glfw.ns.text[0])) _glfw.ns.text[0] = 0; // don't send text for ascii control codes
debug_key("text: %s glfw_key: %s marked_text: %s\n",
debug_key("text: %s glfw_key: %s marked_text: (%s)\n",
format_text(_glfw.ns.text), _glfwGetKeyName(key), [[markedText string] UTF8String]);
if (!window->ns.deadKeyState) {
if ([self hasMarkedText]) {
@ -1442,10 +1442,14 @@ is_ascii_control_char(char x) {
{
(void)selectedRange; (void)replacementRange;
[markedText release];
if ([string isKindOfClass:[NSAttributedString class]])
if (string == nil) { [self unmarkText]; return; }
if ([string isKindOfClass:[NSAttributedString class]]) {
if (((NSMutableAttributedString*)string).length == 0) { [self unmarkText]; return; }
markedText = [[NSMutableAttributedString alloc] initWithAttributedString:string];
else
} else {
if (((NSString*)string).length == 0) { [self unmarkText]; return; }
markedText = [[NSMutableAttributedString alloc] initWithString:string];
}
}
- (void)unmarkText