Pārlūkot izejas kodu

Merge pull request #11809 from Gillibald/fixes/windowsIME

[Windows] Make sure the InputMethod deletes current selection before preedit is set
Max Katz 2 gadi atpakaļ
vecāks
revīzija
28e9b3a49d
1 mainītis faili ar 18 papildinājumiem un 0 dzēšanām
  1. 18 0
      src/Windows/Avalonia.Win32/Input/Imm32InputMethod.cs

+ 18 - 0
src/Windows/Avalonia.Win32/Input/Imm32InputMethod.cs

@@ -324,6 +324,11 @@ namespace Avalonia.Win32.Input
             if (IsActive)
             {
                 Client.SetPreeditText(null);
+
+                if (Client.SupportsSurroundingText && Client.SurroundingText.AnchorOffset != Client.SurroundingText.CursorOffset)
+                {
+                    KeyPress(Key.Delete);
+                }
             }
 
             IsComposing = true;
@@ -393,6 +398,19 @@ namespace Avalonia.Win32.Input
             return (int)(ptr.ToInt64() & 0xffffffff);
         }
 
+        private void KeyPress(Key key)
+        {
+            if (_parent?.Input != null)
+            {
+                _parent.Input(new RawKeyEventArgs(KeyboardDevice.Instance!, (ulong)DateTime.Now.Ticks, _parent.Owner,
+                RawKeyEventType.KeyDown, key, RawInputModifiers.None));
+
+                _parent.Input(new RawKeyEventArgs(KeyboardDevice.Instance!, (ulong)DateTime.Now.Ticks, _parent.Owner,
+                RawKeyEventType.KeyUp, key, RawInputModifiers.None));
+
+            }
+        }
+
         ~Imm32InputMethod()
         {
             _caretManager.TryDestroy();