[kotlin] K2 Introduce variable refactoring: show the settings popup above the gear icon to prevent it from being closed

by the list of suggested names when selecting the "Specify type explicitly" setting

^KTIJ-21135

GitOrigin-RevId: 11d27b6eed6ffe90a0a4a9afcdbb21416f981d24
This commit is contained in:
Andrey Cherkasov
2023-07-03 21:31:30 +04:00
committed by intellij-monorepo-bot
parent 1d485a6072
commit ed254de550
3 changed files with 28 additions and 11 deletions

View File

@@ -273,7 +273,8 @@ object InplaceExtractUtils {
logStatisticsOnHide(project, settingsPopup)
}
}
return TemplateInlayUtil.createNavigatableButtonWithPopup(templateState.editor, offset, presentation, settingsPopup.panel, templateElement)
return TemplateInlayUtil.createNavigatableButtonWithPopup(templateState.editor, offset, presentation, settingsPopup.panel,
templateElement, isPopupAbove = false)
}
fun addPreview(preview: EditorCodePreview, editor: Editor, lines: IntRange, navigatableOffset: Int){

View File

@@ -32,10 +32,12 @@ import com.intellij.refactoring.rename.RenamePsiElementProcessor
import com.intellij.refactoring.rename.impl.TextOptions
import com.intellij.refactoring.rename.impl.isEmpty
import com.intellij.refactoring.util.TextOccurrencesUtil
import com.intellij.ui.awt.RelativePoint
import com.intellij.ui.dsl.builder.RightGap
import com.intellij.ui.dsl.builder.panel
import com.intellij.ui.dsl.builder.selected
import com.intellij.ui.popup.PopupFactoryImpl
import com.intellij.ui.util.preferredHeight
import com.intellij.util.ui.JBEmptyBorder
import com.intellij.util.ui.JBInsets
import org.jetbrains.annotations.ApiStatus
@@ -107,7 +109,8 @@ object TemplateInlayUtil {
panel: DialogPanel,
templateElement: SelectableTemplateElement = SelectableTemplateElement(presentation),
logStatisticsOnHide: () -> Unit = {}): Inlay<PresentationRenderer>? {
return createNavigatableButtonWithPopup(templateState, inEditorOffset, presentation, panel as JPanel, templateElement, logStatisticsOnHide)
return createNavigatableButtonWithPopup(templateState, inEditorOffset, presentation, panel as JPanel, templateElement,
isPopupAbove = false, logStatisticsOnHide)
}
@JvmOverloads
@@ -117,8 +120,10 @@ object TemplateInlayUtil {
presentation: SelectableInlayPresentation,
panel: JPanel,
templateElement: SelectableTemplateElement = SelectableTemplateElement(presentation),
isPopupAbove: Boolean,
logStatisticsOnHide: () -> Unit = {}): Inlay<PresentationRenderer>? {
val inlay = createNavigatableButtonWithPopup(templateState.editor, inEditorOffset, presentation, panel, templateElement) ?: return null
val inlay = createNavigatableButtonWithPopup(templateState.editor, inEditorOffset, presentation, panel, templateElement,
isPopupAbove = isPopupAbove) ?: return null
Disposer.register(templateState, inlay)
presentation.addSelectionListener { isSelected ->
if (!isSelected) logStatisticsOnHide.invoke()
@@ -128,11 +133,13 @@ object TemplateInlayUtil {
@JvmOverloads
@JvmStatic
fun createNavigatableButtonWithPopup(editor: Editor,
offset: Int,
presentation: SelectableInlayPresentation,
panel: JPanel,
templateElement: SelectableTemplateElement = SelectableTemplateElement(presentation),
fun createNavigatableButtonWithPopup(
editor: Editor,
offset: Int,
presentation: SelectableInlayPresentation,
panel: JPanel,
templateElement: SelectableTemplateElement = SelectableTemplateElement(presentation),
isPopupAbove: Boolean,
): Inlay<PresentationRenderer>? {
val inlay = createNavigatableButton(editor, offset, presentation, templateElement) ?: return null
fun showPopup() {
@@ -158,7 +165,15 @@ object TemplateInlayUtil {
.registerCustomShortcutSet(KeymapUtil.getActiveKeymapShortcuts(IdeActions.ACTION_EDITOR_ENTER), panel, popup)
try {
editor.putUserData(PopupFactoryImpl.ANCHOR_POPUP_POSITION, inlay.visualPosition)
popup.showInBestPositionFor(editor)
if (isPopupAbove) {
val popupFactory = JBPopupFactory.getInstance()
val target = popupFactory.guessBestPopupLocation(editor)
val screenPoint = target.getScreenPoint()
popup.show(RelativePoint(Point(screenPoint.x, screenPoint.y - editor.lineHeight - panel.preferredHeight)))
}
else {
popup.showInBestPositionFor(editor)
}
}
finally {
editor.putUserData(PopupFactoryImpl.ANCHOR_POPUP_POSITION, null)
@@ -317,7 +332,7 @@ object TemplateInlayUtil {
}
optionsListener.invoke(newOptions)
}
return createNavigatableButtonWithPopup(templateState, offset, presentation, panel as JPanel, templateElement) {
return createNavigatableButtonWithPopup(templateState, offset, presentation, panel as JPanel, templateElement, isPopupAbove = false) {
logStatisticsOnHide(editor, initOptions, currentOptions)
}
}

View File

@@ -162,7 +162,8 @@ class KotlinVariableInplaceIntroducer(
currentVariableRange.endOffset,
presentation,
popupComponent as JPanel,
templateElement
templateElement,
isPopupAbove = true
) { }
}