Bug 53569 - UITextField "SelectedTextRange" setter doesn't actually set the selected text range
Summary: UITextField "SelectedTextRange" setter doesn't actually set the selected text...
Status: RESOLVED INVALID
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: XI 10.2 (iOS 10.1)
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-03-20 18:09 UTC by russ
Modified: 2017-04-25 22:29 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Sample app. (10.70 KB, application/zip)
2017-03-23 11:23 UTC, Manuel de la Peña [MSFT]
Details
Sample View Controller (1.57 KB, application/octet-stream)
2017-03-23 21:02 UTC, russ
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description russ 2017-03-20 18:09:26 UTC
Altering the SelectedTextRange on a UITextField appears to have no effect.

Given a UITextField named "foo," I would expect that the following code would highlight everything in my text field:

  UITextRange allRange = foo.GetTextRange(foo.BeginningOfDocument, foo.EndOfDocument);
  foo.SelectedTextRange = allRange;

But nothing happens; foo.SelectedTextRange remains unchanged and no text is highlighted.  I made sure that that the field was already the first responder, in case that had an impact.  I then tried simply moving the cursor by getting a text range with identical start and ending positions, and that also had no effect.

Inspection of "allRange" shows that it's getting correct start and end positions.

Am I missing something?
Comment 1 Manuel de la Peña [MSFT] 2017-03-23 11:22:25 UTC
The SelectedText range does work as expected. I have attached a project that shows it. Nevertheless, can you please le me know in what thread are you doing the selection?
Comment 2 Manuel de la Peña [MSFT] 2017-03-23 11:23:19 UTC
Created attachment 20735 [details]
Sample app.

This project will select the text in the input when the button is clicked.
Comment 3 russ 2017-03-23 21:02:35 UTC
Created attachment 20776 [details]
Sample View Controller
Comment 4 russ 2017-03-23 21:04:03 UTC
Ah ha, turns out my issue is that I'm trying to do the highlighting in EditingDidBegin for the text field.  Attached a sample view controller.

Is this unsupported?

(Also, in answer to your earlier question, I tried forcing it on the main thread even though it should have already been there due to it being fired on a text field event handler, no luck).
Comment 5 russ 2017-03-23 21:13:36 UTC
I should point out that in this sample, you can successfully highlight with the button whenever the text field is the first responder, otherwise you have null beginning/ends of document.  When trying to highlight within the EditingDidBegin handler by simply touching the textfield after you've filled in some text and hit Return, the beginning/end values are valid, but highlighting produces no result.
Comment 6 Alex Soto [MSFT] 2017-04-25 22:29:40 UTC
Hello!

It seems there is no bug in the Xamarin iOS product itself and your question seems more related to API usage.

The broader developer community would be the best and quickest place for additional troubleshooting help on this issue.

Posting a question on Stack Overflow [0] or the Xamarin Forums [1] would be the best next step.

 [0] http://stackoverflow.com/questions/tagged/xamarin
 [1] https://forums.xamarin.com/

 (Investigation by the Xamarin team in the bug tracker for an issue like this would usually require that the reporter includes additional background info to hint that Xamarin is behaving differently compared to Xcode.)

 In case it might also be a helpful reference, you can find some general recommendations on the best places to ask various kinds of questions about Xamarin on:

 https://developer.xamarin.com/guides/cross-platform/troubleshooting/support-options/