Project: SWT
Bug 137320 [StyledText] caret does not move correctly when inserted text wraps
Reported: 2006-04-18 14:30:36 | Status: resolved fixed

Run the following example and hit the Escape key. Notice that the caret is somewhere past the end of the first line but it should really be between "by" and "abcdefghij" on the second line. The inserted text has caused the line to wrap but the caret has not followed. If you arrow left or arrow right, the caret fixes itself. public static void main (String [] args) { Display display = new Display (); Shell shell = new Shell (display); shell.setLayout(new FillLayout()); final StyledText text = new StyledText(shell, SWT.BORDER | SWT.WRAP); text.setText("A drop target receives data in a Drag and Drop operation. The data received by\n"+ "the drop target may have come from the same widget, from a different widget within \n"+ "the same application, or from a different application altogether. For example, you \n"+ "can drag text from an email application and drop it on your application, or you could \n"+ "drag an item in a tree and drop it below a different node in the same tree."); text.addListener(SWT.KeyDown, new Listener() { public void handleEvent(Event e) { if (e.character == SWT.ESC) { text.setCaretOffset(78); text.insert("abcdefghij"); } } }); Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT); shell.setSize(size.x + 4, size.y + 100); shell.open (); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } display.dispose (); }

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