1
0
mirror of https://github.com/chylex/IntelliJ-AceJump.git synced 2024-11-24 23:42:46 +01:00

Compare commits

..

2 Commits

9 changed files with 27 additions and 13 deletions

View File

@ -8,7 +8,7 @@ plugins {
} }
group = "org.acejump" group = "org.acejump"
version = "chylex-25" version = "chylex-26"
repositories { repositories {
mavenCentral() mavenCentral()

View File

@ -20,6 +20,7 @@ class AceConfig : PersistentStateComponent<AceSettings> {
val layout get() = settings.layout val layout get() = settings.layout
val minQueryLength get() = settings.minQueryLength val minQueryLength get() = settings.minQueryLength
val invertUppercaseMode get() = settings.invertUppercaseMode
val editorFadeOpacity get() = settings.editorFadeOpacity val editorFadeOpacity get() = settings.editorFadeOpacity
val jumpModeColor get() = settings.jumpModeColor val jumpModeColor get() = settings.jumpModeColor
val tagForegroundColor1 get() = settings.tagForegroundColor1 val tagForegroundColor1 get() = settings.tagForegroundColor1

View File

@ -15,6 +15,7 @@ class AceConfigurable : Configurable {
panel.allowedChars != settings.allowedChars || panel.allowedChars != settings.allowedChars ||
panel.keyboardLayout != settings.layout || panel.keyboardLayout != settings.layout ||
panel.minQueryLengthInt != settings.minQueryLength || panel.minQueryLengthInt != settings.minQueryLength ||
panel.invertUppercaseMode != settings.invertUppercaseMode ||
panel.editorFadeOpacityPercent != settings.editorFadeOpacity || panel.editorFadeOpacityPercent != settings.editorFadeOpacity ||
panel.jumpModeColor != settings.jumpModeColor || panel.jumpModeColor != settings.jumpModeColor ||
panel.tagForegroundColor1 != settings.tagForegroundColor1 || panel.tagForegroundColor1 != settings.tagForegroundColor1 ||
@ -25,6 +26,7 @@ class AceConfigurable : Configurable {
settings.allowedChars = panel.allowedChars settings.allowedChars = panel.allowedChars
settings.layout = panel.keyboardLayout settings.layout = panel.keyboardLayout
settings.minQueryLength = panel.minQueryLengthInt ?: settings.minQueryLength settings.minQueryLength = panel.minQueryLengthInt ?: settings.minQueryLength
settings.invertUppercaseMode = panel.invertUppercaseMode
settings.editorFadeOpacity = panel.editorFadeOpacityPercent settings.editorFadeOpacity = panel.editorFadeOpacityPercent
panel.jumpModeColor?.let { settings.jumpModeColor = it } panel.jumpModeColor?.let { settings.jumpModeColor = it }
panel.tagForegroundColor1?.let { settings.tagForegroundColor1 = it } panel.tagForegroundColor1?.let { settings.tagForegroundColor1 = it }

View File

@ -8,6 +8,7 @@ import java.awt.Color
data class AceSettings( data class AceSettings(
var layout: KeyLayout = QWERTY, var layout: KeyLayout = QWERTY,
var allowedChars: String = layout.allChars, var allowedChars: String = layout.allChars,
var invertUppercaseMode: Boolean = false,
var minQueryLength: Int = 1, var minQueryLength: Int = 1,
var editorFadeOpacity: Int = 70, var editorFadeOpacity: Int = 70,

View File

@ -2,6 +2,7 @@ package org.acejump.config
import com.intellij.openapi.ui.ComboBox import com.intellij.openapi.ui.ComboBox
import com.intellij.ui.ColorPanel import com.intellij.ui.ColorPanel
import com.intellij.ui.components.JBCheckBox
import com.intellij.ui.components.JBSlider import com.intellij.ui.components.JBSlider
import com.intellij.ui.components.JBTextArea import com.intellij.ui.components.JBTextArea
import com.intellij.ui.components.JBTextField import com.intellij.ui.components.JBTextField
@ -30,6 +31,7 @@ internal class AceSettingsPanel {
private val keyboardLayoutCombo = ComboBox<KeyLayout>() private val keyboardLayoutCombo = ComboBox<KeyLayout>()
private val keyboardLayoutArea = JBTextArea().apply { isEditable = false } private val keyboardLayoutArea = JBTextArea().apply { isEditable = false }
private val minQueryLengthField = JBTextField() private val minQueryLengthField = JBTextField()
private val invertUppercaseModeCheckBox = JBCheckBox("Invert uppercase mode")
private val editorFadeOpacitySlider = JBSlider(0, 10).apply { private val editorFadeOpacitySlider = JBSlider(0, 10).apply {
labelTable = Hashtable((0..10).associateWith { JLabel("${it * 10}") }) labelTable = Hashtable((0..10).associateWith { JLabel("${it * 10}") })
paintTrack = true paintTrack = true
@ -59,6 +61,7 @@ internal class AceSettingsPanel {
group("Behavior") { group("Behavior") {
row("Minimum typed characters (1-10):") { cell(minQueryLengthField).columns(COLUMNS_SHORT) } row("Minimum typed characters (1-10):") { cell(minQueryLengthField).columns(COLUMNS_SHORT) }
row { cell(invertUppercaseModeCheckBox) }
} }
group("Colors") { group("Colors") {
@ -83,6 +86,7 @@ internal class AceSettingsPanel {
internal var keyboardLayout by keyboardLayoutCombo internal var keyboardLayout by keyboardLayoutCombo
internal var keyChars by keyboardLayoutArea internal var keyChars by keyboardLayoutArea
internal var minQueryLength by minQueryLengthField internal var minQueryLength by minQueryLengthField
internal var invertUppercaseMode by invertUppercaseModeCheckBox
internal var editorFadeOpacity by editorFadeOpacitySlider internal var editorFadeOpacity by editorFadeOpacitySlider
internal var jumpModeColor by jumpModeColorWheel internal var jumpModeColor by jumpModeColorWheel
internal var tagForegroundColor1 by tagForeground1ColorWheel internal var tagForegroundColor1 by tagForeground1ColorWheel
@ -101,6 +105,7 @@ internal class AceSettingsPanel {
allowedChars = settings.allowedChars allowedChars = settings.allowedChars
keyboardLayout = settings.layout keyboardLayout = settings.layout
minQueryLength = settings.minQueryLength.toString() minQueryLength = settings.minQueryLength.toString()
invertUppercaseMode = settings.invertUppercaseMode
editorFadeOpacityPercent = settings.editorFadeOpacity editorFadeOpacityPercent = settings.editorFadeOpacity
jumpModeColor = settings.jumpModeColor jumpModeColor = settings.jumpModeColor
tagForegroundColor1 = settings.tagForegroundColor1 tagForegroundColor1 = settings.tagForegroundColor1

View File

@ -12,9 +12,9 @@ import org.acejump.matchesAt
/** /**
* Searches editor text for matches of a [SearchQuery], and updates previous results when the user [refineQuery]s a character. * 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>) { class SearchProcessor private constructor(query: SearchQuery, val boundaries: Boundaries, val invertUppercaseMode: Boolean, private val results: MutableMap<Editor, IntArrayList>) {
internal constructor(editors: List<Editor>, query: SearchQuery, boundaries: Boundaries) : this(query, boundaries, mutableMapOf()) { internal constructor(editors: List<Editor>, query: SearchQuery, boundaries: Boundaries, invertUppercaseMode: Boolean) : this(query, boundaries, invertUppercaseMode, mutableMapOf()) {
val regex = query.toRegex() val regex = query.toRegex(invertUppercaseMode)
if (regex != null) { if (regex != null) {
for (editor in editors) { for (editor in editors) {

View File

@ -21,7 +21,7 @@ internal sealed class SearchQuery {
/** /**
* Converts the query into a regular expression to find the initial matches. * Converts the query into a regular expression to find the initial matches.
*/ */
abstract fun toRegex(): Regex? abstract fun toRegex(invertUppercaseMode: Boolean): Regex?
/** /**
* Searches for all occurrences of a literal text query. * Searches for all occurrences of a literal text query.
@ -41,14 +41,14 @@ internal sealed class SearchQuery {
return text.countMatchingCharacters(offset, rawText) return text.countMatchingCharacters(offset, rawText)
} }
override fun toRegex(): Regex { override fun toRegex(invertUppercaseMode: Boolean): Regex {
val firstChar = rawText.first() val firstChar = rawText.first()
val pattern = if (firstChar.isLowerCase()) { val pattern = if (firstChar.isLowerCase() xor invertUppercaseMode) {
val fullPattern = Regex.escape(rawText) val fullPattern = Regex.escape(rawText)
"(?i)$fullPattern" "(?i)$fullPattern"
} }
else { else {
val firstCharUppercasePattern = Regex.escape(firstChar.toString()) val firstCharUppercasePattern = Regex.escape(firstChar.uppercase())
val firstCharLowercasePattern = Regex.escape(firstChar.lowercase()) val firstCharLowercasePattern = Regex.escape(firstChar.lowercase())
val remainingPattern = if (rawText.length > 1) Regex.escape(rawText.drop(1)) else "" val remainingPattern = if (rawText.length > 1) Regex.escape(rawText.drop(1)) else ""
"(?:$firstCharUppercasePattern|(?<![a-zA-Z])$firstCharLowercasePattern)$remainingPattern" "(?:$firstCharUppercasePattern|(?<![a-zA-Z])$firstCharLowercasePattern)$remainingPattern"
@ -72,7 +72,7 @@ internal sealed class SearchQuery {
return 1 return 1
} }
override fun toRegex(): Regex { override fun toRegex(invertUppercaseMode: Boolean): Regex {
return Regex(pattern, setOf(RegexOption.MULTILINE, RegexOption.IGNORE_CASE)) return Regex(pattern, setOf(RegexOption.MULTILINE, RegexOption.IGNORE_CASE))
} }
} }

View File

@ -113,7 +113,7 @@ class Session(private val mainEditor: Editor, private val jumpEditors: List<Edit
} }
setMode(mode()) setMode(mode())
state = SessionState.WaitForKey(actions, jumpEditors, defaultBoundary) state = SessionState.WaitForKey(actions, jumpEditors, defaultBoundary, AceConfig.invertUppercaseMode)
} }
/** /**
@ -128,7 +128,7 @@ class Session(private val mainEditor: Editor, private val jumpEditors: List<Edit
canvas.setMarkers(emptyList()) canvas.setMarkers(emptyList())
} }
val processor = SearchProcessor(jumpEditors, SearchQuery.RegularExpression(pattern.regex), defaultBoundary) val processor = SearchProcessor(jumpEditors, SearchQuery.RegularExpression(pattern.regex), defaultBoundary, AceConfig.invertUppercaseMode)
textHighlighter.renderOccurrences(processor.resultsCopy, processor.query) textHighlighter.renderOccurrences(processor.resultsCopy, processor.query)
state = SessionState.SelectTag(actions, jumpEditors, processor) state = SessionState.SelectTag(actions, jumpEditors, processor)

View File

@ -16,9 +16,10 @@ sealed interface SessionState {
private val actions: SessionActions, private val actions: SessionActions,
private val jumpEditors: List<Editor>, private val jumpEditors: List<Editor>,
private val defaultBoundary: Boundaries, private val defaultBoundary: Boundaries,
private val invertUppercaseMode: Boolean,
) : SessionState { ) : SessionState {
override fun type(char: Char): TypeResult { override fun type(char: Char): TypeResult {
val searchProcessor = SearchProcessor(jumpEditors, SearchQuery.Literal(char.toString()), defaultBoundary) val searchProcessor = SearchProcessor(jumpEditors, SearchQuery.Literal(char.toString()), defaultBoundary, invertUppercaseMode)
return if (searchProcessor.isQueryFinished) { return if (searchProcessor.isQueryFinished) {
TypeResult.ChangeState(SelectTag(actions, jumpEditors, searchProcessor)) TypeResult.ChangeState(SelectTag(actions, jumpEditors, searchProcessor))
@ -72,10 +73,14 @@ sealed interface SessionState {
else -> searchProcessor.boundaries else -> searchProcessor.boundaries
} }
val newSearchProcessor = SearchProcessor(jumpEditors, query, newBoundaries) val newSearchProcessor = SearchProcessor(jumpEditors, query, newBoundaries, searchProcessor.invertUppercaseMode)
return TypeResult.ChangeState(SelectTag(actions, jumpEditors, newSearchProcessor)) return TypeResult.ChangeState(SelectTag(actions, jumpEditors, newSearchProcessor))
} }
} }
else if (char == '\n') {
val newSearchProcessor = SearchProcessor(jumpEditors, searchProcessor.query, searchProcessor.boundaries, !searchProcessor.invertUppercaseMode)
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(AceConfig.layout.characterRemapping.getOrDefault(char, char))) {
is TaggingResult.Nothing -> TypeResult.Nothing is TaggingResult.Nothing -> TypeResult.Nothing