Skip to content

Commit

Permalink
switch to tinypinyin engine #314
Browse files Browse the repository at this point in the history
  • Loading branch information
breandan committed Apr 22, 2020
1 parent 1800efd commit 8d49532
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
7 changes: 5 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ tasks {
dependencies {
// gradle-intellij-plugin doesn't attach sources properly for Kotlin :(
compileOnly(kotlin("stdlib-jdk8"))
implementation("net.duguying.pinyin:pinyin:0.0.1")
implementation("com.github.promeg:tinypinyin:2.0.3")
}

repositories.mavenCentral()
repositories {
mavenCentral()
jcenter()
}

intellij {
version = "2020.1"
Expand Down
10 changes: 3 additions & 7 deletions src/main/kotlin/org/acejump/view/Model.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.acejump.view

import com.github.promeg.pinyinhelper.Pinyin
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
Expand Down Expand Up @@ -33,12 +33,8 @@ object Model {
get() = editor.document.text
.let { if (AceConfig.supportPinyin) it.mapToPinyin() else it }

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

val pinyin = Pinyin()
private fun String.mapToPinyin() =
map { Pinyin.toPinyin(it).first() }.joinToString("")

var naturalBlock = false
var naturalBlink = true
Expand Down

0 comments on commit 8d49532

Please sign in to comment.