Scoop API

scoop:scoop.surface:0.1.0

src/shared/input/text_continuation.scoop

Selected production source · src/shared/input/text_continuation.scoop

1package scoop.surface
3import scoop.window.*
5/** A pending receiver change for the same native text document. */
6internal class InputTextContinuation(
7 val source: InputArea,
8 val target: InputArea,
9 val connection: TextInputConnection,
10 val revision: ULong
13internal fun InputRouter.continueTextInput(source: InputArea, target: InputArea): Boolean {
14 checkOpen()
15 requireInput(
16 source.owner === this && target.owner === this,
17 "text areas belong to different windows"
18 )
19 if (source === target || !source.hasFocus || !source.isFocusActive)
20 return false
21 val connection = imeConnection ?: return false
22 val value = InputTextContinuation(source, target, connection, source.textInputRevision)
23 if (!acceptsTextContinuation(value))
24 return false
25 textContinuation = Some(value)
26 return true
29private fun InputRouter.acceptsTextContinuation(value: InputTextContinuation): Boolean =
30 osFocused &&
31 !value.source.closed &&
32 !value.target.closed &&
33 value.source.textInput &&
34 value.target.textInput &&
35 allowsFocus(value.source.scope) &&
36 allowsFocus(value.target.scope) &&
37 value.source.textInputRevision ==
38 value.revision &&
39 imeRequest ==
40 value.revision &&
41 imeConnection ==
42 Some(value.connection) &&
43 when (ime) {
44 case On(val area) -> area === value.source
45 else -> false
46 }
48internal fun InputRouter.validateTextContinuation() {
49 when (textContinuation) {
50 case Some(val value) -> if (!acceptsTextContinuation(value))
51 textContinuation = None
52 case None -> {}
53 }
56internal fun InputRouter.completeTextContinuation(previous: InputArea?, next: InputArea?) {
57 val value = textContinuation ?: return
58 textContinuation = None
59 if (!sameArea(previous, Some(value.source)) || !sameArea(next, Some(value.target)))
60 return
61 if (!acceptsTextContinuation(value))
62 return
63 ime = ImeSession.On(value.target)
64 imeRequest = value.target.textInputRevision
65 imeCaret = None
66 // The receiving editor adopts the shared document before the source retires it.
67 var failure =
68 cleanupFailure(None) {
69 notify(
70 value.target.scope,
71 InputEvent.TextInput(TextInputEvent.Enabled(Some(value.connection)))
72 )
73 }
74 failure =
75 cleanupFailure(failure) {
76 notify(
77 value.source.scope,
78 InputEvent.TextInput(TextInputEvent.Disabled(Some(value.connection))),
79 inactive = true
80 )
81 }
82 throwFailure(failure)