Skip to content

Commit

Permalink
fix test and add lazy loading
Browse files Browse the repository at this point in the history
  • Loading branch information
breandan committed Nov 14, 2018
1 parent 53f3e5d commit d911528
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 16 deletions.
8 changes: 5 additions & 3 deletions src/main/kotlin/org/acejump/config/AceConfig.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.acejump.config

import com.intellij.openapi.components.*
import com.intellij.openapi.components.PersistentStateComponent
import com.intellij.openapi.components.State
import com.intellij.openapi.components.Storage
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.options.Configurable

Expand All @@ -11,7 +13,7 @@ import com.intellij.openapi.options.Configurable
@State(name = "AceConfig", storages = [(Storage("AceJump.xml"))])
object AceConfig : Configurable, PersistentStateComponent<AceSettings> {
private val logger = Logger.getInstance(AceConfig::class.java)
var settings: AceSettings = AceSettings()
var settings = AceSettings()

override fun getState() = settings

Expand All @@ -20,7 +22,7 @@ object AceConfig : Configurable, PersistentStateComponent<AceSettings> {
settings = state
}

private val panel = AceSettingsPanel()
private val panel by lazy { AceSettingsPanel() }

override fun getDisplayName() = "AceJump"

Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/org/acejump/config/AceSettingsPanel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class AceSettingsPanel {
}
}

// https://github.com/JetBrains/intellij-community/blob/master/platform/platform-impl/src/com/intellij/ui/layout/readme.md
internal val rootPanel: JPanel = panel {
fun Cell.short(component: JComponent) = component(growPolicy = SHORT_TEXT)
fun Cell.medium(component: JComponent) = component(growPolicy = MEDIUM_TEXT)
Expand Down
19 changes: 12 additions & 7 deletions src/main/kotlin/org/acejump/search/AceUtil.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package org.acejump.search

import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.*
import com.intellij.openapi.fileEditor.*
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.LogicalPosition
import com.intellij.openapi.editor.VisualPosition
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.fileEditor.TextEditor
import com.intellij.openapi.project.ProjectManager
import com.intellij.ui.awt.RelativePoint
import org.acejump.view.Model.MAX_TAG_RESULTS
import org.acejump.view.Model.viewBounds
import java.awt.Point
import java.util.*
import javax.swing.JComponent
import kotlin.math.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

interface Resettable {
fun reset()
Expand Down Expand Up @@ -167,16 +173,15 @@ fun Editor.getLineCount() = document.run {
/**
* Gets the actual number of characters in the file
*
* @param includeEndNewLine True include newline
* @param countNewLines True include newline
*
* @return The file's character count
*/

fun Editor.getFileSize(includeEndNewLine: Boolean = false): Int {
fun Editor.getFileSize(countNewLines: Boolean = false): Int {
val len = document.textLength
val doc = document.charsSequence
return if (includeEndNewLine || len == 0 || doc[len - 1] != '\n') len
else len - 1
return if (countNewLines || len == 0 || doc[len - 1] != '\n') len else len - 1
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/main/kotlin/org/acejump/view/Canvas.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ package org.acejump.view
import com.intellij.openapi.application.ApplicationInfo
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.editor.Editor
import org.acejump.search.*
import org.acejump.search.Resettable
import org.acejump.search.getView
import org.acejump.search.runLater
import org.acejump.view.Model.fontWidth
import org.acejump.view.Model.viewBounds
import java.awt.*
import java.awt.Graphics
import java.awt.Graphics2D
import java.awt.Point
import javax.swing.JComponent
import javax.swing.SwingUtilities.convertPoint

Expand Down
9 changes: 7 additions & 2 deletions src/main/kotlin/org/acejump/view/Marker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import org.acejump.view.Model.fontHeight
import org.acejump.view.Model.fontWidth
import org.acejump.view.Model.rectHeight
import org.acejump.view.Model.rectVOffset
import java.awt.*
import java.awt.AlphaComposite.SRC_OVER
import java.awt.AlphaComposite.getInstance
import java.awt.Graphics
import java.awt.Graphics2D
import java.awt.Point
import java.awt.RenderingHints.KEY_ANTIALIASING
import java.awt.RenderingHints.VALUE_ANTIALIAS_ON
import org.acejump.view.Model.editorText as text
Expand Down Expand Up @@ -84,7 +86,10 @@ class Marker : CustomHighlighterRenderer {
}
}

// Called by IntelliJ Platform (as a CustomHighlightRenderer)
/**
* Called by IntelliJ Platform as a [CustomHighlighterRenderer]
*/

override fun paint(editor: Editor, highlight: RangeHighlighter, g: Graphics) =
(g as Graphics2D).highlightEditorText()

Expand Down
6 changes: 4 additions & 2 deletions src/test/kotlin/AceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ import com.intellij.testFramework.EditorActionTestCase
class AceTest : EditorActionTestCase() {
override fun getActionId() = "AceAction"

fun testSomething() {} // Why doesn't this work?
}
fun testSomething() {
assert(true)
}
}

0 comments on commit d911528

Please sign in to comment.