改行せずに絵文字が12以上並んだら改行を挟む

This commit is contained in:
tateisu 2020-09-10 23:05:52 +09:00
parent e256292fc0
commit 264664bdc4
1 changed files with 15 additions and 3 deletions

View File

@ -9,6 +9,7 @@ import jp.juggler.subwaytooter.api.entity.NicoProfileEmoji
import jp.juggler.subwaytooter.api.entity.TootAttachmentLike
import jp.juggler.subwaytooter.api.entity.TootMention
import jp.juggler.subwaytooter.table.HighlightWord
import jp.juggler.util.CharacterGroup
import jp.juggler.util.WordTrieTree
import java.util.*
@ -51,16 +52,27 @@ class DecodeOptions(
private fun SpannableStringBuilder.workaroundForEmojiLineBreak() : SpannableStringBuilder {
val spans = getSpans(0, length, ReplacementSpan::class.java)
if(spans != null) {
if(spans != null && spans.size >= 40) {
val wrapCount = 12 // if(linkHelper?.isMisskey == true ) 6 else 12
fun hasLineBreak(start : Int?, end : Int) : Boolean {
if(start != null)
for(i in start until end) {
if(get(i) == '\n') return true
}
return false
}
val insertList = ArrayList<Int>()
spans.sortBy { getSpanStart(it) }
var repeatCount = 0
var preEnd : Int? = null
for(span in spans) {
val start = getSpanStart(span)
if(start != preEnd) {
val hasLf = hasLineBreak(preEnd, start)
if(hasLf) {
repeatCount = 0
} else if(++ repeatCount >= 12) {
} else if(++ repeatCount >= wrapCount) {
repeatCount = 0
insertList.add(start)
}