Skip to content

Commit

Permalink
Add smartcase and remove case sensitive.
Browse files Browse the repository at this point in the history
  • Loading branch information
a690700752 committed Jul 4, 2018
1 parent 1051afa commit ededd39
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/werfad/ConfigUI.form
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@
</constraints>
<properties/>
</component>
<component id="68164" class="javax.swing.JCheckBox" binding="caseSensitiveCheckBox" default-binding="true">
<component id="68164" class="javax.swing.JCheckBox" binding="smartcaseCheckBox">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<enabled value="true"/>
<selected value="false"/>
<text value="Case sensitive"/>
<text value="Smartcase"/>
</properties>
</component>
<vspacer id="af8c4">
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/werfad/ConfigUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

6 changes: 3 additions & 3 deletions src/main/kotlin/com/werfad/KJumpConfigurable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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() {
Expand All @@ -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
}
}
4 changes: 2 additions & 2 deletions src/main/kotlin/com/werfad/UserConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ class UserConfig : PersistentStateComponent<UserConfig.DataBean> {
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)
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/com/werfad/finder/Char1Finder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class Char1Finder : Finder {
override fun input(e: Editor, c: Char, lastMarks: List<Mark>): List<Mark> {
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)
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/com/werfad/finder/Char2Finder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/com/werfad/finder/Word1Finder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class Word1Finder : Finder {
override fun input(e: Editor, c: Char, lastMarks: List<Mark>): List<Mark> {
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)
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


<change-notes><![CDATA[
* v0.0.5 add case sensitive and configuration item. <br/>
* v0.0.5 add smartcase feature. <br/>
* v0.0.4 add user config for characters and colors. <br/>
* v0.0.3 add features: word0 jump, word1 jump, and line jump<br>
* v0.0.2 compat with IntelliJ Platform Products<br>
Expand Down

0 comments on commit ededd39

Please sign in to comment.