From ededd39533df1bc972d336ebd08c1caa84c8cad7 Mon Sep 17 00:00:00 2001 From: a690700752 Date: Wed, 4 Jul 2018 22:23:36 +0800 Subject: [PATCH] Add smartcase and remove case sensitive. --- src/main/java/com/werfad/ConfigUI.form | 4 ++-- src/main/java/com/werfad/ConfigUI.java | 10 +++++----- src/main/kotlin/com/werfad/KJumpConfigurable.kt | 6 +++--- src/main/kotlin/com/werfad/UserConfig.kt | 4 ++-- src/main/kotlin/com/werfad/finder/Char1Finder.kt | 3 ++- src/main/kotlin/com/werfad/finder/Char2Finder.kt | 3 ++- src/main/kotlin/com/werfad/finder/Word1Finder.kt | 3 ++- src/main/resources/META-INF/plugin.xml | 2 +- 8 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/werfad/ConfigUI.form b/src/main/java/com/werfad/ConfigUI.form index 6c0035a..c14a85f 100644 --- a/src/main/java/com/werfad/ConfigUI.form +++ b/src/main/java/com/werfad/ConfigUI.form @@ -56,14 +56,14 @@ - + - + diff --git a/src/main/java/com/werfad/ConfigUI.java b/src/main/java/com/werfad/ConfigUI.java index 6b9995d..3b4e2a6 100644 --- a/src/main/java/com/werfad/ConfigUI.java +++ b/src/main/java/com/werfad/ConfigUI.java @@ -8,7 +8,7 @@ public class ConfigUI { private JTextField charactersTF; private JTextField fontColorTF; private JTextField bgTF; - private JCheckBox caseSensitiveCheckBox; + private JCheckBox smartcaseCheckBox; public JPanel getRootPanel() { return rootPanel; @@ -48,12 +48,12 @@ public void setBgColor(int c) { bgTF.setText(Integer.toHexString(c)); } - public Boolean getCaseSensitive() { - return caseSensitiveCheckBox.isSelected(); + public Boolean getSmartcase() { + return smartcaseCheckBox.isSelected(); } - public void setCaseSensitive(boolean caseSensitive) { - caseSensitiveCheckBox.setSelected(caseSensitive); + public void setSmartcase(boolean caseSensitive) { + smartcaseCheckBox.setSelected(caseSensitive); } } diff --git a/src/main/kotlin/com/werfad/KJumpConfigurable.kt b/src/main/kotlin/com/werfad/KJumpConfigurable.kt index bc5d577..85d700f 100644 --- a/src/main/kotlin/com/werfad/KJumpConfigurable.kt +++ b/src/main/kotlin/com/werfad/KJumpConfigurable.kt @@ -11,7 +11,7 @@ class KJumpConfigurable : Configurable { return ui.characters != config.characters || ui.fontColor != config.fontColor || ui.bgColor != config.bgColor - || ui.caseSensitive != config.caseSensitive + || ui.smartcase != config.smartcase } override fun getDisplayName(): String { @@ -26,7 +26,7 @@ class KJumpConfigurable : Configurable { config.bgColor = if (ui.bgColor == null) UserConfig.DEFAULT_BG_COLOR else ui.bgColor!! - config.caseSensitive = ui.caseSensitive + config.smartcase = ui.smartcase } override fun reset() { @@ -44,6 +44,6 @@ class KJumpConfigurable : Configurable { ui.characters = config.characters ui.setFontColor(config.fontColor) ui.setBgColor(config.bgColor) - ui.caseSensitive = config.caseSensitive + ui.smartcase = config.smartcase } } diff --git a/src/main/kotlin/com/werfad/UserConfig.kt b/src/main/kotlin/com/werfad/UserConfig.kt index 68ed754..5bf8295 100644 --- a/src/main/kotlin/com/werfad/UserConfig.kt +++ b/src/main/kotlin/com/werfad/UserConfig.kt @@ -22,13 +22,13 @@ class UserConfig : PersistentStateComponent { data class DataBean(var characters: String = DEFAULT_CHARACTERS, var fontColor: Int = DEFAULT_FONT_COLOR, var bgColor: Int = DEFAULT_BG_COLOR, - var caseSensitive: Boolean = DEFAULT_CASE_SENSITIVE) + var smartcase: Boolean = DEFAULT_SMARTCASE) companion object { const val DEFAULT_CHARACTERS = "abcdefghijklmnopqrstuvwxyz;" const val DEFAULT_FONT_COLOR = 0xFFFFFF const val DEFAULT_BG_COLOR = 0x007ACC - const val DEFAULT_CASE_SENSITIVE = false + const val DEFAULT_SMARTCASE = true fun getInstance(): UserConfig { return ServiceManager.getService(UserConfig::class.java) diff --git a/src/main/kotlin/com/werfad/finder/Char1Finder.kt b/src/main/kotlin/com/werfad/finder/Char1Finder.kt index 0bdee7e..209458c 100644 --- a/src/main/kotlin/com/werfad/finder/Char1Finder.kt +++ b/src/main/kotlin/com/werfad/finder/Char1Finder.kt @@ -26,7 +26,8 @@ class Char1Finder : Finder { override fun input(e: Editor, c: Char, lastMarks: List): List { return when (state) { STATE_WAIT_SEARCH_CHAR -> { - val offsets = s.findAll(c, !config.caseSensitive) + val ignoreCase = config.smartcase && c.isLowerCase() + val offsets = s.findAll(c, ignoreCase) .map { it + visibleRange.startOffset } .sortedBy { Math.abs(it - e.caretModel.offset) } val tags = KeyTagsGenerator.createTagsTree(offsets.size) diff --git a/src/main/kotlin/com/werfad/finder/Char2Finder.kt b/src/main/kotlin/com/werfad/finder/Char2Finder.kt index f3ad207..fc22096 100644 --- a/src/main/kotlin/com/werfad/finder/Char2Finder.kt +++ b/src/main/kotlin/com/werfad/finder/Char2Finder.kt @@ -34,7 +34,8 @@ class Char2Finder : Finder { null } STATE_WAIT_SEARCH_CHAR2 -> { - val offsets = s.findAll("" + firstChar + c, !config.caseSensitive) + val ignoreCase = config.smartcase && firstChar.isLowerCase() && c.isLowerCase() + val offsets = s.findAll("" + firstChar + c, ignoreCase) .map { it + visibleRange.startOffset } .sortedBy { Math.abs(it - e.caretModel.offset) } val tags = KeyTagsGenerator.createTagsTree(offsets.size) diff --git a/src/main/kotlin/com/werfad/finder/Word1Finder.kt b/src/main/kotlin/com/werfad/finder/Word1Finder.kt index 2347f10..7da6f59 100644 --- a/src/main/kotlin/com/werfad/finder/Word1Finder.kt +++ b/src/main/kotlin/com/werfad/finder/Word1Finder.kt @@ -26,8 +26,9 @@ class Word1Finder : Finder { override fun input(e: Editor, c: Char, lastMarks: List): List { return when (state) { STATE_WAIT_SEARCH_CHAR -> { + val ignoreCase = config.smartcase && c.isLowerCase() var pattern = "\\b$c" - if (!config.caseSensitive) { + if (ignoreCase) { pattern = "(?i)$pattern"; } val offsets = s.findAllRegex(pattern) diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 71ca7da..eab183c 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -15,7 +15,7 @@ + * v0.0.5 add smartcase feature.
* v0.0.4 add user config for characters and colors.
* v0.0.3 add features: word0 jump, word1 jump, and line jump
* v0.0.2 compat with IntelliJ Platform Products