Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 323373 - StyledTextRenderer.hasLink() uses invalid indexing if no ranges array is defined
Summary: StyledTextRenderer.hasLink() uses invalid indexing if no ranges array is defined
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.0   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: 3.7 M2   Edit
Assignee: Felipe Heidrich CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-23 06:04 EDT by Pekko Tiitto CLA
Modified: 2010-09-15 17:02 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pekko Tiitto CLA 2010-08-23 06:04:23 EDT
Build Identifier: I20100608-0911

I have implemented a org.eclipse.swt.custom.LineStyleListener to style my text (links, different colors), and for each line there can be 0-N StyleRanges. If I do not specify the LineStyleEvent.ranges array, then changing the mouse cursor when the mouse cursor is over a link doesn't always work correctly.

I think the problem is in the method org.eclipse.swt.custom.StyledTextRenderer.hasLink(int):

    ...
    for (int i = 0; i < styles.length; i++) {
        if (styles[i].start <= offset && offset < styles[i].start + styles[i].length && 
            styles[i >> 1].underline && styles[i >> 1].underlineStyle == SWT.UNDERLINE_LINK) {
            return true;
        }
    }
    ...

And more specifically in the latter two cases where the array 'styles' is indexed ("styles[i >> 1]"). I think those should be replaced with "styles[i]".

If I define the LineStyleEvent.ranges array then mouse cursor is changed correctly.

Reproducible: Always
Comment 1 Felipe Heidrich CLA 2010-08-23 12:13:29 EDT
You are right, thank you for the patch.

Fixed in HEAD