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

Bug 362625

Summary: Up and Down arrow keys don't work in RTL text
Product: [Eclipse Project] Platform Reporter: Mohsen Saboorian <mohsens>
Component: SWTAssignee: Felipe Heidrich <eclipse.felipe>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, eclipse.felipe
Version: 3.7.1   
Target Milestone: 3.8 M4   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
A UTF-8 file to reproduce this behavior none

Description Mohsen Saboorian CLA 2011-11-02 00:36:17 EDT
There is an I18N issue regarding RTL text in a text document. Here is how to reproduce it:
1. Open a text editor (for example attached UTF-8 text) and write some LTR and RTL content in it.
2. go to a line, ending with RTL content and press end button. Now press Up/Down button. You can see that up/down arrow keys don't work in some locations, when for example you press Up and the upper line (ending with RTL text) has less characters that current line. Same happens when pressing Down arrow key and the bottom line has less characters.

This happens in Eclipse 3.7.0, 3.7.1, and STS 2.7.x

-- Configuration Details --
Product: Eclipse 1.4.1.20110909-0613 (org.eclipse.epp.package.jee.product)
Installed Features:
 org.eclipse.platform 3.7.1.r37x_v20110729-9gF7UHOxFtniV7mI3T556iZN9AU8bEZ1lHMcVK
Comment 1 Mohsen Saboorian CLA 2011-11-02 00:38:18 EDT
Created attachment 206307 [details]
A UTF-8 file to reproduce this behavior

After opening file in eclipse, press Ctrl+Enter and change file encoding to UTF-8. Then go to a sample line, say 5 and press End. Now go Up, and Down. Down will not work.
Comment 2 Dani Megert CLA 2011-11-02 03:58:15 EDT
The reason is a StringIndexOutOfBoundsException in TextLayout.getOffset(...).

It can also be reproduced via CustomControlExample.

1. launch the CustomControlExample
2. change font to Consolas 10
3. select vertical and horizontal fill
4. paste the text from the attached file
5. on line 7 place the caret after "personal"
6. press Downwards_Arrow

==>

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 14
	at java.lang.String.charAt(String.java:686)
	at org.eclipse.swt.graphics.TextLayout.getOffset(TextLayout.java:2269)
	at org.eclipse.swt.custom.StyledText.getOffsetAtPoint(StyledText.java:4405)
	at org.eclipse.swt.custom.StyledText.doLineDown(StyledText.java:2610)
	at org.eclipse.swt.custom.StyledText.invokeAction(StyledText.java:6871)
	at org.eclipse.swt.custom.StyledText.handleKey(StyledText.java:5926)
	at org.eclipse.swt.custom.StyledText.handleKeyDown(StyledText.java:5952)
	at org.eclipse.swt.custom.StyledText$7.handleEvent(StyledText.java:5646)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1104)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1100)
	at org.eclipse.swt.widgets.Widget.wmKeyDown(Widget.java:1809)
	at org.eclipse.swt.widgets.Control.WM_KEYDOWN(Control.java:4892)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4560)
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:341)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4972)
	at org.eclipse.swt.internal.win32.OS.CallWindowProcW(Native Method)
	at org.eclipse.swt.internal.win32.OS.CallWindowProc(OS.java:2428)
	at org.eclipse.swt.internal.BidiUtil.windowProc(BidiUtil.java:639)
	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2534)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3752)
	at org.eclipse.swt.examples.controlexample.CustomControlExample.main(CustomControlExample.java:54)
Comment 3 Felipe Heidrich CLA 2011-11-14 11:28:54 EST
I broke this when I was working on surrogate support.
Fix http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=3e3d516dc75b4711bc2c5aa804a3940a7d89e620

thank you for the text case.
Comment 4 Dani Megert CLA 2011-11-16 10:51:00 EST
Verified in I20111115-0800.