Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Loskutov2015-12-01 15:39:20 +0000
committerDani Megert2015-12-08 15:34:44 +0000
commit3ed1845ebd7446875f59a4b229c203bfcf13bff6 (patch)
tree30f13fa39167197899c58d953b96a49ae489db4f
parent9a6ac0d725b0783c337cf80a20d7cbbef60c052b (diff)
downloadeclipse.platform.text-3ed1845ebd7446875f59a4b229c203bfcf13bff6.tar.gz
eclipse.platform.text-3ed1845ebd7446875f59a4b229c203bfcf13bff6.tar.xz
eclipse.platform.text-3ed1845ebd7446875f59a4b229c203bfcf13bff6.zip
Bug 481818 - [rulers] Annotation in vertical ruler not on the wrapped line
Change-Id: I5f21f2a4205ae09ff982233660d39502904437e2 Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/source/DiffPainter.java19
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationRulerColumn.java38
2 files changed, 45 insertions, 12 deletions
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/source/DiffPainter.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/source/DiffPainter.java
index 6f68e1365f4..a615bbaf1cf 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/source/DiffPainter.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/source/DiffPainter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2008 IBM Corporation and others.
+ * Copyright (c) 2006, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -17,6 +17,7 @@ import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
@@ -221,8 +222,20 @@ public final class DiffPainter {
if (info != null) {
int y= fWidget.getLinePixel(widgetLine);
- int lineHeight= fWidget.getLineHeight(fWidget.getOffsetAtLine(widgetLine));
-
+ boolean isWrapActive= fWidget.getWordWrap();
+ int lineHeight;
+ int offset= fWidget.getOffsetAtLine(widgetLine);
+ if (!isWrapActive) {
+ lineHeight= fWidget.getLineHeight(offset);
+ } else {
+ int offsetEnd= offset + fWidget.getLine(widgetLine).length();
+ if (offsetEnd == fWidget.getCharCount()) {
+ lineHeight= fWidget.getLineHeight(offset);
+ } else {
+ Rectangle textBounds= fWidget.getTextBounds(offset, offsetEnd);
+ lineHeight= textBounds.height;
+ }
+ }
// draw background color if special
if (hasSpecialColor(info)) {
gc.setBackground(getColor(info));
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationRulerColumn.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationRulerColumn.java
index 0e3472bedc0..e0676c3c9ad 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationRulerColumn.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationRulerColumn.java
@@ -644,7 +644,7 @@ public class AnnotationRulerColumn implements IVerticalRulerColumn, IVerticalRul
// draw Annotations
Rectangle r= new Rectangle(0, 0, 0, 0);
int maxLayer= 1; // loop at least once through layers.
-
+ boolean isWrapActive= fCachedTextWidget.getWordWrap();
for (int layer= 0; layer < maxLayer; layer++) {
Iterator<Annotation> iter;
if (fModel instanceof IAnnotationModelExtension2)
@@ -695,13 +695,21 @@ public class AnnotationRulerColumn implements IVerticalRulerColumn, IVerticalRul
endLine -= topLine;
r.x= 0;
- r.y= JFaceTextUtil.computeLineHeight(fCachedTextWidget, 0, startLine, startLine) - fScrollPos;
r.width= dimension.x;
int lines= endLine - startLine;
- r.height= JFaceTextUtil.computeLineHeight(fCachedTextWidget, startLine, endLine + 1, lines + 1);
-
+ if (startLine != endLine || !isWrapActive || length <= 0) {
+ // line height for different lines includes wrapped line info already,
+ // end we show annotations without offset info at very first line anyway
+ r.height= JFaceTextUtil.computeLineHeight(fCachedTextWidget, startLine, endLine + 1, lines + 1);
+ r.y= JFaceTextUtil.computeLineHeight(fCachedTextWidget, 0, startLine, startLine) - fScrollPos;
+ } else {
+ // annotate only the part of the line related to the given offset
+ Rectangle textBounds= fCachedTextWidget.getTextBounds(offset, offset + length);
+ r.height= textBounds.height;
+ r.y= textBounds.y;
+ }
if (r.y < dimension.y && fAnnotationAccessExtension != null) // annotation within visible area
fAnnotationAccessExtension.paint(annotation, gc, fCanvas, r);
@@ -733,7 +741,7 @@ public class AnnotationRulerColumn implements IVerticalRulerColumn, IVerticalRul
// draw Annotations
Rectangle r= new Rectangle(0, 0, 0, 0);
ReusableRegion range= new ReusableRegion();
-
+ boolean isWrapActive= fCachedTextWidget.getWordWrap();
int minLayer= Integer.MAX_VALUE, maxLayer= Integer.MIN_VALUE;
fCachedAnnotations.clear();
Iterator<Annotation> iter;
@@ -785,21 +793,33 @@ public class AnnotationRulerColumn implements IVerticalRulerColumn, IVerticalRul
if (widgetRegion == null)
continue;
- int startLine= extension.widgetLineOfWidgetOffset(widgetRegion.getOffset());
+ int offset= widgetRegion.getOffset();
+ int startLine= extension.widgetLineOfWidgetOffset(offset);
if (startLine == -1)
continue;
- int endLine= extension.widgetLineOfWidgetOffset(widgetRegion.getOffset() + Math.max(widgetRegion.getLength() -1, 0));
+ int length= Math.max(widgetRegion.getLength() -1, 0);
+ int endLine= extension.widgetLineOfWidgetOffset(offset + length);
if (endLine == -1)
continue;
r.x= 0;
- r.y= JFaceTextUtil.computeLineHeight(fCachedTextWidget, 0, startLine, startLine) - fScrollPos;
r.width= dimension.x;
int lines= endLine - startLine;
- r.height= JFaceTextUtil.computeLineHeight(fCachedTextWidget, startLine, endLine + 1, lines + 1);
+ if(startLine != endLine || !isWrapActive || length <= 0){
+ // line height for different lines includes wrapped line info already,
+ // end we show annotations without offset info at very first line anyway
+ r.height= JFaceTextUtil.computeLineHeight(fCachedTextWidget, startLine, endLine + 1, lines + 1);
+ r.y= JFaceTextUtil.computeLineHeight(fCachedTextWidget, 0, startLine, startLine) - fScrollPos;
+ } else {
+ // annotate only the part of the line related to the given offset
+ Rectangle textBounds= fCachedTextWidget.getTextBounds(offset, offset + length);
+ r.height= textBounds.height;
+ r.y = textBounds.y;
+ }
+
if (r.y < dimension.y && fAnnotationAccessExtension != null) // annotation within visible area
fAnnotationAccessExtension.paint(annotation, gc, fCanvas, r);
}

Back to the top