From 46fce02e4b9a103bed2401754a27303e98cbe7cd Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Mon, 10 Feb 2014 12:00:52 +0400 Subject: [PATCH] IDEA-120265 Incorrect whitespaces (tab) painting when cursor change position --- .../openapi/editor/impl/ArrowPainter.java | 15 ++++++++++++--- .../intellij/openapi/editor/impl/EditorImpl.java | 1 + .../impl/softwrap/ArrowSoftWrapPainter.java | 11 +++++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/ArrowPainter.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/ArrowPainter.java index b5b9e6945d61..38b00078596d 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/ArrowPainter.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/ArrowPainter.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,10 +30,19 @@ import java.awt.*; public class ArrowPainter { private final ColorProvider myColorHolder; + private final Computable myWidthProvider; private final Computable myHeightProvider; - public ArrowPainter(@NotNull ColorProvider colorHolder, @NotNull Computable heightProvider) { + /** + * Creates an ArrowPainter with specified parameters. + * + * @param colorHolder defines arrow color + * @param widthProvider defines character width, it is used to calculate an inset for the arrow's tip + * @param heightProvider defines character height, it's used to calculate an arrow's width and height + */ + public ArrowPainter(@NotNull ColorProvider colorHolder, @NotNull Computable widthProvider, @NotNull Computable heightProvider) { myColorHolder = colorHolder; + myWidthProvider = widthProvider; myHeightProvider = heightProvider; } @@ -46,7 +55,7 @@ public class ArrowPainter { * @param stop ending 'x' position to use during drawing */ public void paint(Graphics g, int y, int start, int stop) { - stop -= g.getFontMetrics().charWidth(' ') / 2; + stop -= myWidthProvider.compute() / 2; Color oldColor = g.getColor(); g.setColor(myColorHolder.getColor()); final int height = myHeightProvider.compute(); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java index b9c391a0c545..ef49b827c7dc 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java @@ -729,6 +729,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi private void initTabPainter() { myTabPainter = new ArrowPainter( ColorProvider.byColorsScheme(myScheme, EditorColors.WHITESPACES_COLOR), + new Computable.PredefinedValueComputable(EditorUtil.getSpaceWidth(Font.PLAIN, this)), new Computable() { @Override public Integer compute() { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/ArrowSoftWrapPainter.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/ArrowSoftWrapPainter.java index ccd241e977ef..d00eb487a627 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/ArrowSoftWrapPainter.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/softwrap/ArrowSoftWrapPainter.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,7 +43,7 @@ public class ArrowSoftWrapPainter implements SoftWrapPainter { public ArrowSoftWrapPainter(Editor editor) { myEditor = editor; - myArrowPainter = new ArrowPainter(ColorProvider.byColor(myEditor.getColorsScheme().getDefaultForeground()), myHeightProvider); + myArrowPainter = new ArrowPainter(ColorProvider.byColor(myEditor.getColorsScheme().getDefaultForeground()), new WidthProvider(), myHeightProvider); } @Override @@ -102,4 +102,11 @@ public class ArrowSoftWrapPainter implements SoftWrapPainter { return myHeight; } } + + private class WidthProvider implements Computable { + @Override + public Integer compute() { + return EditorUtil.getSpaceWidth(Font.PLAIN, myEditor); + } + } }