mirror of
https://github.com/chylex/IntelliJ-AceJump.git
synced 2025-04-09 17:15:43 +02:00
Merge pull request #358 from AlexPl292/jump_boundaries
Allow defining jump mode with boundaries
This commit is contained in:
commit
85163d4fb9
src
@ -34,6 +34,8 @@ class Session(private val editor: Editor) {
|
||||
private val listeners: MutableList<AceJumpListener> =
|
||||
ContainerUtil.createLockFreeCopyOnWriteList()
|
||||
|
||||
private var boundaries: Boundaries = defaultBoundaries
|
||||
|
||||
private companion object {
|
||||
private val defaultBoundaries
|
||||
get() = if (AceConfig.searchWholeFile) WHOLE_FILE else VISIBLE_ON_SCREEN
|
||||
@ -82,7 +84,7 @@ class Session(private val editor: Editor) {
|
||||
if (processor == null) {
|
||||
processor = SearchProcessor.fromChar(
|
||||
editor,
|
||||
charTyped, defaultBoundaries
|
||||
charTyped, boundaries
|
||||
).also { searchProcessor = it }
|
||||
} else if (!processor.type(charTyped, tagger)) {
|
||||
return
|
||||
@ -200,6 +202,12 @@ class Session(private val editor: Editor) {
|
||||
jumpMode = jumpModeTracker.toggle(newMode)
|
||||
}
|
||||
|
||||
@ExternalUsage
|
||||
fun toggleJumpMode(newMode: JumpMode, boundaries: Boundaries) {
|
||||
this.boundaries = this.boundaries.intersection(boundaries)
|
||||
jumpMode = jumpModeTracker.toggle(newMode)
|
||||
}
|
||||
|
||||
/**
|
||||
* See [TagVisitor.visitPrevious]. If there are no tags, nothing happens.
|
||||
*/
|
||||
|
@ -1,7 +1,12 @@
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import junit.framework.TestCase
|
||||
import org.acejump.boundaries.StandardBoundaries.*
|
||||
import org.acejump.search.Pattern.*
|
||||
import org.acejump.session.*
|
||||
import org.acejump.boundaries.Boundaries
|
||||
import org.acejump.boundaries.EditorOffsetCache
|
||||
import org.acejump.boundaries.StandardBoundaries.WHOLE_FILE
|
||||
import org.acejump.input.JumpMode
|
||||
import org.acejump.search.Pattern.ALL_WORDS
|
||||
import org.acejump.session.AceJumpListener
|
||||
import org.acejump.session.SessionManager
|
||||
import org.acejump.test.util.BaseTest
|
||||
|
||||
/**
|
||||
@ -46,4 +51,24 @@ class ExternalUsageTest: BaseTest() {
|
||||
|
||||
TestCase.assertEquals(8, session.tags.size)
|
||||
}
|
||||
|
||||
fun `test external jump with bounds`() {
|
||||
makeEditor("test word and word usage")
|
||||
|
||||
SessionManager.start(myFixture.editor)
|
||||
.toggleJumpMode(JumpMode.JUMP, object : Boundaries {
|
||||
override fun getOffsetRange(editor: Editor, cache: EditorOffsetCache): IntRange {
|
||||
return 14..18
|
||||
}
|
||||
|
||||
override fun isOffsetInside(editor: Editor, offset: Int, cache: EditorOffsetCache): Boolean {
|
||||
return offset in 14..18
|
||||
}
|
||||
})
|
||||
|
||||
typeAndWaitForResults("word")
|
||||
|
||||
TestCase.assertEquals(1, session.tags.size)
|
||||
TestCase.assertEquals(14, session.tags.single().value)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user