1
0
mirror of https://github.com/chylex/IntelliJ-AceJump.git synced 2025-04-24 06:15:43 +02:00

[WIP] Simplify tags by only tagging if the search query has at 2 or more alnum characters (or other symbols)

This commit is contained in:
chylex 2021-01-16 01:14:54 +01:00
parent 752e661bb7
commit 49dd8ddaf6
2 changed files with 14 additions and 3 deletions
src/main/kotlin/org/acejump
search
session

View File

@ -22,6 +22,9 @@ import kotlin.collections.component2
class Tagger(private val editor: Editor) {
private var tagMap = HashBiMap.create<String, Int>()
val hasTags
get() = tagMap.isNotEmpty()
@ExternalUsage
internal val tags
get() = tagMap.map { SimpleImmutableEntry(it.key, it.value) }.sortedBy { it.value }

View File

@ -55,6 +55,7 @@ class Session(private val editor: Editor) {
EditorKeyListener.attach(editor, object : TypedActionHandler {
override fun execute(editor: Editor, charTyped: Char, context: DataContext) {
val state = state ?: return
val hadTags = tagger.hasTags
editorSettings.startEditing(editor)
val result = mode.type(state, charTyped, acceptedTag)
@ -63,7 +64,7 @@ class Session(private val editor: Editor) {
when (result) {
TypeResult.Nothing -> updateHint()
TypeResult.RestartSearch -> restart().also { this@Session.state = SessionState(editor, tagger); updateHint() }
is TypeResult.UpdateResults -> updateSearch(result.processor)
is TypeResult.UpdateResults -> updateSearch(result.processor, markImmediately = hadTags)
is TypeResult.ChangeMode -> setMode(result.mode)
TypeResult.EndSession -> end()
}
@ -75,10 +76,15 @@ class Session(private val editor: Editor) {
* Updates text highlights and tag markers according to the current search state. Dispatches jumps if the search query matches a tag.
* If all tags are outside view, scrolls to the closest one.
*/
private fun updateSearch(processor: SearchProcessor) {
private fun updateSearch(processor: SearchProcessor, markImmediately: Boolean) {
val query = processor.query
val results = processor.results
if (query is SearchQuery.Literal && !markImmediately && query.rawText.let { it.length < 2 && it.all(Char::isLetterOrDigit) }) {
textHighlighter.renderOccurrences(results, query)
return
}
when (val result = tagger.update(query, results.clone())) {
is TaggingResult.Accept -> {
val offset = result.offset
@ -148,7 +154,9 @@ class Session(private val editor: Editor) {
setMode(JumpMode())
tagger = Tagger(editor)
tagCanvas.setMarkers(emptyList(), isRegex = true)
updateSearch(SearchProcessor.fromRegex(editor, pattern, boundaries).also { state = SessionState(editor, tagger, it) })
val processor = SearchProcessor.fromRegex(editor, pattern, boundaries).also { state = SessionState(editor, tagger, it) }
updateSearch(processor, markImmediately = true)
}
/**