Community
Participate
Working Groups
Build Identifier: 20100917-0705 The getSelectionText method of the Text widget mistakenly returns the selected text shifted 2 chars to the right. In Mozilla Forefox the getSelectionText method returns the correct text. The problem exists only in IE. Reproducible: Always Steps to Reproduce: 1.Create a view with a single Text widget 2.Write using the append() method a string to the text widget with "\r\n" at the end. 3.Implement right click menu on the text widget with a single action that prints the selected text to the console using text.getSelectionText() *** Or use the attached files, run the application, select the "test" word in the view, right click, select the Copy action. The output is "st li" instead of "test".
Created attachment 183607 [details] SampleView.java
Created attachment 183608 [details] ActionCopy.java
This is reproducible with Controls Demo too. Tested with IE9.
After some investigation I found that the problem is in TextField.js#getSelectionStart(). In case of IE and string ends with "\r\n" the vRange.text.length is two chars shorter. This leads to additional two chars offset in final result: len - vRange.text.length.
After searching the web, it seems that this is a known problem in IE (for some reason IE doesn’t always count the \n and \r in the length). Changed TextField.js#getSelectionStart() IE part to proper return the selection start. JS test added. Tested in IE9, IE8 and IE6.