Bug 401230 - [rulers] OverviewRuler becomes wrong if scrollbar is not show in editor
Summary: [rulers] OverviewRuler becomes wrong if scrollbar is not show in editor
Status: RESOLVED DUPLICATE of bug 490951
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.3   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: bugday, helpwanted
Depends on:
Blocks: 424501
  Show dependency tree
 
Reported: 2013-02-19 14:58 EST by Fabio Zadrozny CLA
Modified: 2016-04-22 07:33 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fabio Zadrozny CLA 2013-02-19 14:58:44 EST
To reproduce, create an editor with a source viewer and mark the vertical ScrollBar of the StyledText of the source viewer invisible.

i.e.: on a class derived from org.eclipse.jface.text.source.projection.ProjectionViewer, override:

protected StyledText createTextWidget(Composite parent, int styles) {
    StyledText t = super.createTextWidget(parent, styles);
    t.getVerticalBar().setVisible(false);
}


then, open some editors, add some error annotations and resize the editor a bit: at some point the overview ruler will become wrong because it'll end up mixing the head/body because the method org.eclipse.jface.text.source.SourceViewer.RulerLayout.getVerticalScrollArrowHeights(StyledText, int) returns absurd values if the vertical bar is invisible.

A possible fix would be changing:

if (verticalBar == null)
    return new int[] { 0, 0 };

to

if (verticalBar == null || !verticalBar.getVisible())
    return new int[] { 0, 0 };

as the first thing in the getVerticalScrollArrowHeights method.
Comment 1 Dani Megert CLA 2013-02-20 02:50:20 EST
(In reply to comment #0)
> To reproduce, create an editor with a source viewer and mark the vertical
> ScrollBar of the StyledText of the source viewer invisible.

Can you attach a test case / example?
Comment 2 Dani Megert CLA 2013-02-27 03:42:23 EST
Please reopen after attaching a sample / test case.
Comment 3 Fabio Zadrozny CLA 2013-03-12 14:46:31 EDT
Not attaching test, but giving detailed instructions on how to reproduce this with a regular text editor (i.e.: editor for .txt files). Should be straightforward if you have the Eclipse sources there.

1. Override org.eclipse.jface.text.TextViewer.createTextWidget(Composite, int) to do styledText.getVerticalBar().setVisible(false):


I.e.:

protected StyledText createTextWidget(Composite parent, int styles) {
	StyledText styledText = new StyledText(parent, styles);
	styledText.getVerticalBar().setVisible(false);
	styledText.setLeftMargin(Math.max(styledText.getLeftMargin(), 2));
	return styledText;
}



2. Print the returned values at:

org.eclipse.jface.text.source.SourceViewer.RulerLayout.getVerticalScrollArrowHeights(StyledText, int)

I.e.: right after:  int[] arrowHeights = computeScrollArrowHeights(textWidget, bottomOffset); add:
System.out.println("Computed: "+arrowHeights[0]+" - "+arrowHeights[1]);


3. Change your annotations so that they appear in the overview ruler.

4. Open a text file (say, 20 lines repeating the string 'aaaa'), do a text search for 'aaaa' (so that annotations appear for each line in the overview ruler) and resize the editor vertically: you'll notice that the values printed are usually 0 and sometimes some absurd number.


Another thing to observe is that the annotations in the overview ruler become totally wrong (although this seems to be a separate issue, as fixing it to return new int[] { 0, 0 } still has a weird behavior, although absurd values are no longer given there, also, it seems that the positions where I hover over the overview ruler no longer match the positions that they should match in the editor -- should I open another issue for that?).
Comment 4 Dani Megert CLA 2013-03-21 10:41:52 EDT
OK, I see it now. The overview ruler was not implemented to work along with the scroll bar. Fixing the arrow height is one thing, but as you noted, the annotations will still be placed at wrong locations.
Comment 5 Fabio Zadrozny CLA 2013-03-21 10:45:56 EDT
I'll try to come up with a patch to solve those issues (I actually have it working with the old OverviewRuler code, but it changed a lot from 3.x to 4.x, so, it's non-trivial porting that code, so, it may take a while).

What would be the limit to have this incorporated into the final Eclipse 4.3?
Comment 6 Dani Megert CLA 2013-03-21 10:51:39 EDT
(In reply to comment #5)
> (I actually have it
> working with the old OverviewRuler code, but it changed a lot from 3.x to
> 4.x
This statement is invalid. The JFace Text code is 100% identical for 3.x and 4.x.

> What would be the limit to have this incorporated into the final Eclipse 4.3?
I'd need it by April 15.
Comment 7 Fabio Zadrozny CLA 2013-03-21 11:49:20 EDT
(In reply to comment #6)
> (In reply to comment #5)
> > (I actually have it
> > working with the old OverviewRuler code, but it changed a lot from 3.x to
> > 4.x
> This statement is invalid. The JFace Text code is 100% identical for 3.x and
> 4.x.

You're right. I have a fix from an older version of the OverviewRuler (I had a fork of it to do some experiments on PyDev with a minimap).
Comment 8 Fabio Zadrozny CLA 2013-03-21 16:38:43 EDT
Can you just change

if (verticalBar == null)
    return new int[] { 0, 0 };

to

if (verticalBar == null || !verticalBar.getVisible())
    return new int[] { 0, 0 };

as the first thing in the org.eclipse.jface.text.source.SourceViewer.RulerLayout.getVerticalScrollArrowHeights method? (at least it'd allow me to fix things in a subclass later on if I miss the date and can only provide an actual fix for 4.4).

If you need I can add a patch for that...
Comment 9 Dani Megert CLA 2013-03-22 04:38:56 EDT
(In reply to comment #8)
> Can you just change
> 
> if (verticalBar == null)
>     return new int[] { 0, 0 };
> 
> to
> 
> if (verticalBar == null || !verticalBar.getVisible())
>     return new int[] { 0, 0 };
> 
> as the first thing in the
> org.eclipse.jface.text.source.SourceViewer.RulerLayout.
> getVerticalScrollArrowHeights method? (at least it'd allow me to fix things
> in a subclass later on if I miss the date and can only provide an actual fix
> for 4.4).
> 
> If you need I can add a patch for that...

Fixed with http://git.eclipse.org/c/platform/eclipse.platform.text.git/commit/?id=67e1ed78a51efe5d1182de6bb9f98631a3e9841c
Comment 10 Lars Vogel CLA 2014-01-03 15:14:55 EST
(In reply to Dani Megert from comment #9)
> Fixed with
> http://git.eclipse.org/c/platform/eclipse.platform.text.git/commit/
> ?id=67e1ed78a51efe5d1182de6bb9f98631a3e9841c

Should the bug marked as fixed?
Comment 11 Fabio Zadrozny CLA 2014-01-04 04:24:23 EST
No, the original request is not totally fulfilled (that's just the first building block for it). I still haven't been able to properly investigate the code to see why it's not working properly to produce a proper patch (what I know is that it did work properly some point in the past and stopped working with some of the latest changes in the overview ruler)...
Comment 12 Fabio Zadrozny CLA 2016-04-22 07:31:44 EDT

*** This bug has been marked as a duplicate of bug 490951 ***
Comment 13 Fabio Zadrozny CLA 2016-04-22 07:33:40 EDT
As a note, this issue is fixed in the gerrit review submitted for #490951 (so, marking this one as a duplicate).