Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 330857

Summary: [Text] Wrong selection start in IE under some constellation
Product: [RT] RAP Reporter: DANIEL <daniel.eclipse>
Component: RWTAssignee: Project Inbox <rap-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: unspecified   
Target Milestone: 1.4 M7   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
SampleView.java
none
ActionCopy.java none

Description DANIEL CLA 2010-11-22 16:16:40 EST
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".
Comment 1 DANIEL CLA 2010-11-22 16:18:48 EST
Created attachment 183607 [details]
SampleView.java
Comment 2 DANIEL CLA 2010-11-22 16:19:45 EST
Created attachment 183608 [details]
ActionCopy.java
Comment 3 Ivan Furnadjiev CLA 2011-04-20 08:18:44 EDT
This is reproducible with Controls Demo too. Tested with IE9.
Comment 4 Ivan Furnadjiev CLA 2011-04-20 08:44:42 EDT
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.
Comment 5 Ivan Furnadjiev CLA 2011-04-21 03:25:10 EDT
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.