From 805b73fcc93ccf64fa74af6d65a60faddc79208d Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Thu, 12 Jul 2007 14:06:08 +0000 Subject: [PATCH] Make LineBackgroundPainter conform to CursorLinePainter (related to bug 195853) --- .../internal/ui/LineBackgroundPainter.java | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/LineBackgroundPainter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/LineBackgroundPainter.java index 26a46ec8003..10a11e0fe77 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/LineBackgroundPainter.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/LineBackgroundPainter.java @@ -70,6 +70,8 @@ public class LineBackgroundPainter implements IPainter, LineBackgroundListener { private Position fLastCursorLine= new Position(0, 0); /** Enablement of the cursor line highlighting */ private boolean fCursorLineEnabled; + /** Whether cursor line highlighting is active */ + private boolean fCursorLineActive; /** Map of position type to color */ private Map fColorMap= new HashMap(); @@ -120,7 +122,8 @@ public class LineBackgroundPainter implements IPainter, LineBackgroundListener { */ public void enableCursorLine(boolean enable) { fCursorLineEnabled= enable; - if (fCursorLineEnabled) { + fCursorLineActive= enable; + if (fCursorLineActive) { updateCursorLine(); } } @@ -260,14 +263,28 @@ public class LineBackgroundPainter implements IPainter, LineBackgroundListener { return; } activate(false); + if (fCursorLineEnabled) { - // redraw in case of text changes prior to update of current cursor line - if (!fLastCursorLine.equals(fCursorLine)) { + // check selection + StyledText textWidget= fTextViewer.getTextWidget(); + Point selection= textWidget.getSelection(); + int startLine= textWidget.getLineAtOffset(selection.x); + int endLine= textWidget.getLineAtOffset(selection.y); + if (startLine != endLine) { redrawPositions(Collections.singletonList(fLastCursorLine)); - fLastCursorLine.offset= fCursorLine.offset; - fLastCursorLine.length= fCursorLine.length; + fCursorLineActive= false; + } else { + fCursorLineActive= true; + } + if (fCursorLineActive) { + // redraw in case of text changes prior to update of current cursor line + if (!fLastCursorLine.equals(fCursorLine)) { + redrawPositions(Collections.singletonList(fLastCursorLine)); + fLastCursorLine.offset= fCursorLine.offset; + fLastCursorLine.length= fCursorLine.length; + } + updateCursorLine(); } - updateCursorLine(); } List changedPositions= getChangedPositions(); if (changedPositions != null) { @@ -286,7 +303,7 @@ public class LineBackgroundPainter implements IPainter, LineBackgroundListener { fIsActive= true; fTextWidget.addLineBackgroundListener(this); if (redraw) { - if (fCursorLineEnabled) { + if (fCursorLineActive) { updateCursorLine(); } updatePositions(); @@ -510,7 +527,7 @@ public class LineBackgroundPainter implements IPainter, LineBackgroundListener { */ private Position findIncludingPosition(int offset) { // TLETODO [performance] Use binary search? - for (int i= fCursorLineEnabled ? 0 : 1, sz= fPositions.size(); i < sz; ++i) { + for (int i= fCursorLineActive ? 0 : 1, sz= fPositions.size(); i < sz; ++i) { Position position= (Position)fPositions.get(i); if (position.offset == offset || position.includes(offset)) { return position;