1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 10:46:02 +02:00

Make LineBackgroundPainter conform to CursorLinePainter (related to bug 195853)

This commit is contained in:
Anton Leherbauer 2007-07-12 14:06:08 +00:00
parent 9f2b40cbd9
commit 805b73fcc9

View file

@ -70,6 +70,8 @@ public class LineBackgroundPainter implements IPainter, LineBackgroundListener {
private Position fLastCursorLine= new Position(0, 0); private Position fLastCursorLine= new Position(0, 0);
/** Enablement of the cursor line highlighting */ /** Enablement of the cursor line highlighting */
private boolean fCursorLineEnabled; private boolean fCursorLineEnabled;
/** Whether cursor line highlighting is active */
private boolean fCursorLineActive;
/** Map of position type to color */ /** Map of position type to color */
private Map fColorMap= new HashMap(); private Map fColorMap= new HashMap();
@ -120,7 +122,8 @@ public class LineBackgroundPainter implements IPainter, LineBackgroundListener {
*/ */
public void enableCursorLine(boolean enable) { public void enableCursorLine(boolean enable) {
fCursorLineEnabled= enable; fCursorLineEnabled= enable;
if (fCursorLineEnabled) { fCursorLineActive= enable;
if (fCursorLineActive) {
updateCursorLine(); updateCursorLine();
} }
} }
@ -260,14 +263,28 @@ public class LineBackgroundPainter implements IPainter, LineBackgroundListener {
return; return;
} }
activate(false); activate(false);
if (fCursorLineEnabled) { if (fCursorLineEnabled) {
// redraw in case of text changes prior to update of current cursor line // check selection
if (!fLastCursorLine.equals(fCursorLine)) { 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)); redrawPositions(Collections.singletonList(fLastCursorLine));
fLastCursorLine.offset= fCursorLine.offset; fCursorLineActive= false;
fLastCursorLine.length= fCursorLine.length; } 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(); List changedPositions= getChangedPositions();
if (changedPositions != null) { if (changedPositions != null) {
@ -286,7 +303,7 @@ public class LineBackgroundPainter implements IPainter, LineBackgroundListener {
fIsActive= true; fIsActive= true;
fTextWidget.addLineBackgroundListener(this); fTextWidget.addLineBackgroundListener(this);
if (redraw) { if (redraw) {
if (fCursorLineEnabled) { if (fCursorLineActive) {
updateCursorLine(); updateCursorLine();
} }
updatePositions(); updatePositions();
@ -510,7 +527,7 @@ public class LineBackgroundPainter implements IPainter, LineBackgroundListener {
*/ */
private Position findIncludingPosition(int offset) { private Position findIncludingPosition(int offset) {
// TLETODO [performance] Use binary search? // 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); Position position= (Position)fPositions.get(i);
if (position.offset == offset || position.includes(offset)) { if (position.offset == offset || position.includes(offset)) {
return position; return position;