Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/net/vektah/codeglance/EditorPanelInjector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class EditorPanelInjector(private val project: Project, private val runner: Task
val glancePanel = GlancePanel(project, editor, panel, runner)
panel.add(glancePanel, where)
panels.put(editor, glancePanel)
glancePanel.updateImage()
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/vektah/codeglance/GlancePanel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ import net.vektah.codeglance.concurrent.DirtyLock
import net.vektah.codeglance.config.Config
import net.vektah.codeglance.config.ConfigService
import net.vektah.codeglance.render.*

import javax.swing.*
import java.awt.*
import java.awt.event.*
import java.awt.image.BufferedImage
import java.lang.ref.SoftReference
import javax.swing.*

/**
* This JPanel gets injected into editor windows and renders a image generated by GlanceFileRenderer
Expand Down Expand Up @@ -78,6 +77,7 @@ class GlancePanel(private val project: Project, fileEditor: FileEditor, private
componentListener = object : ComponentAdapter() {
override fun componentResized(componentEvent: ComponentEvent?) {
updateSize()
updateImage()
scrollstate.setVisibleHeight(height)
this@GlancePanel.revalidate()
this@GlancePanel.repaint()
Expand Down Expand Up @@ -120,11 +120,11 @@ class GlancePanel(private val project: Project, fileEditor: FileEditor, private

// the minimap is held by a soft reference so the GC can delete it at any time.
// if its been deleted and we want it again (active tab) we recreate it.
private fun getOrCreateMap() : Minimap? {
private fun getOrCreateMap(): Minimap? {
var map = mapRef.get()

if (map == null) {
map = Minimap(configService.state!!)
map = Minimap(configService.state!!, editor)
mapRef = SoftReference<Minimap>(map)
}

Expand All @@ -134,7 +134,7 @@ class GlancePanel(private val project: Project, fileEditor: FileEditor, private
/**
* Fires off a new task to the worker thread. This should only be called from the ui thread.
*/
private fun updateImage() {
fun updateImage() {
if (isDisabled) return
if (project.isDisposed) return

Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/vektah/codeglance/render/Folds.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
package net.vektah.codeglance.render

import com.intellij.openapi.editor.FoldRegion
import java.util.HashSet

// Is a copy of Array<FoldRegion> that only contains folded folds and can be passed safely to another thread
class Folds{
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/net/vektah/codeglance/render/Minimap.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@

package net.vektah.codeglance.render

import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.editor.FoldRegion
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.colors.EditorColorsScheme
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
import com.intellij.openapi.fileTypes.SyntaxHighlighter
import com.intellij.psi.tree.IElementType
import net.vektah.codeglance.config.Config
Expand All @@ -39,7 +41,7 @@ import java.util.ArrayList
/**
* A rendered minimap of a document
*/
class Minimap(private val config: Config) {
class Minimap(private val config: Config, private val editor: Editor) {
var img: BufferedImage? = null
var height: Int = 0
private val logger = Logger.getInstance(javaClass)
Expand Down Expand Up @@ -92,6 +94,14 @@ class Minimap(private val config: Config) {
this.line_endings = line_endings
height = (lines + 1) * config.pixelsPerLine

if (EditorSettingsExternalizable.getInstance().isAdditionalPageAtBottom) {
ApplicationManager.getApplication().runReadAction {
val editorHeight = editor.component.height
val linesOnScreen = editorHeight / editor.lineHeight
height += linesOnScreen * config.pixelsPerLine
}
}

// If the image is too small to represent the entire document now then regenerate it
// TODO: Copy old image when incremental update is added.
if (img == null || img!!.height < height || img!!.width < config.width) {
Expand Down