[dotnet, inlays] adjust inlay width to next text-equal width

GitOrigin-RevId: 9d3e207ef07df6671ebb4bb1f278fc1915622b6b
This commit is contained in:
Nikolay Plyusnin
2024-06-10 15:30:38 +03:00
committed by intellij-monorepo-bot
parent 5b2556c776
commit 01a0db3047

View File

@@ -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)