Project: SWT
Bug 368417 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.
Reported: 2012-01-12 03:42:46 | Status: resolved fixed

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

Files changed in fix:
bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java