@@ -28,15 +28,13 @@ import androidx.core.text.inSpans
28
28
import com.osfans.trime.core.Rime
29
29
import com.osfans.trime.core.RimeProto
30
30
import com.osfans.trime.data.theme.ColorManager
31
- import com.osfans.trime.data.theme.EventManager
32
31
import com.osfans.trime.data.theme.FontManager
33
32
import com.osfans.trime.data.theme.Theme
34
33
import com.osfans.trime.data.theme.model.CompositionComponent
35
34
import com.osfans.trime.ime.core.TrimeInputMethodService
36
35
import com.osfans.trime.ime.keyboard.Event
37
36
import com.osfans.trime.ime.keyboard.KeyboardActionListener
38
37
import com.osfans.trime.ime.keyboard.KeyboardPrefs.isLandscapeMode
39
- import com.osfans.trime.ime.keyboard.KeyboardSwitcher
40
38
import com.osfans.trime.util.sp
41
39
import splitties.dimensions.dp
42
40
import kotlin.math.absoluteValue
@@ -273,28 +271,29 @@ class Composition(
273
271
m : CompositionComponent ,
274
272
composition : RimeProto .Context .Composition ,
275
273
) {
274
+ if (composition.length <= 0 ) return
276
275
val alignmentSpan = alignmentSpan(m.align)
277
- val preeditSpans =
278
- listOf (
279
- alignmentSpan,
280
- CompositionSpan (),
281
- AbsoluteSizeSpan (sp(theme.generalStyle.textSize)),
282
- m.letterSpacing
283
- .toFloat()
284
- .takeIf { it > 0 }
285
- ?.let { ScaleXSpan (it) },
286
- ).mapNotNull { it }.toTypedArray()
287
- val colorSpans = listOf (highlightTextColorSpan, highlightBackColorSpan).mapNotNull { it }
288
- inSpans(alignmentSpan) { append(m.start) }
276
+ if (m.start.isNotEmpty()) {
277
+ inSpans(alignmentSpan) { append(m.start) }
278
+ }
289
279
preeditRange[0 ] = length
290
- inSpans(* preeditSpans) { append(composition.preedit) }
280
+ inSpans(
281
+ alignmentSpan,
282
+ CompositionSpan (),
283
+ AbsoluteSizeSpan (sp(theme.generalStyle.textSize)),
284
+ ) { append(composition.preedit) }
285
+ if (m.letterSpacing > 0 ) {
286
+ setSpan(ScaleXSpan (m.letterSpacing.toFloat()), preeditRange[0 ], length, Spanned .SPAN_INCLUSIVE_EXCLUSIVE )
287
+ }
291
288
preeditRange[1 ] = length
289
+
292
290
val selStart = preeditRange[0 ] + composition.selStart
293
291
val selEnd = preeditRange[0 ] + composition.selEnd
294
- for (span in colorSpans) {
295
- setSpan(span, selStart, selEnd, Spanned .SPAN_INCLUSIVE_EXCLUSIVE )
292
+ highlightTextColorSpan?.let { setSpan(it, selStart, selEnd, Spanned .SPAN_INCLUSIVE_EXCLUSIVE ) }
293
+ highlightBackColorSpan?.let { setSpan(it, selStart, selEnd, Spanned .SPAN_INCLUSIVE_EXCLUSIVE ) }
294
+ if (m.end.isNotEmpty()) {
295
+ append(m.end)
296
296
}
297
- inSpans(alignmentSpan) { append(m.end) }
298
297
}
299
298
300
299
/* * 生成悬浮窗内的文本 */
@@ -366,23 +365,6 @@ class Composition(
366
365
inSpans(alignmentSpan) { append(m.end) }
367
366
}
368
367
369
- private fun SpannableStringBuilder.buildSpannedButton (
370
- m : CompositionComponent ,
371
- menu : RimeProto .Context .Menu ,
372
- ) {
373
- when (m.whenStr) {
374
- " paging" -> if (menu.pageNumber == 0 ) return
375
- " has_menu" -> if (menu.candidates.isEmpty()) return
376
- }
377
- val alignmentSpan = alignmentSpan(m.align)
378
- val event = EventManager .getEvent(m.click)
379
- val label = m.label.ifBlank { event.getLabel(KeyboardSwitcher .currentKeyboard) }
380
- val buttonSpans = listOf (alignmentSpan, EventSpan (event), keyTextSizeSpan).toTypedArray()
381
- inSpans(alignmentSpan) { append(m.start) }
382
- inSpans(* buttonSpans) { append(label) }
383
- inSpans(alignmentSpan) { append(m.end) }
384
- }
385
-
386
368
private fun SpannableStringBuilder.buildSpannedMove (m : CompositionComponent ) {
387
369
val alignmentSpan = alignmentSpan(m.align)
388
370
val moveSpans =
@@ -443,8 +425,6 @@ class Composition(
443
425
component,
444
426
ctx.composition,
445
427
)
446
-
447
- component.click.isNotBlank() -> buildSpannedButton(component, ctx.menu)
448
428
component.candidate.isNotBlank() ->
449
429
buildSpannedCandidates(
450
430
component,
0 commit comments