Skip to content

Commit

Permalink
Fix arrows with line numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
romainguy committed May 3, 2024
1 parent 8fab81c commit da90411
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
15 changes: 10 additions & 5 deletions src/jvmMain/kotlin/dev/romainguy/kotlin/explorer/CodeTextArea.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ open class CodeTextArea(
private var jumpOffsets: JumpOffsets? = null
private var fullText = ""

var presentationMode: Boolean = false

init {
addCaretListener(::caretUpdate)
}
Expand All @@ -59,7 +57,7 @@ open class CodeTextArea(
override fun paintComponent(g: Graphics?) {
super.paintComponent(g)
jumpOffsets?.let { jump ->
val scale = if (presentationMode) 2 else 1
val scale = if (explorerState.presentationMode) 2 else 1
val padding = 6 * scale
val triangleSize = 8 * scale

Expand All @@ -69,10 +67,17 @@ open class CodeTextArea(
val x1 = bounds1.x.toInt() - padding
val y1 = (bounds1.y + lineHeight / 2).toInt()

val x2 = bounds2.x.toInt() - padding
val delta = jump.dst - getLineStartOffset(getLineOfOffset(jump.dst))
val endPadding = if (explorerState.showLineNumbers && delta < 4) 2 else padding

val x2 = bounds2.x.toInt() - endPadding
val y2 = (bounds2.y + lineHeight / 2).toInt()

val x0 = modelToView2D(4).x.toInt()
val x0 = if (explorerState.showLineNumbers) {
modelToView2D(minOf(0, jump.dst - 4)).x.toInt() + padding
} else {
modelToView2D(6).x.toInt()
}

val g2 = g as Graphics2D
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,6 @@ private fun Settings(
private fun RSyntaxTextArea.updateStyle(explorerState: ExplorerState) {
val presentation = explorerState.presentationMode
font = font.deriveFont(if (presentation) FontSizePresentationMode else FontSizeEditingMode)
if (this is CodeTextArea) {
presentationMode = presentation
}
}

private fun updateTextArea(textArea: RSyntaxTextArea, text: String) {
Expand Down

0 comments on commit da90411

Please sign in to comment.