SDL: Fix iOS text input not working with password integration 2

From 7af479bc5351da9ee0659eb62f0638a4874ff405 Mon Sep 17 00:00:00 2001
From: Salman Alshamrani <[EMAIL REDACTED]>
Date: Sun, 30 Nov 2025 11:13:55 -0500
Subject: [PATCH] Fix iOS text input not working with password integration 2

---
 src/video/uikit/SDL_uikitviewcontroller.m | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/video/uikit/SDL_uikitviewcontroller.m b/src/video/uikit/SDL_uikitviewcontroller.m
index 845c0d3686b19..e6443955b57f5 100644
--- a/src/video/uikit/SDL_uikitviewcontroller.m
+++ b/src/video/uikit/SDL_uikitviewcontroller.m
@@ -578,6 +578,14 @@ - (void)keyboardDidHide:(NSNotification *)notification
 
 - (void)textFieldTextDidChange:(NSNotification *)notification
 {
+    // When opening a password manager overlay to select a password and have it auto-filled,
+    // text input becomes stopped as a result of the keyboard being hidden or the text field losing focus.
+    // As a workaround, ensure text input is activated on any changes to the text field.
+    bool startTextInputMomentarily = !SDL_TextInputActive(window);
+
+    if (startTextInputMomentarily)
+        SDL_StartTextInput(window);
+
     if (textField.markedTextRange == nil) {
         if (isOTPMode && labs((NSInteger)textField.text.length - (NSInteger)committedText.length) != 1) {
             return;
@@ -616,6 +624,9 @@ - (void)textFieldTextDidChange:(NSNotification *)notification
         }
         committedText = textField.text;
     }
+
+    if (startTextInputMomentarily)
+        SDL_StopTextInput(window);
 }
 
 - (void)updateKeyboard
@@ -661,7 +672,7 @@ - (void)setKeyboardHeight:(int)height
 - (BOOL)textField:(UITextField *)_textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
 {
     if (!isOTPMode) {
-        if (textField.markedTextRange == nil && textField.text.length < 16) {
+        if (textField.markedTextRange == nil && [string length] == 0 && textField.text.length < 16) {
             [self resetTextState];
         }
     }