Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2019-04-01 22:43:35 +0000
committerMickael Istria2019-04-01 22:57:59 +0000
commited76a4ee96d3a0ea40b6bf4d1447f2af49cb9f7f (patch)
treeccf16a832d3b255db597d44103c2c19bfea07be6 /org.eclipse.jface.text/src/org/eclipse
parent4b9a8a739f42da547975427154744c981d0811ba (diff)
downloadeclipse.platform.text-ed76a4ee96d3a0ea40b6bf4d1447f2af49cb9f7f.tar.gz
eclipse.platform.text-ed76a4ee96d3a0ea40b6bf4d1447f2af49cb9f7f.tar.xz
eclipse.platform.text-ed76a4ee96d3a0ea40b6bf4d1447f2af49cb9f7f.zip
Bug 546020 - [code mining] "Index out of Bounds" when inline w/ foldingI20190407-1800I20190406-1800I20190405-1800I20190404-1800I20190403-1800I20190402-1800
Change-Id: I7b10e2d8122372bec5452225313142cf6ec58f3c Signed-off-by: Mickael Istria <mistria@redhat.com>
Diffstat (limited to 'org.eclipse.jface.text/src/org/eclipse')
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/AbstractInlinedAnnotation.java16
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/InlinedAnnotationDrawingStrategy.java22
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/LineContentAnnotation.java10
3 files changed, 30 insertions, 18 deletions
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/AbstractInlinedAnnotation.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/AbstractInlinedAnnotation.java
index 2eeea983c48..464186604e5 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/AbstractInlinedAnnotation.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/AbstractInlinedAnnotation.java
@@ -22,8 +22,10 @@ import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
+import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewerExtension5;
import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.ISourceViewer;
@@ -72,14 +74,24 @@ public abstract class AbstractInlinedAnnotation extends Annotation {
}
/**
- * Returns the position where the annotation must be drawn.
+ * Returns the position where the annotation must be drawn. For {@link ITextViewerExtension5}
+ * (enabling folding with widget/model projection), this position is the <strong>model</strong>
+ * position.
*
- * @return the position where the annotation must be drawn.
+ * @return the model position where the annotation must be drawn.
*/
public Position getPosition() {
return position;
}
+ final Position computeWidgetPosition() {
+ if (fViewer instanceof ITextViewerExtension5) {
+ IRegion region= ((ITextViewerExtension5) fViewer).modelRange2WidgetRange(new Region(position.getOffset(), position.getLength()));
+ return new Position(region.getOffset(), region.getLength());
+ }
+ return position;
+ }
+
/**
* Returns the {@link StyledText} widget where the annotation must be drawn.
*
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/InlinedAnnotationDrawingStrategy.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/InlinedAnnotationDrawingStrategy.java
index 1bf56916bc6..c29c6332f0a 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/InlinedAnnotationDrawingStrategy.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/InlinedAnnotationDrawingStrategy.java
@@ -32,7 +32,7 @@ import org.eclipse.jface.text.source.AnnotationPainter.IDrawingStrategy;
class InlinedAnnotationDrawingStrategy implements IDrawingStrategy {
@Override
- public void draw(Annotation annotation, GC gc, StyledText textWidget, int offset, int length, Color color) {
+ public void draw(Annotation annotation, GC gc, StyledText textWidget, int widgetoffset, int length, Color color) {
if (!(annotation instanceof AbstractInlinedAnnotation)) {
return;
}
@@ -40,7 +40,7 @@ class InlinedAnnotationDrawingStrategy implements IDrawingStrategy {
// The annotation is not in visible lines, don't draw it.
return;
}
- draw((AbstractInlinedAnnotation) annotation, gc, textWidget, offset, length,
+ draw((AbstractInlinedAnnotation) annotation, gc, textWidget, widgetoffset, length,
color);
}
@@ -50,16 +50,16 @@ class InlinedAnnotationDrawingStrategy implements IDrawingStrategy {
* @param annotation the annotation to be drawn
* @param gc the graphics context, <code>null</code> when in clearing mode
* @param textWidget the text widget to draw on
- * @param offset the offset of the line
+ * @param widgetOffset the offset of the line
* @param length the length of the line
* @param color the color of the line
*/
- public static void draw(AbstractInlinedAnnotation annotation, GC gc, StyledText textWidget, int offset, int length,
+ public static void draw(AbstractInlinedAnnotation annotation, GC gc, StyledText textWidget, int widgetOffset, int length,
Color color) {
if (annotation instanceof LineHeaderAnnotation) {
- draw((LineHeaderAnnotation) annotation, gc, textWidget, offset, length, color);
+ draw((LineHeaderAnnotation) annotation, gc, textWidget, widgetOffset, length, color);
} else {
- draw((LineContentAnnotation) annotation, gc, textWidget, offset, length, color);
+ draw((LineContentAnnotation) annotation, gc, textWidget, widgetOffset, length, color);
}
}
@@ -125,16 +125,16 @@ class InlinedAnnotationDrawingStrategy implements IDrawingStrategy {
* @param annotation the annotation to be drawn
* @param gc the graphics context, <code>null</code> when in clearing mode
* @param textWidget the text widget to draw on
- * @param offset the offset of the line
+ * @param widgetOffset the offset of the line in the widget (not model)
* @param length the length of the line
* @param color the color of the line
*/
- private static void draw(LineContentAnnotation annotation, GC gc, StyledText textWidget, int offset, int length,
+ private static void draw(LineContentAnnotation annotation, GC gc, StyledText textWidget, int widgetOffset, int length,
Color color) {
- if (annotation.drawRightToPreviousChar(offset)) {
- drawAsRightOfPreviousCharacter(annotation, gc, textWidget, offset, length, color);
+ if (annotation.drawRightToPreviousChar(widgetOffset)) {
+ drawAsRightOfPreviousCharacter(annotation, gc, textWidget, widgetOffset, length, color);
} else {
- drawAsLeftOf1stCharacter(annotation, gc, textWidget, offset, length, color);
+ drawAsLeftOf1stCharacter(annotation, gc, textWidget, widgetOffset, length, color);
}
}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/LineContentAnnotation.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/LineContentAnnotation.java
index 76c97148b57..332a8a5837b 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/LineContentAnnotation.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/LineContentAnnotation.java
@@ -108,15 +108,15 @@ public class LineContentAnnotation extends AbstractInlinedAnnotation {
* @return the style to apply with GlyphMetrics width only if needed.
*/
StyleRange updateStyle(StyleRange style) {
- boolean usePreviousChar= drawRightToPreviousChar(getPosition().getOffset());
+ Position widgetPosition= computeWidgetPosition();
+ boolean usePreviousChar= drawRightToPreviousChar(widgetPosition.getOffset());
if (width == 0 || getRedrawnCharacterWidth() == 0) {
return null;
}
int fullWidth= width + getRedrawnCharacterWidth();
if (style == null) {
style= new StyleRange();
- Position position= getPosition();
- style.start= position.getOffset();
+ style.start= widgetPosition.getOffset();
if (usePreviousChar) {
style.start--;
}
@@ -144,8 +144,8 @@ public class LineContentAnnotation extends AbstractInlinedAnnotation {
return style;
}
- boolean drawRightToPreviousChar(int offset) {
- return getTextWidget().getLineAtOffset(offset) == getTextWidget().getLineAtOffset(offset - 1);
+ boolean drawRightToPreviousChar(int widgetOffset) {
+ return getTextWidget().getLineAtOffset(widgetOffset) == getTextWidget().getLineAtOffset(widgetOffset - 1);
}
}

Back to the top