Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

"OnFocus - Select all" not working for TMP input on Android

Discussion in 'UGUI & TextMesh Pro' started by Fizzer, Jun 26, 2019.

  1. Fizzer

    Fizzer

    Joined:
    Nov 16, 2016
    Posts:
    40
    Hello!

    I'm a long-time Text Mesh Pro user who's upgrading from 2017.4 to 2018.4. I used to use the paid version of TMP (1.2.2), and I'm now upgrading to the built-in version (1.4.1).

    I ran into a functionality regression of the Text Mesh Pro Input Field component when the "OnFocus - Select All" box is checked on Android.

    Repro steps:

    1. Create a Text Mesh Pro input field in a canvas.
    2. Ensure the "OnFocus - Select all" box is checked (as it is by default).
    3. Give the box some text, such as "hello".
    4. Run the app on an Android device.
    5. Tap the text box with your finger
    6. In the software keyboard that pops up, press any key, such as "5"

    Actual results: The "5" is appended to "hello", leaving "hello5" in the box.
    Expected results: The "5" replaces the text, leaving simply "5" in the box.

    My app relies on this behavior since it makes it easy to replace the contents of a box, which is something my users do quite often so adding the extra step of deleting the text is a big problem.

    I believe it to be a bug since the other platforms already selects all and allows for replacing, so Android should behave the same. Also because it works in 1.2.2.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Thanks for reporting the behavior.

    I am currently travelling so I won't be able to look into this until early next week. I'll provide feedback as soon as I have more information.
     
  3. Fizzer

    Fizzer

    Joined:
    Nov 16, 2016
    Posts:
    40
    Hi, any update on this? I filed bug 1168274 back when I made this forum thread nearly three months ago, but I still have not seen any progress.
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I should have an update on this tomorrow.
     
  5. Fizzer

    Fizzer

    Joined:
    Nov 16, 2016
    Posts:
    40
    I hate to be a bother but it's been 3 weeks -- is progress being made?
     
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Thank you for the reminder.

    I did look at the issue a few weeks ago for which I still need to find a good solution. I'll try looking at it again over the new few days and provide feedback shortly thereafter.

    Please feel free to poke me again if I do not provide an update within that time frame.
     
  7. Fizzer

    Fizzer

    Joined:
    Nov 16, 2016
    Posts:
    40
    Hey, checking in :)
     
    micbigtree likes this.
  8. micbigtree

    micbigtree

    Joined:
    Apr 3, 2018
    Posts:
    2
    bump on this, having the same issue with iOS
     
  9. Headless_Chicken

    Headless_Chicken

    Joined:
    Oct 17, 2019
    Posts:
    1
    I found I had the same issue on android however under the "Control Settings" for the Text Mesh Pro Input Field component I selected "Hide Mobile Input". After selecting this the "OnFocus - Select All" feature started working correctly.
     
  10. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I have resolved this issue. The fix will be included in the new package release which will be this week.
     
  11. KonstantinShkulev

    KonstantinShkulev

    Joined:
    Jan 24, 2019
    Posts:
    31
    It looks like "OnFocus - Select All" doesn't work on iOS with 3.0.4 plugin version on Unity 2020.1.7f. At least for me. But it works well on Android devices.
     
  12. Shivachev

    Shivachev

    Joined:
    Mar 2, 2021
    Posts:
    1
    Hi there, I am facing the same problem when I install a build of my project on Android (my device is running Android 10). I am using Unity 2019.2.15f1 with a TMP 2.0.1 version (screenshot attached). Selecting normal or TMP Input fields ( where OnFocus Select All is enabled) does not select the content of the field
     
  13. KonstantinShkulev

    KonstantinShkulev

    Joined:
    Jan 24, 2019
    Posts:
    31
    Hi, @Stephan_B
    Bug still occurs in 3.0.5 version
     
  14. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Is it just "OnFocus - Select All" on iOS that doesn't appear to work for you?

    Can you provide the steps to reproduce (in case they are different then previously posted)?
     
  15. KonstantinShkulev

    KonstantinShkulev

    Joined:
    Jan 24, 2019
    Posts:
    31
    Yes, only "OnFocus - Select All" doesn't work.

    We just select "OnFocus - Select All", "Reset On DeActivation", "Restore on ESC Key", "Rich Text" and "Allow Rich Text Editing". All remaining options are disabled. It works as expected on Android.
     
  16. IslandLabsKReguieg

    IslandLabsKReguieg

    Joined:
    May 18, 2020
    Posts:
    7
    Hi @Stephan_B ,

    Short ping to confirm the bug still persists on iOS with "com.unity.textmeshpro": "3.0.6" on Unity 2020.3 LTS.
    It works in the Editor but not in a build iOS app.

    Greetings. :)
     
  17. IslandLabsKReguieg

    IslandLabsKReguieg

    Joined:
    May 18, 2020
    Posts:
    7
    Hi Community:

    Based on the work of @KonstantinShkulev we were able to identify the error more precisely and created a patch. We verfied the solution on several different iOS versions (14+ and 15.+), iPads and iPhones. An issue tracker id will be published soon and I will post it here as well. Feel free to apply the patch in your local forks of TextMeshPro:

    Issue Tracker ID:

    https://issuetracker.unity3d.com/issues/ios-touchscreenkeyboard-dot-selection-is-ignored


    Code (CSharp):
    1. From 7642ac8a999496dd787aaee049ce7d1098c8c314 Mon Sep 17 00:00:00 2001
    2. Date: Thu, 18 Nov 2021 15:36:45 +0100
    3. Subject: [PATCH 1/2] Fix OnFocusSelectAll not working on iOS, by refreshing
    4. the selection after some time.
    5.  
    6. ---
    7. .../Scripts/Runtime/TMP_InputField.cs         | 34 +++++++++++++++++--
    8. 1 file changed, 32 insertions(+), 2 deletions(-)
    9.  
    10. diff --git a/Packages/com.unity.textmeshpro/Scripts/Runtime/TMP_InputField.cs b/Packages/com.unity.textmeshpro/Scripts/Runtime/TMP_InputField.cs
    11. index 7edfa6e..75ee315 100644
    12. --- a/Packages/com.unity.textmeshpro/Scripts/Runtime/TMP_InputField.cs
    13. +++ b/Packages/com.unity.textmeshpro/Scripts/Runtime/TMP_InputField.cs
    14. @@ -4056,6 +4056,28 @@ namespace TMPro
    15.              m_ShouldActivateNextUpdate = true;
    16.          }
    17. +        private Coroutine selectionRefreshCoroutine = null;
    18. +        /// <summary>
    19. +        /// Part of a workaround for the system keyboard which resets its selection after couple of frames.
    20. +        /// The coroutine waits until the system keyboard resets the selection or the timeout is reached and reapplies the selection.
    21. +        /// </summary>
    22. +        /// <returns></returns>
    23. +        private IEnumerator RefreshSelection()
    24. +        {
    25. +            const float maxWaitTime = 0.5f;
    26. +            float timeoutTime = Time.realtimeSinceStartup + maxWaitTime;
    27. +
    28. +            yield return new WaitUntil(() => (this.m_SoftKeyboard == null) || (Time.realtimeSinceStartup > timeoutTime) || (this.m_SoftKeyboard.selection.length == 0));
    29. +
    30. +            if (this.m_SoftKeyboard != null)
    31. +            {
    32. +                int length = stringPositionInternal < stringSelectPositionInternal ? stringSelectPositionInternal - stringPositionInternal : stringPositionInternal - stringSelectPositionInternal;
    33. +                m_SoftKeyboard.selection = new RangeInt(stringPositionInternal < stringSelectPositionInternal ? stringPositionInternal : stringSelectPositionInternal, length);
    34. +            }
    35. +
    36. +            this.selectionRefreshCoroutine = null;
    37. +        }
    38. +
    39.          private void ActivateInputFieldInternal()
    40.          {
    41.              if (EventSystem.current == null)
    42. @@ -4085,15 +4107,23 @@ namespace TMPro
    43.                      {
    44.                          int length = stringPositionInternal < stringSelectPositionInternal ? stringSelectPositionInternal - stringPositionInternal : stringPositionInternal - stringSelectPositionInternal;
    45.                          m_SoftKeyboard.selection = new RangeInt(stringPositionInternal < stringSelectPositionInternal ? stringPositionInternal : stringSelectPositionInternal, length);
    46. +
    47. +                        #if UNITY_IOS
    48. +                        // 2021-11-18: Using 2020.3.20f1 on iOS the selection gets reset after a couple of frames, therefore we need to refresh the selection after some time.
    49. +                        if (this.selectionRefreshCoroutine != null)
    50. +                            this.StopCoroutine(this.selectionRefreshCoroutine);
    51. +
    52. +                        this.selectionRefreshCoroutine = this.StartCoroutine(this.RefreshSelection());
    53. +                        #endif
    54.                      }
    55.                      //}
    56.                  }
    57.                  // Cache the value of isInPlaceEditingAllowed, because on UWP this involves calling into native code
    58.                  // The value only needs to be updated once when the TouchKeyboard is opened.
    59. -                #if UNITY_2019_1_OR_NEWER
    60. +#if UNITY_2019_1_OR_NEWER
    61.                  m_TouchKeyboardAllowsInPlaceEditing = TouchScreenKeyboard.isInPlaceEditingAllowed;
    62. -                #endif
    63. +#endif
    64.              }
    65.              else
    66.              {
    67. --
    68. 2.33.1.windows.1
    69.  
    70.  
     
    Last edited: Nov 22, 2021
    KonstantinShkulev likes this.