Skip to content

Commit

Permalink
Do not assign tags inside folded regions
Browse files Browse the repository at this point in the history
  • Loading branch information
chylex committed Jan 1, 2024
1 parent c2e672f commit d0ead7d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/main/kotlin/org/acejump/search/Solver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.acejump.immutableText
import org.acejump.input.KeyLayoutCache
import org.acejump.isWordPart
import org.acejump.wordEndPlus
import java.util.*
import java.util.IdentityHashMap
import kotlin.math.max

/*
Expand Down Expand Up @@ -89,6 +89,10 @@ internal class Solver private constructor(
while (iter.hasNext()) {
val site = iter.nextInt()

if (editor.foldingModel.isOffsetCollapsed(site)) {
continue
}

for ((firstLetter, tags) in tagsByFirstLetter.entries) {
if (canTagBeginWithChar(editor, site, firstLetter)) {
for (tag in tags) {
Expand Down
5 changes: 4 additions & 1 deletion src/main/kotlin/org/acejump/search/Tag.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.acejump.search

import com.intellij.openapi.editor.Editor
import org.acejump.getView

data class Tag(val editor: Editor, val offset: Int)
data class Tag(val editor: Editor, val offset: Int) {
fun isVisible() = offset in editor.getView() && !editor.foldingModel.isOffsetCollapsed(offset)
}
2 changes: 1 addition & 1 deletion src/main/kotlin/org/acejump/search/Tagger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ internal class Tagger(private val editors: List<Editor>) {
tagPortion.isNotEmpty()
&& label.startsWith(tagPortion, ignoreCase = true)
&& isTagCompatibleWithQuery(label, tag, query)
&& tag.offset in tag.editor.getView()
&& tag.isVisible()
}

private fun removeResultsWithOverlappingTags(editor: Editor, offsets: IntList) {
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/org/acejump/view/TagCanvas.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ internal class TagCanvas(private val editor: Editor): JComponent(), CaretListene

val cache = EditorOffsetCache.new()
val viewRange = VISIBLE_ON_SCREEN.getOffsetRange(editor, cache)
val foldingModel = editor.foldingModel
val occupied = mutableListOf<Rectangle>()

// If there is a tag at the caret location, prioritize its rendering over
Expand All @@ -82,8 +83,9 @@ internal class TagCanvas(private val editor: Editor): JComponent(), CaretListene
val caretMarker = markers.find { it.offsetL == caretOffset || it.offsetR == caretOffset }
caretMarker?.paint(g, editor, cache, font, occupied)

for (marker in markers)
if (marker.isOffsetInRange(viewRange) && marker !== caretMarker)
for (marker in markers) {
if (marker.isOffsetInRange(viewRange) && !foldingModel.isOffsetCollapsed(marker.offsetL) && marker !== caretMarker)
marker.paint(g, editor, cache, font, occupied)
}
}
}

0 comments on commit d0ead7d

Please sign in to comment.