mirror of
https://github.com/chylex/IntelliJ-AceJump.git
synced 2024-11-25 17:42:46 +01:00
Compare commits
No commits in common. "1f76a8bd25b16b662e1cae515b3fc7d729f3c3a4" and "575283b2beab09dbcb4ace942323551e0dabb5e5" have entirely different histories.
1f76a8bd25
...
575283b2be
@ -8,7 +8,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "org.acejump"
|
||||
version = "chylex-19"
|
||||
version = "chylex-18"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
@ -11,8 +11,18 @@ import org.acejump.matchesAt
|
||||
/**
|
||||
* Searches editor text for matches of a [SearchQuery], and updates previous results when the user [refineQuery]s a character.
|
||||
*/
|
||||
class SearchProcessor private constructor(query: SearchQuery, val boundaries: Boundaries, private val results: MutableMap<Editor, IntArrayList>) {
|
||||
internal constructor(editors: List<Editor>, query: SearchQuery, boundaries: Boundaries) : this(query, boundaries, mutableMapOf()) {
|
||||
class SearchProcessor private constructor(query: SearchQuery, private val results: MutableMap<Editor, IntArrayList>) {
|
||||
companion object {
|
||||
fun fromString(editors: List<Editor>, query: String, boundaries: Boundaries): SearchProcessor {
|
||||
return SearchProcessor(editors, SearchQuery.Literal(query), boundaries)
|
||||
}
|
||||
|
||||
fun fromRegex(editors: List<Editor>, pattern: String, boundaries: Boundaries): SearchProcessor {
|
||||
return SearchProcessor(editors, SearchQuery.RegularExpression(pattern), boundaries)
|
||||
}
|
||||
}
|
||||
|
||||
private constructor(editors: List<Editor>, query: SearchQuery, boundaries: Boundaries) : this(query, mutableMapOf()) {
|
||||
val regex = query.toRegex()
|
||||
|
||||
if (regex != null) {
|
||||
@ -55,7 +65,7 @@ class SearchProcessor private constructor(query: SearchQuery, val boundaries: Bo
|
||||
return true
|
||||
}
|
||||
else {
|
||||
query = query.refine(char)
|
||||
query = SearchQuery.Literal(query.rawText + char)
|
||||
removeObsoleteResults()
|
||||
return isQueryFinished
|
||||
}
|
||||
|
@ -8,11 +8,6 @@ import org.acejump.countMatchingCharacters
|
||||
internal sealed class SearchQuery {
|
||||
abstract val rawText: String
|
||||
|
||||
/**
|
||||
* Returns a new query with the given character appended.
|
||||
*/
|
||||
abstract fun refine(char: Char): SearchQuery
|
||||
|
||||
/**
|
||||
* Returns how many characters the search occurrence highlight should cover.
|
||||
*/
|
||||
@ -24,42 +19,29 @@ internal sealed class SearchQuery {
|
||||
abstract fun toRegex(): Regex?
|
||||
|
||||
/**
|
||||
* Searches for all occurrences of a literal text query.
|
||||
* If the first character of the query is lowercase, then the entire query will be case-insensitive,
|
||||
* and only beginnings of words and camel humps will be matched.
|
||||
* Searches for all occurrences of a literal text query. If the first character of the query is lowercase, then the entire query will be
|
||||
* case-insensitive.
|
||||
*
|
||||
* Each occurrence must either match the entire query, or match the query up to a point so that the rest of the query matches the
|
||||
* beginning of a tag at the location of the occurrence.
|
||||
*/
|
||||
class Literal(override val rawText: String, val excludeMiddlesOfWords: Boolean) : SearchQuery() {
|
||||
class Literal(override val rawText: String) : SearchQuery() {
|
||||
init {
|
||||
require(rawText.isNotEmpty())
|
||||
}
|
||||
|
||||
override fun refine(char: Char): SearchQuery {
|
||||
return Literal(rawText + char, excludeMiddlesOfWords)
|
||||
}
|
||||
|
||||
override fun getHighlightLength(text: CharSequence, offset: Int): Int {
|
||||
return text.countMatchingCharacters(offset, rawText)
|
||||
}
|
||||
|
||||
override fun toRegex(): Regex {
|
||||
val firstChar = rawText.first()
|
||||
val pattern = if (firstChar.isLowerCase()) {
|
||||
if (excludeMiddlesOfWords) {
|
||||
val firstCharUppercasePattern = Regex.escape(firstChar.uppercaseChar().toString())
|
||||
val firstCharPattern = Regex.escape(firstChar.toString())
|
||||
val remainingPattern = if (rawText.length > 1) Regex.escape(rawText.drop(1)) else ""
|
||||
"(?:$firstCharUppercasePattern|(?<![a-zA-Z])$firstCharPattern)$remainingPattern"
|
||||
}
|
||||
else {
|
||||
val fullPattern = Regex.escape(rawText)
|
||||
"(?i)$fullPattern"
|
||||
}
|
||||
}
|
||||
else {
|
||||
Regex.escape(rawText)
|
||||
val options = mutableSetOf(RegexOption.MULTILINE)
|
||||
|
||||
if (rawText.first().isLowerCase()) {
|
||||
options.add(RegexOption.IGNORE_CASE)
|
||||
}
|
||||
|
||||
return Regex(pattern, setOf(RegexOption.MULTILINE))
|
||||
return Regex(Regex.escape(rawText), options)
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,10 +51,6 @@ internal sealed class SearchQuery {
|
||||
class RegularExpression(private val pattern: String) : SearchQuery() {
|
||||
override val rawText = ""
|
||||
|
||||
override fun refine(char: Char): SearchQuery {
|
||||
return Literal(char.toString(), excludeMiddlesOfWords = false)
|
||||
}
|
||||
|
||||
override fun getHighlightLength(text: CharSequence, offset: Int): Int {
|
||||
return 1
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ class Session(private val mainEditor: Editor, private val jumpEditors: List<Edit
|
||||
val state = state ?: return
|
||||
|
||||
editorSettings.startEditing(editor)
|
||||
val result = mode.type(state, charTyped, acceptedTag)
|
||||
val result = mode.type(state, AceConfig.layout.characterRemapping.getOrDefault(charTyped, charTyped), acceptedTag)
|
||||
editorSettings.stopEditing(editor)
|
||||
|
||||
when (result) {
|
||||
@ -128,7 +128,7 @@ class Session(private val mainEditor: Editor, private val jumpEditors: List<Edit
|
||||
canvas.setMarkers(emptyList())
|
||||
}
|
||||
|
||||
val processor = SearchProcessor(jumpEditors, SearchQuery.RegularExpression(pattern.regex), defaultBoundary)
|
||||
val processor = SearchProcessor.fromRegex(jumpEditors, pattern.regex, defaultBoundary)
|
||||
textHighlighter.renderOccurrences(processor.resultsCopy, processor.query)
|
||||
|
||||
state = SessionState.SelectTag(actions, jumpEditors, processor)
|
||||
|
@ -2,9 +2,7 @@ package org.acejump.session
|
||||
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import org.acejump.boundaries.Boundaries
|
||||
import org.acejump.config.AceConfig
|
||||
import org.acejump.search.SearchProcessor
|
||||
import org.acejump.search.SearchQuery
|
||||
import org.acejump.search.Tagger
|
||||
import org.acejump.search.TaggingResult
|
||||
|
||||
@ -17,7 +15,7 @@ sealed interface SessionState {
|
||||
private val defaultBoundary: Boundaries,
|
||||
) : SessionState {
|
||||
override fun type(char: Char): TypeResult {
|
||||
val searchProcessor = SearchProcessor(jumpEditors, SearchQuery.Literal(char.toString(), excludeMiddlesOfWords = true), defaultBoundary)
|
||||
val searchProcessor = SearchProcessor.fromString(jumpEditors, char.toString(), defaultBoundary)
|
||||
|
||||
return if (searchProcessor.isQueryFinished) {
|
||||
TypeResult.ChangeState(SelectTag(actions, jumpEditors, searchProcessor))
|
||||
@ -51,8 +49,8 @@ sealed interface SessionState {
|
||||
|
||||
class SelectTag internal constructor(
|
||||
private val actions: SessionActions,
|
||||
private val jumpEditors: List<Editor>,
|
||||
private val searchProcessor: SearchProcessor,
|
||||
jumpEditors: List<Editor>,
|
||||
searchProcessor: SearchProcessor,
|
||||
) : SessionState {
|
||||
private val tagger = Tagger(jumpEditors, searchProcessor.resultsCopy)
|
||||
|
||||
@ -61,16 +59,7 @@ sealed interface SessionState {
|
||||
}
|
||||
|
||||
override fun type(char: Char): TypeResult {
|
||||
if (char == ' ') {
|
||||
val query = searchProcessor.query
|
||||
if (query is SearchQuery.Literal && query.excludeMiddlesOfWords) {
|
||||
val newQuery = SearchQuery.Literal(query.rawText, excludeMiddlesOfWords = false)
|
||||
val newSearchProcessor = SearchProcessor(jumpEditors, newQuery, searchProcessor.boundaries)
|
||||
return TypeResult.ChangeState(SelectTag(actions, jumpEditors, newSearchProcessor))
|
||||
}
|
||||
}
|
||||
|
||||
return when (val result = tagger.type(AceConfig.layout.characterRemapping.getOrDefault(char, char))) {
|
||||
return when (val result = tagger.type(char)) {
|
||||
is TaggingResult.Nothing -> TypeResult.Nothing
|
||||
is TaggingResult.Accept -> TypeResult.AcceptTag(result.tag)
|
||||
is TaggingResult.Mark -> {
|
||||
|
Loading…
Reference in New Issue
Block a user