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

Bug 87774

Summary: [StyledText] Caret at end of line is clipped
Product: [Eclipse Project] Platform Reporter: Florian Priester <fwp>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: niraj.modi, raji
Version: 3.1Keywords: helpwanted, triaged
Target Milestone: ---   
Hardware: PC   
OS: All   
Whiteboard: stalebug
Attachments:
Description Flags
Screenshot 1a
none
Screenshot 1b
none
Screenshot 2 none

Description Florian Priester CLA 2005-03-11 10:31:14 EST
(Moved from bug 58569)

SWT-win32, v3124

Between 3.0M7 and 3.0M8 in Q1/Q2 2004, major internal changes were made
to the StyledText class and its underlying line-wrapping and text layout
mechanisms. As a result of those changes, the size (and presence) of the
caret no longer seems to be taken into account when handling issues
concerning the preferred size of the StyledText and the layout of its
contents. More specifically, this means that:

1.) If the caret offset is after the last character of a logical line
    and there is enough room for the actual text but not for the caret,
    the caret will be clipped (that is, the caret disappears, the user
    does not see it anymore). See screenshots 1a (for the SWT.WRAP case)
    and 1b (for the SWT.H_SCROLL case).
2.) If the caret offset is at the end of a visual line and is preceded by
    one or more whitespace characters, the caret will be clipped if
    there is enough room for the non-whitespace text but not for the
    whitespace text and the caret. See screenshot 2 (SWT.WRAP only).

The request here is that this bug be fixed in a way that ensures that
the caret will be visible at all times. The old version of the StyledText
widget solved this by wrapping the text as soon as needed (or updating
the scroll bar in the SWT.H_SCROLL case). Note that all of this should
also work for caret widths greater than 1 pixel.

---

import org.eclipse.swt.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class StyledTextCaretTest {
  public static void main(String[] args) {
    Display display = new Display();
    
    Shell shell = new Shell(display);
    
    GridLayout layout = new GridLayout();
    layout.marginWidth  = 10;
    layout.marginHeight = 10;
    shell.setLayout(layout);
    
    Font font = new Font(display, "Tahoma", 14, SWT.NORMAL);
      
    StyledText text = new StyledText(shell, SWT.MULTI | SWT.WRAP);
    text.setFont(font);
    text.setText("The quick brown fox jumps over the lazy dog.");
    text.setLayoutData(new GridData(GridData.FILL_BOTH));
    
    // case #1
    text.setCaretOffset(text.getText().length());
    // case #2
    //text.setCaretOffset(26);
    
    shell.setSize(500, 200);
    shell.open();
    
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    
    font.dispose();
    display.dispose();
  }
}
Comment 1 Florian Priester CLA 2005-03-11 10:32:27 EST
Created attachment 18695 [details]
Screenshot 1a
Comment 2 Florian Priester CLA 2005-03-11 10:33:15 EST
Created attachment 18696 [details]
Screenshot 1b
Comment 3 Florian Priester CLA 2005-03-11 10:34:02 EST
Created attachment 18697 [details]
Screenshot 2
Comment 4 Felipe Heidrich CLA 2007-09-12 18:01:49 EDT
Problems 1a and 1b are fixed (in StyledText)

problem 2 is fixed in TextLayout (in carbon with ATSLineKeepSpacesOutOfMargin).

Still working on problem 2 for windows, so many cases to test (see bug 58569).


Comment 5 Raji Akella CLA 2008-03-05 17:28:23 EST
Has problem 2 been fixed for Windows on 3.4?

Comment 6 Felipe Heidrich CLA 2008-03-06 14:17:06 EST
> Has problem 2 been fixed for Windows on 3.4?
No, it is not.

Comment 7 Felipe Heidrich CLA 2009-08-19 08:42:50 EDT
Your bug has been moved to triage, visit http://www.eclipse.org/swt/triage.php for more info.
Comment 8 Niraj Modi CLA 2017-07-06 08:26:23 EDT
One possible solution to this problem:
Identify the condition when caret is clipped and instead move the caret to the start of next line.

A fix patch is welcome here.
Comment 9 Eclipse Genie CLA 2020-01-27 14:49:09 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.