From 08d3e695570f01f18202e2eb0555afb031aaeaad Mon Sep 17 00:00:00 2001 From: Anastassia Pellja Date: Fri, 12 Jun 2026 16:39:38 +0300 Subject: [PATCH] fix dublicates in MacOS special character inputs --- native/Avalonia.Native/src/OSX/AvnView.mm | 45 ++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/native/Avalonia.Native/src/OSX/AvnView.mm b/native/Avalonia.Native/src/OSX/AvnView.mm index 600dca865f..02abde9aff 100644 --- a/native/Avalonia.Native/src/OSX/AvnView.mm +++ b/native/Avalonia.Native/src/OSX/AvnView.mm @@ -830,7 +830,50 @@ static void ConvertTilt(NSPoint tilt, float* xTilt, float* yTilt) { text = (NSString*) string; } - + + // If replacement range is provided for committed text input, + // select the corresponding surrounding text + // Skip this when marked text is active. + if (replacementRange.location != NSNotFound && + ![self hasMarkedText] && + parent->InputMethod->IsActive()) + { + int start; + int end; + + if (replacementRange.length > 0) + { + if (_selectedRange.length > 0) + { + start = (int)replacementRange.location; + end = (int)(replacementRange.location + replacementRange.length); + } + + // ReplacementRange is reported one position behind, + // so adjust it. + else + { + start = (int)replacementRange.location + 1; + end = (int)(replacementRange.location + replacementRange.length) + 1; + } + } + + // Special case for the first character. ReplacementRange for the first character + // arrives as {0,0} instead of a replacement range, so explicitly + // select it. + else if (replacementRange.location == 0) + { + start = 0; + end = 1; + } + else + { + return; + } + + parent->InputMethod->Client->SelectInSurroundingText(start, end); + } + [self unmarkText]; uint64_t timestamp = static_cast([NSDate timeIntervalSinceReferenceDate] * 1000);