From 0c7abbfcd8f8ea5570c753512f00debcb7bb6aa7 Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Thu, 3 Oct 2019 14:42:22 +0300 Subject: [PATCH] allow disabling margins around annotations in editor gutter GitOrigin-RevId: f22952150422600c4084d3ad68ad31df78666de6 --- .../openapi/editor/TextAnnotationGutterProvider.java | 8 ++++++++ .../openapi/editor/impl/EditorGutterComponentImpl.java | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/platform/editor-ui-api/src/com/intellij/openapi/editor/TextAnnotationGutterProvider.java b/platform/editor-ui-api/src/com/intellij/openapi/editor/TextAnnotationGutterProvider.java index 80ad4636ad0b..329ea6080221 100644 --- a/platform/editor-ui-api/src/com/intellij/openapi/editor/TextAnnotationGutterProvider.java +++ b/platform/editor-ui-api/src/com/intellij/openapi/editor/TextAnnotationGutterProvider.java @@ -71,4 +71,12 @@ public interface TextAnnotationGutterProvider { * @see EditorGutter#closeAllAnnotations() */ void gutterClosed(); + + /** + * If {@code true}, a couple of pixels will be added at both sides of displayed text (if it's not empty), + * otherwise the width of annotation will be equal to the width of provided text. + */ + default boolean useMargin() { + return true; + } } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java index a043ab86571b..6dccf1a0b97a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java @@ -487,7 +487,7 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse EditorFontType style = gutterProvider.getStyle(line, myEditor); Font font = getFontForText(s, style); g.setFont(font); - g.drawString(s, getGapBetweenAnnotations() / 2 + x, y + myEditor.getAscent()); + g.drawString(s, (gutterProvider.useMargin() ? getGapBetweenAnnotations() / 2 : 0) + x, y + myEditor.getAscent()); } } @@ -772,7 +772,7 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse gutterSize = Math.max(gutterSize, fontMetrics.stringWidth(lineText)); } } - if (gutterSize > 0 && j < guttersCount - 1) gutterSize += getGapBetweenAnnotations(); + if (gutterSize > 0 && gutterProvider.useMargin()) gutterSize += getGapBetweenAnnotations(); myTextAnnotationGutterSizes.set(j, gutterSize); myTextAnnotationGuttersSize += gutterSize; }