Skip to content

Commit fbec531

Browse files
committed
Fix saving quickphrase with newline character
1 parent 9d2304f commit fbec531

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

app/src/main/java/org/fcitx/fcitx5/android/data/quickphrase/QuickPhraseData.kt

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,24 @@ package org.fcitx.fcitx5.android.data.quickphrase
33
import org.fcitx.fcitx5.android.R
44
import org.fcitx.fcitx5.android.utils.errorRuntime
55

6-
class QuickPhraseData(private val data: List<QuickPhraseEntry>) :
7-
List<QuickPhraseEntry> by data {
6+
class QuickPhraseData(private val data: List<QuickPhraseEntry>) : List<QuickPhraseEntry> by data {
87

98
fun serialize(): String = joinToString("\n") { it.serialize() }
109

1110
companion object {
12-
fun fromLines(lines: List<String>): Result<QuickPhraseData> =
13-
runCatching {
14-
lines.filter { it.isNotBlank() }
15-
.map {
16-
val s = it.trim()
17-
val spaceIndex = s.indexOf(' ')
18-
if (spaceIndex < 0)
19-
errorRuntime(R.string.exception_quickphrase_parse, it)
20-
QuickPhraseEntry(s.substring(0, spaceIndex), s.substring(spaceIndex + 1))
21-
}
22-
}.map { QuickPhraseData(it) }
11+
fun fromLines(lines: List<String>): Result<QuickPhraseData> {
12+
return runCatching {
13+
val list = mutableListOf<QuickPhraseEntry>()
14+
lines.forEach {
15+
if (it.isBlank()) return@forEach
16+
val s = it.trim()
17+
val sep = s.indexOf(' ')
18+
if (sep < 0)
19+
errorRuntime(R.string.exception_quickphrase_parse, it)
20+
list.add(QuickPhraseEntry(s.substring(0, sep), s.substring(sep + 1)))
21+
}
22+
QuickPhraseData(list)
23+
}
24+
}
2325
}
2426
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package org.fcitx.fcitx5.android.data.quickphrase
22

33
data class QuickPhraseEntry(val keyword: String, val phrase: String) {
4-
fun serialize() = "$keyword $phrase"
4+
fun serialize() = "$keyword ${phrase.replace("\n", "\\n")}"
55
}

app/src/main/java/org/fcitx/fcitx5/android/ui/main/settings/QuickPhraseEditFragment.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.fcitx.fcitx5.android.ui.main.settings
22

33
import android.app.AlertDialog
44
import android.view.View
5+
import android.view.inputmethod.EditorInfo
56
import androidx.core.os.bundleOf
67
import androidx.lifecycle.lifecycleScope
78
import kotlinx.coroutines.Dispatchers
@@ -42,6 +43,10 @@ class QuickPhraseEditFragment : ProgressFragment(), OnItemChangedListener<QuickP
4243
Mode.FreeAdd("", converter = { QuickPhraseEntry("", "") }),
4344
initialEntries,
4445
) {
46+
override fun showEntry(x: QuickPhraseEntry): String = x.run {
47+
"$keyword${phrase.replace("\n", "\\n")}"
48+
}
49+
4550
override fun showEditDialog(
4651
title: String,
4752
entry: QuickPhraseEntry?,
@@ -50,6 +55,10 @@ class QuickPhraseEditFragment : ProgressFragment(), OnItemChangedListener<QuickP
5055
val (keywordLayout, keywordField) = materialTextInput {
5156
setHint(R.string.quickphrase_keyword)
5257
}
58+
keywordField.apply {
59+
isSingleLine = true
60+
imeOptions = EditorInfo.IME_ACTION_NEXT
61+
}
5362
val (phraseLayout, phraseField) = materialTextInput {
5463
setHint(R.string.quickphrase_phrase)
5564
}
@@ -71,10 +80,6 @@ class QuickPhraseEditFragment : ProgressFragment(), OnItemChangedListener<QuickP
7180
.setNegativeButton(android.R.string.cancel, null)
7281
.show()
7382
}
74-
75-
override fun showEntry(x: QuickPhraseEntry): String = x.run {
76-
"$keyword\u2003\u2003$phrase"
77-
}
7883
}
7984
ui.addOnItemChangedListener(this)
8085
ui.addTouchCallback()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy