@@ -48,7 +48,8 @@ import java.lang.ref.SoftReference
4848/* *
4949 * This JPanel gets injected into editor windows and renders a image generated by GlanceFileRenderer
5050 */
51- class GlancePanel (private val project : Project , fileEditor : FileEditor , private val container : JPanel , private val runner : TaskRunner ) : JPanel(), VisibleAreaListener {
51+ class GlancePanel (private val project : Project , fileEditor : FileEditor , private val container : JPanel , private val runner : TaskRunner ) : JPanel(),
52+ VisibleAreaListener {
5253 private val editor = (fileEditor as TextEditor ).editor
5354 private var mapRef = SoftReference <Minimap >(null )
5455 private val configService = ServiceManager .getService(ConfigService ::class .java)
@@ -62,7 +63,7 @@ class GlancePanel(private val project: Project, fileEditor: FileEditor, private
6263 // Anonymous Listeners that should be cleaned up.
6364 private val componentListener: ComponentListener
6465 private val documentListener: DocumentListener
65- private val selectionListener: SelectionListener = SelectionListener { repaint() }
66+ private val selectionListener: SelectionListener
6667
6768 private val isDisabled: Boolean
6869 get() = config.disabled || editor.document.textLength > config.maxFileSize || editor.document.lineCount < config.minLineCount || container.width < config.minWindowWidth
@@ -85,8 +86,8 @@ class GlancePanel(private val project: Project, fileEditor: FileEditor, private
8586 }
8687 container.addComponentListener(componentListener)
8788
88- documentListener = object : DocumentAdapter () {
89- override fun documentChanged (documentEvent : DocumentEvent ? ) {
89+ documentListener = object : DocumentListener {
90+ override fun documentChanged (event : DocumentEvent ) {
9091 updateImage()
9192 }
9293 }
@@ -96,6 +97,12 @@ class GlancePanel(private val project: Project, fileEditor: FileEditor, private
9697
9798 editor.scrollingModel.addVisibleAreaListener(this )
9899
100+ selectionListener = object : SelectionListener {
101+ override fun selectionChanged (e : SelectionEvent ) {
102+ repaint()
103+ }
104+ }
105+
99106 editor.selectionModel.addSelectionListener(selectionListener)
100107 updateSize()
101108 updateImage()
@@ -120,7 +127,7 @@ class GlancePanel(private val project: Project, fileEditor: FileEditor, private
120127
121128 // the minimap is held by a soft reference so the GC can delete it at any time.
122129 // if its been deleted and we want it again (active tab) we recreate it.
123- private fun getOrCreateMap () : Minimap ? {
130+ private fun getOrCreateMap (): Minimap ? {
124131 var map = mapRef.get()
125132
126133 if (map == null ) {
@@ -170,10 +177,12 @@ class GlancePanel(private val project: Project, fileEditor: FileEditor, private
170177
171178
172179 if (buf != null ) {
173- g.drawImage(buf,
180+ g.drawImage(
181+ buf,
174182 0 , 0 , buf!! .width, buf!! .height,
175183 0 , 0 , buf!! .width, buf!! .height,
176- null )
184+ null
185+ )
177186 }
178187 paintSelections(g)
179188 scrollbar.paint(gfx)
@@ -251,7 +260,7 @@ class GlancePanel(private val project: Project, fileEditor: FileEditor, private
251260 }
252261
253262 private fun paintSelections (g : Graphics2D ) {
254- paintSelection(g, editor.selectionModel.selectionStart, editor.selectionModel.selectionEnd)
263+ paintSelection(g, editor.selectionModel.selectionStart, editor.selectionModel.selectionEnd)
255264
256265 for ((index, start) in editor.selectionModel.blockSelectionStarts.withIndex()) {
257266 paintSelection(g, start, editor.selectionModel.blockSelectionEnds[index])
0 commit comments