From 01a0db3047f958b4e95cd6aa01b8b0dd2195fb6b Mon Sep 17 00:00:00 2001 From: Nikolay Plyusnin Date: Mon, 10 Jun 2024 15:30:38 +0300 Subject: [PATCH] [dotnet, inlays] adjust inlay width to next text-equal width GitOrigin-RevId: 9d3e207ef07df6671ebb4bb1f278fc1915622b6b --- .../hints/presentation/PresentationFactory.kt | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hints/presentation/PresentationFactory.kt b/platform/lang-impl/src/com/intellij/codeInsight/hints/presentation/PresentationFactory.kt index 089bf68c2398..59ae12716a52 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hints/presentation/PresentationFactory.kt +++ b/platform/lang-impl/src/com/intellij/codeInsight/hints/presentation/PresentationFactory.kt @@ -15,6 +15,7 @@ import com.intellij.openapi.editor.colors.CodeInsightColors import com.intellij.openapi.editor.colors.EditorColors import com.intellij.openapi.editor.colors.EditorColors.REFERENCE_HYPERLINK_COLOR import com.intellij.openapi.editor.colors.TextAttributesKey +import com.intellij.openapi.editor.ex.util.EditorUtil import com.intellij.openapi.util.NlsContexts import com.intellij.openapi.vfs.JarFileSystem import com.intellij.openapi.vfs.VfsUtilCore @@ -118,6 +119,30 @@ class PresentationFactory(private val editor: Editor) : InlayPresentationFactory return DynamicInsetPresentation(rounding, offsetFromTopProvider) } + @Contract(pure = true) + fun roundWithBackgroundAndNoInset(base: InlayPresentation): InlayPresentation { + val rounding = withInlayAttributes(RoundWithBackgroundPresentation(base, 8, 8)) + return DynamicInsetPresentation(rounding, offsetFromTopProvider) + } + + @Contract(pure = true) + fun adjustToNextTextEqualWidth(base: InlayPresentation): InlayPresentation { + return DynamicInsetPresentation(base, object : InsetValueProvider { + + fun getInset(roundUp: Boolean): Int { + val spaceWidth = EditorUtil.getPlainSpaceWidth(editor) + val additionalWidth = spaceWidth - base.width % spaceWidth + return if (roundUp) (additionalWidth + 1) / 2 else additionalWidth / 2 + } + + override val left: Int + get() = getInset(true) + + override val right: Int + get() = getInset(false) + }) + } + @Contract(pure = true) override fun icon(icon: Icon): IconPresentation = IconPresentation(icon, editor.component)