From 7ce63830348cf57580f86203090c4eeaba16fda2 Mon Sep 17 00:00:00 2001 From: Louis Vignier Date: Tue, 30 Jul 2024 18:42:31 +0200 Subject: [PATCH] [intention-preview] Fix intention preview width #IJPL-158759 Fixed GitOrigin-RevId: f988a806c89e029cdb3752bfd6c0559deb530d06 --- .../preview/IntentionPreviewPopupUpdateProcessor.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/preview/IntentionPreviewPopupUpdateProcessor.kt b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/preview/IntentionPreviewPopupUpdateProcessor.kt index fab7474a7048..86560e09899c 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/preview/IntentionPreviewPopupUpdateProcessor.kt +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/preview/IntentionPreviewPopupUpdateProcessor.kt @@ -174,7 +174,6 @@ class IntentionPreviewPopupUpdateProcessor internal constructor( IntentionPreviewComponent.NO_PREVIEW_LABEL } else { - val size = component.preferredSize val location = popup.locationOnScreen val screen = ScreenUtil.getScreenRectangle(location) @@ -185,13 +184,15 @@ class IntentionPreviewPopupUpdateProcessor internal constructor( if (origLocation != null && location.x < origLocation.x) { delta = delta.coerceAtMost(origLocation.x - screen.x - PositionAdjuster.DEFAULT_GAP) } - size.width = size.width.coerceAtMost(delta) for (editor in editors) { editor.softWrapModel.addSoftWrapChangeListener(object : SoftWrapChangeListener { override fun recalculationEnds() { val height = (editor as EditorImpl).offsetToXY(editor.document.textLength).y + editor.lineHeight + 6 - editor.component.preferredSize = Dimension(editor.component.preferredSize.width, min(height, MAX_HEIGHT)) + editor.component.preferredSize = Dimension( + max(editor.component.preferredSize.width, MIN_WIDTH).coerceAtMost(delta), + min(height, MAX_HEIGHT) + ) editor.component.parent?.invalidate() popup.pack(true, true) } @@ -199,7 +200,10 @@ class IntentionPreviewPopupUpdateProcessor internal constructor( override fun softWrapsChanged() {} }) - editor.component.preferredSize = Dimension(max(size.width, MIN_WIDTH), min(editor.component.preferredSize.height, MAX_HEIGHT)) + editor.component.preferredSize = Dimension( + max(editor.component.preferredSize.width, MIN_WIDTH).coerceAtMost(delta), + min(editor.component.preferredSize.height, MAX_HEIGHT) + ) } editorsToRelease.addAll(editors)