@@ -23,31 +23,33 @@ import com.intellij.openapi.ui.ComponentValidator
23
23
import com.intellij.openapi.ui.ValidationInfo
24
24
import com.intellij.openapi.ui.popup.JBPopup
25
25
import com.intellij.openapi.ui.popup.JBPopupFactory
26
+ import com.intellij.openapi.ui.popup.JBPopupListener
27
+ import com.intellij.openapi.ui.popup.LightweightWindowEvent
26
28
import com.intellij.openapi.wm.IdeFocusManager
27
29
import com.intellij.openapi.wm.impl.InternalDecorator
28
30
import com.intellij.temporary.gui.block.AutoDevCoolBorder
29
31
import com.intellij.ui.JBColor
30
32
import com.intellij.ui.MutableCollectionComboBoxModel
31
33
import com.intellij.ui.SimpleListCellRenderer
34
+ import com.intellij.ui.awt.RelativePoint
32
35
import com.intellij.ui.components.JBLabel
33
36
import com.intellij.ui.content.ContentManager
34
37
import com.intellij.util.EventDispatcher
35
38
import com.intellij.util.ui.JBEmptyBorder
36
39
import com.intellij.util.ui.JBUI
37
40
import com.intellij.util.ui.UIUtil
38
41
import com.intellij.util.ui.components.BorderLayoutPanel
39
- import com.intellij.vcsUtil.showAbove
40
42
import kotlinx.serialization.decodeFromString
41
43
import kotlinx.serialization.json.Json
42
44
import java.awt.Color
43
45
import java.awt.Component
44
46
import java.awt.Dimension
47
+ import java.awt.Point
45
48
import java.awt.event.MouseAdapter
46
49
import java.awt.event.MouseEvent
47
50
import java.util.function.Supplier
48
51
import javax.swing.Box
49
52
import javax.swing.JComponent
50
- import javax.swing.JTextField
51
53
import kotlin.math.max
52
54
import kotlin.math.min
53
55
@@ -106,11 +108,15 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
106
108
107
109
// check new input == $
108
110
if (event.newFragment.contentEquals(" $" ) || event.newFragment.contentEquals(" ¥" )) {
111
+ if (popup?.isVisible == true ) {
112
+ popup?.cancel()
113
+ }
114
+
109
115
if (popup?.isDisposed == true ) {
110
116
popup = createPopup()
111
- popup?.showAbove(input )
117
+ showPopupAbove(popup !! , this @AutoDevInputSection )
112
118
} else {
113
- popup?.showAbove(input )
119
+ showPopupAbove(popup !! , this @AutoDevInputSection )
114
120
}
115
121
}
116
122
}
@@ -169,10 +175,13 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
169
175
tokenizer = TokenizerImpl .INSTANCE
170
176
}
171
177
172
- private fun createPopup () = JBPopupFactory .getInstance().createComponentPopupBuilder(AutoDevVariableListComponent (), null )
178
+ private fun createPopup () = JBPopupFactory .getInstance()
179
+ .createComponentPopupBuilder(AutoDevVariableList (listOf (
180
+ AutoDevVariableListComponent (),
181
+ ) ,null ), null )
173
182
.setRequestFocus(false )
174
183
.setMinSize(
175
- Dimension (200 , 200 )
184
+ Dimension (this @AutoDevInputSection.width, 0 )
176
185
).createPopup()
177
186
178
187
@@ -266,4 +275,19 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
266
275
}
267
276
268
277
val focusableComponent: JComponent get() = input
269
- }
278
+ }
279
+
280
+ fun showPopupAbove (popup : JBPopup , component : Component ) {
281
+ val northWest = RelativePoint (component, Point ())
282
+
283
+ popup.addListener(object : JBPopupListener {
284
+ override fun beforeShown (event : LightweightWindowEvent ) {
285
+ val location = Point (popup.locationOnScreen).apply { y = northWest.screenPoint.y - popup.size.height }
286
+
287
+ popup.setLocation(location)
288
+ popup.removeListener(this )
289
+ }
290
+ })
291
+
292
+ popup.show(northWest)
293
+ }
0 commit comments