Skip to content

Commit

Permalink
fix pinyin support #314
Browse files Browse the repository at this point in the history
  • Loading branch information
breandan committed Apr 20, 2020
1 parent 8fc42b8 commit 99eca78
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

### 3.6.1

Fixes [#324](https://github.com/acejump/AceJump/issues/314). Thanks @AlexPl292!

Fixes [#325](https://github.com/acejump/AceJump/issues/325).

Fixes Pinyin support.

### 3.6.0

Adds support for Chinese [#314](https://github.com/acejump/AceJump/issues/314).
Expand Down
24 changes: 13 additions & 11 deletions src/main/kotlin/org/acejump/config/AceSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ import kotlin.reflect.KProperty
*/

// TODO: https://github.com/acejump/AceJump/issues/215
data class AceSettings(var layout: KeyLayout = QWERTY,
var allowedChars: String = layout.text,
// These must be primitives in order to be serializable
internal var jumpModeRGB: Int = BLUE.rgb,
internal var targetModeRGB: Int = RED.rgb,
internal var definitionModeRGB: Int = MAGENTA.rgb,
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 supportPinyin: Boolean = true) {
data class AceSettings(
var layout: KeyLayout = QWERTY,
var allowedChars: String = layout.text,
// These must be primitives in order to be serializable
internal var jumpModeRGB: Int = BLUE.rgb,
internal var targetModeRGB: Int = RED.rgb,
internal var definitionModeRGB: Int = MAGENTA.rgb,
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 supportPinyin: Boolean = false
) {

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

init {
Expand Down Expand Up @@ -104,6 +104,6 @@ internal class AceSettingsPanel {
private operator fun ColorPanel.getValue(a: AceSettingsPanel, p: KProperty<*>) = selectedColor
private operator fun ColorPanel.setValue(a: AceSettingsPanel, p: KProperty<*>, c: Color?) = setSelectedColor(c)

private operator fun JCheckBox.getValue(a: AceSettingsPanel, p: KProperty<*>) = isEnabled
private operator fun JCheckBox.setValue(a: AceSettingsPanel, p: KProperty<*>, enabled: Boolean) = setEnabled(enabled)
private operator fun JCheckBox.getValue(a: AceSettingsPanel, p: KProperty<*>) = isSelected
private operator fun JCheckBox.setValue(a: AceSettingsPanel, p: KProperty<*>, selected: Boolean) = setSelected(selected)
}
9 changes: 4 additions & 5 deletions src/main/kotlin/org/acejump/view/Model.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ object Model {
get() = editor.document.text
.let { if (AceConfig.supportPinyin) it.mapToPinyin() else it }

private fun String.mapToPinyin() =
chars().run { if(DEFAULT_BUFFER < length) parallel() else this }.mapToObj {
if (UnicodeScript.of(it) == UnicodeScript.HAN)
pinyin.translateFirstChar(it.toString()).first() else it.toChar()
}.toArray().joinToString("")
private fun String.mapToPinyin() = map {
if (UnicodeScript.of(it.toInt()) == UnicodeScript.HAN)
pinyin.translateFirstChar(it.toString()).first() else it
}.joinToString("")

val pinyin = Pinyin()

Expand Down

0 comments on commit 99eca78

Please sign in to comment.