| Summary: |
When you try to move cursor up/down with arrow keys in a multiline StyledText with word wrapping and nonzero margins, cursor may "freeze" and pressing up/down keys has no effect. |
| Product: |
[Eclipse Project] Platform
|
Reporter: |
Alexander Zakusylo <zakgof> |
| Component: |
SWT | Assignee: |
Felipe Heidrich <eclipse.felipe> |
| Status: |
RESOLVED
FIXED
|
QA Contact: |
|
| Severity: |
normal
|
|
|
| Priority: |
P3
|
CC: |
alex.evseenko, eclipse.felipe, Silenio_Quarti
|
| Version: |
4.2 | |
|
| Target Milestone: |
3.8 M5 | |
|
| Hardware: |
PC | |
|
| OS: |
Windows 7 | |
|
| Whiteboard: |
|
Build Identifier: Version: Indigo Service Release 1 Build id: 20110916-0149 Looks like the reason of the bug is trivial: the top margin in StyledText#getVisualLineIndex is added twice: int getVisualLineIndex(TextLayout layout, int offsetInLine) { int lineIndex = layout.getLineIndex(offsetInLine); int[] offsets = layout.getLineOffsets(); if (lineIndex != 0 && offsetInLine == offsets[lineIndex]) { int lineY = layout.getLineBounds(lineIndex).y; int caretY = getCaret().getLocation().y - topMargin - getLinePixel(getCaretLine()); if (lineY > caretY) lineIndex--; caretAlignment = OFFSET_LEADING; } return lineIndex; } topMargin is explicitly subtracted, but it is already included in value calculated by getLinePixel. The line should look like: int caretY = getCaret().getLocation().y - getLinePixel(getCaretLine()); Reproducible: Always Steps to Reproduce: 1. Run the following snippet: public class Snippet { static String text = "Line One. Long Long Long Long Long Long Long Long Long Long Long Long Long Long Long Long Long Long\n" + "Line Two.\n" + "Line Three"; public static void main(final String [] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final StyledText styledText = new StyledText(shell, SWT.MULTI | SWT.WRAP | SWT.BORDER); styledText.setMargins(5, 5, 5, 5); styledText.setWordWrap(true); styledText.setText(text); shell.setSize(300, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } } 2. Press ARROW DOWN several times 3. Notice that UP/DOWN keys are no more working