Skip to content

Commit 90cd465

Browse files
committed
Do note propagate SurroundingTextChanged back to iOS
1 parent 3850b80 commit 90cd465

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/iOS/Avalonia.iOS/TextInputResponder.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public TextInputResponder(AvaloniaView view, TextInputMethodClient client)
9090
private int _inSurroundingTextUpdateEvent;
9191
private readonly UITextPosition _beginningOfDocument = new AvaloniaTextPosition(0);
9292
private readonly UITextInputStringTokenizer _tokenizer;
93+
private bool _isInUpdate;
9394

9495
public TextInputMethodClient? Client => _client;
9596

@@ -142,15 +143,15 @@ public override UITextInputMode TextInputMode
142143
private void SurroundingTextChanged(object? sender, EventArgs e)
143144
{
144145
Logger.TryGet(LogEventLevel.Debug, ImeLog)?.Log(null, "SurroundingTextChanged");
145-
if (WeakInputDelegate == null)
146+
if (WeakInputDelegate == null || _isInUpdate)
146147
return;
147148
_inSurroundingTextUpdateEvent++;
148149
try
149150
{
150151
objc_msgSend(WeakInputDelegate.Handle.Handle, TextWillChange, Handle.Handle);
151152
objc_msgSend(WeakInputDelegate.Handle.Handle, TextDidChange, Handle.Handle);
152-
objc_msgSend(WeakInputDelegate.Handle.Handle, SelectionWillChange, this.Handle.Handle);
153-
objc_msgSend(WeakInputDelegate.Handle.Handle, SelectionDidChange, this.Handle.Handle);
153+
objc_msgSend(WeakInputDelegate.Handle.Handle, SelectionWillChange, Handle.Handle);
154+
objc_msgSend(WeakInputDelegate.Handle.Handle, SelectionDidChange, Handle.Handle);
154155
}
155156
finally
156157
{
@@ -180,6 +181,7 @@ private void TextInput(string text)
180181

181182
void IUIKeyInput.InsertText(string text)
182183
{
184+
_isInUpdate = true;
183185
Logger.TryGet(LogEventLevel.Debug, ImeLog)?.Log(null, "IUIKeyInput.InsertText {text}", text);
184186

185187
if (text == "\n")
@@ -203,9 +205,15 @@ void IUIKeyInput.InsertText(string text)
203205
}
204206

205207
TextInput(text);
208+
_isInUpdate = false;
206209
}
207210

208-
void IUIKeyInput.DeleteBackward() => KeyPress(Key.Back, PhysicalKey.Backspace, "\b");
211+
void IUIKeyInput.DeleteBackward()
212+
{
213+
_isInUpdate = true;
214+
KeyPress(Key.Back, PhysicalKey.Backspace, "\b");
215+
_isInUpdate = false;
216+
}
209217

210218
bool IUIKeyInput.HasText => true;
211219

0 commit comments

Comments
 (0)