Skip to content

Commit

Permalink
initial implementation of acejump#314
Browse files Browse the repository at this point in the history
  • Loading branch information
breandan committed Dec 7, 2019
1 parent e5de0fa commit 9e65193
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### 3.6.0

Adds support for Chinese [#314](https://github.com/acejump/AceJump/issues/314).

### 3.5.9

Fix a build configuration error affecting plugins which depend on AceJump. Fixes [#305](https://github.com/acejump/AceJump/issues/305).
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ tasks {
dependencies {
// gradle-intellij-plugin doesn't attach sources properly for Kotlin :(
compileOnly(kotlin("stdlib-jdk8"))
implementation("net.duguying.pinyin:pinyin:0.0.1")
}

repositories.mavenCentral()
Expand Down
5 changes: 4 additions & 1 deletion src/main/kotlin/org/acejump/config/AceConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ object AceConfig: Configurable, PersistentStateComponent<AceSettings> {
val definitionModeColor: Color get() = settings.definitionModeColor
val tagForegroundColor: Color get() = settings.tagForegroundColor
val tagBackgroundColor: Color get() = settings.tagBackgroundColor
val supportPinyin: Boolean get() = settings.supportPinyin

private var allPossibleTags: Set<String> = settings.allowedChars.bigrams()

Expand Down Expand Up @@ -57,7 +58,8 @@ object AceConfig: Configurable, PersistentStateComponent<AceSettings> {
panel.targetModeColor != settings.targetModeColor ||
panel.textHighlightColor != settings.textHighlightColor ||
panel.tagForegroundColor != settings.tagForegroundColor ||
panel.tagBackgroundColor != settings.tagBackgroundColor
panel.tagBackgroundColor != settings.tagBackgroundColor ||
panel.supportPinyin != settings.supportPinyin

private fun String.distinctAlphanumerics() =
if (isEmpty()) settings.layout.text
Expand All @@ -75,6 +77,7 @@ object AceConfig: Configurable, PersistentStateComponent<AceSettings> {
panel.textHighlightColor?.let { settings.textHighlightRGB = it.rgb }
panel.tagForegroundColor?.let { settings.tagForegroundRGB = it.rgb }
panel.tagBackgroundColor?.let { settings.tagBackgroundRGB = it.rgb }
panel.supportPinyin.let { settings.supportPinyin = it }
logger.info("User applied new settings: $settings")
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/org/acejump/config/AceSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ data class AceSettings(var layout: KeyLayout = QWERTY,
internal var textHighlightRGB: Int = GREEN.rgb,
internal var tagForegroundRGB: Int = BLACK.rgb,
internal var tagBackgroundRGB: Int = YELLOW.rgb,
internal var displayQuery: Boolean = false) {
internal var displayQuery: Boolean = false,
internal var supportPinyin: Boolean = true) {

// ...but we expose them to the world as Color
val jumpModeColor: Color by { jumpModeRGB }
Expand Down
5 changes: 5 additions & 0 deletions src/main/kotlin/org/acejump/config/AceSettingsPanel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ internal class AceSettingsPanel {
private val tagForegroundColorWheel = ColorPanel()
private val tagBackgroundColorWheel = ColorPanel()
private val displayQueryCheckBox = JBCheckBox()
private val supportPinyinCheckBox = JBCheckBox()

init {
tagCharsField.apply { font = Font("monospaced", font.style, font.size) }
Expand Down Expand Up @@ -61,6 +62,8 @@ internal class AceSettingsPanel {
row(aceString("textHighlightColorLabel")) { short(textHighlightColorWheel) }
row(aceString("appearanceHeading")) { SeparatorComponent() }
row(aceString("displayQueryLabel")) { short(displayQueryCheckBox) }
row(aceString("languagesHeading")) { SeparatorComponent() }
row(aceString("supportPinyin")) { short(supportPinyinCheckBox) }
}

internal var keyboardLayout: KeyLayout
Expand All @@ -76,6 +79,7 @@ internal class AceSettingsPanel {
internal var tagForegroundColor by tagForegroundColorWheel
internal var tagBackgroundColor by tagBackgroundColorWheel
internal var displayQuery by displayQueryCheckBox
internal var supportPinyin by supportPinyinCheckBox

fun reset(settings: AceSettings) {
allowedChars = settings.allowedChars
Expand All @@ -86,6 +90,7 @@ internal class AceSettingsPanel {
tagForegroundColor = settings.tagForegroundColor
tagBackgroundColor = settings.tagBackgroundColor
displayQuery = settings.displayQuery
supportPinyin = settings.supportPinyin
}

// Removal pending support for https://youtrack.jetbrains.com/issue/KT-8575
Expand Down
13 changes: 12 additions & 1 deletion src/main/kotlin/org/acejump/view/Model.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.colors.EditorColors.CARET_COLOR
import com.intellij.openapi.editor.impl.EditorImpl
import com.intellij.openapi.project.ProjectManager
import net.duguying.pinyin.Pinyin
import org.acejump.config.AceConfig
import org.acejump.search.defaultEditor
import org.acejump.view.Boundary.FULL_FILE_BOUNDARY
import java.awt.Color.BLACK
import java.awt.Color.YELLOW
import java.awt.Font
import java.awt.Font.BOLD
import java.lang.Character.UnicodeScript

/**
* Data holder for all settings and IDE components needed by AceJump.
Expand All @@ -27,8 +29,17 @@ object Model {
get() = editor.project ?: ProjectManager.getInstance().defaultProject
val caretOffset
get() = editor.caretModel.offset
val editorText
val editorText: String
get() = editor.document.text
.let { if (AceConfig.supportPinyin) mapToPinyin(it) else it }

private fun mapToPinyin(it: String) =
it.mapNotNull {
if (UnicodeScript.of(it.toInt()) == UnicodeScript.HAN)
pinyin.translateFirstChar(it.toString()).first() else it
}.joinToString("")

val pinyin = Pinyin()

var naturalBlock = false
var naturalBlink = true
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/AceResources.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ tagForegroundColorLabel=Tag foreground color:
targetModeColorLabel=Target mode color:
textHighlightColorLabel=Text highlight color:
appearanceHeading=Other appearance settings
displayQueryLabel=Display search query
displayQueryLabel=Display search query
langaugesHeading=Language settings
supportPinyin=Support Pinyin selection

0 comments on commit 9e65193

Please sign in to comment.