-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3cc566f
commit dc5a11b
Showing
5 changed files
with
70 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.werfad.finder | ||
|
||
import com.intellij.openapi.editor.Editor | ||
import com.intellij.openapi.util.TextRange | ||
import com.werfad.DEFAULT_TAGS_KEYMAP | ||
import com.werfad.KeyTagsGenerator | ||
import com.werfad.Mark | ||
import com.werfad.utils.findAllRegex | ||
|
||
class Word1Finder : Finder { | ||
private val STATE_WAIT_SEARCH_CHAR = 0 | ||
private val STATE_WAIT_KEY = 1 | ||
private var state = STATE_WAIT_SEARCH_CHAR | ||
|
||
private lateinit var s: String | ||
private lateinit var visibleRange: TextRange | ||
|
||
override fun start(e: Editor, s: String, visibleRange: TextRange): List<Mark>? { | ||
this.s = s | ||
this.visibleRange = visibleRange | ||
state = STATE_WAIT_SEARCH_CHAR | ||
return null | ||
} | ||
|
||
override fun input(e: Editor, c: Char, lastMarks: List<Mark>): List<Mark> { | ||
return when (state) { | ||
STATE_WAIT_SEARCH_CHAR -> { | ||
val offsets = s.findAllRegex("\\b\\w") | ||
.filter { s[it] == c } | ||
.map { it + visibleRange.startOffset } | ||
.sortedBy { Math.abs(it - e.caretModel.offset) } | ||
val tags = KeyTagsGenerator.createTagsTree(offsets.size, DEFAULT_TAGS_KEYMAP) | ||
state = STATE_WAIT_KEY | ||
offsets.mapIndexed { index, offset -> | ||
Mark(tags[index], offset) | ||
} | ||
} | ||
STATE_WAIT_KEY -> matchInputAndCreateMarks(c, lastMarks) | ||
else -> throw RuntimeException("Impossible.") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters