Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2019-11-18 14:10:07 +0000
committerMickael Istria2019-11-26 08:19:56 +0000
commit5550281aef563a9cce3601ba9a9d6ca19118fd67 (patch)
tree19def1f9a658acdcffd23274127798024aa38302
parent52f489ee726a5e60319bf40620717581bd0b0435 (diff)
downloadeclipse.platform.text-5550281aef563a9cce3601ba9a9d6ca19118fd67.tar.gz
eclipse.platform.text-5550281aef563a9cce3601ba9a9d6ca19118fd67.tar.xz
eclipse.platform.text-5550281aef563a9cce3601ba9a9d6ca19118fd67.zip
Bug 553133 - VisibleLinesTracker: don't mix model lines and pixelsY20191126-0500I20191126-2315I20191126-1800I20191126-0600
VisibleLinesTracker called JFaceTextUtil.getLinePixel(widget, index) with a model line index. This is wrong and caused trouble with line numbers not updating correctly in some cases when folding/unfolding in a ProjectionViewer. Track both widget and model bottom indices, and use the widget index to determine the bottom pixel. Also update copyright year and use the standard copyright header format. Change-Id: Ia4ad93078cd1e278b4f496277bf00d53dda1e7e3 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/VisibleLinesTracker.java44
1 files changed, 23 insertions, 21 deletions
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/VisibleLinesTracker.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/VisibleLinesTracker.java
index 4f8c2dfd37d..258b41b1697 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/VisibleLinesTracker.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/VisibleLinesTracker.java
@@ -1,5 +1,5 @@
-/**
- * Copyright (c) 2018 Angelo ZERR.
+/*******************************************************************************
+ * Copyright (c) 2018, 2019 Angelo ZERR and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -9,8 +9,9 @@
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
- * Angelo Zerr <angelo.zerr@gmail.com> - Bug 527720 - [CodeMining] Line number in vertical ruler can be not synchronized with line header annotation
- */
+ * Angelo Zerr <angelo.zerr@gmail.com> - Bug 527720 - [CodeMining] Line number in vertical ruler can be not synchronized with line header annotation
+ * Thomas Wolf <thomas.wolf@paranor.ch> - Bug 553133
+ *******************************************************************************/
package org.eclipse.jface.text.source;
import java.util.LinkedHashSet;
@@ -24,8 +25,7 @@ import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.JFaceTextUtil;
/**
- * Class to track line height change of visible lines of a given {@link StyledText}.
- *
+ * Tracks line height changes of visible lines of a given {@link StyledText}.
*/
class VisibleLinesTracker implements PaintListener {
@@ -37,9 +37,14 @@ class VisibleLinesTracker implements PaintListener {
private final ITextViewer viewer;
/**
- * The previous bottom line index.
+ * The previous bottom model line index.
+ */
+ private int oldModelBottom= -1;
+
+ /**
+ * The previous bottom widget line index.
*/
- private int oldBottom= -1;
+ private int oldWidgetBottom= -1;
/**
* The previous bottom line pixel.
@@ -65,23 +70,20 @@ class VisibleLinesTracker implements PaintListener {
public void paintControl(PaintEvent e) {
StyledText textWidget= viewer.getTextWidget();
// track if bottom line index or bottom line pixel changed.
- if (oldBottom == -1) {
- oldBottom= JFaceTextUtil.getPartialBottomIndex(viewer);
- oldBottomPixel= JFaceTextUtil.getLinePixel(textWidget, oldBottom);
+ if (oldModelBottom == -1) {
+ oldWidgetBottom= JFaceTextUtil.getPartialBottomIndex(textWidget);
+ oldModelBottom= JFaceTextUtil.widgetLine2ModelLine(viewer, oldWidgetBottom);
+ oldBottomPixel= JFaceTextUtil.getLinePixel(textWidget, oldWidgetBottom);
return;
}
- int newBottom= JFaceTextUtil.getPartialBottomIndex(viewer);
- if (newBottom != oldBottom) {
- oldBottom= newBottom;
- oldBottomPixel= JFaceTextUtil.getLinePixel(textWidget, oldBottom);
- handlers.forEach(handler -> handler.accept(textWidget));
- return;
- }
- int newBottomPixel= JFaceTextUtil.getLinePixel(textWidget, newBottom);
- if (newBottomPixel != oldBottomPixel) {
+ int newWidgetBottom= JFaceTextUtil.getPartialBottomIndex(textWidget);
+ int newModelBottom= JFaceTextUtil.widgetLine2ModelLine(viewer, newWidgetBottom);
+ int newBottomPixel= JFaceTextUtil.getLinePixel(textWidget, newWidgetBottom);
+ if (newWidgetBottom != oldWidgetBottom || newModelBottom != oldModelBottom || newBottomPixel != oldBottomPixel) {
+ oldWidgetBottom= newWidgetBottom;
+ oldModelBottom= newModelBottom;
oldBottomPixel= newBottomPixel;
handlers.forEach(handler -> handler.accept(textWidget));
- return;
}
}

Back to the top