scoop:scoop.ui:0.1.0
src/text/editor/value.scoop
Selected production source · src/text/editor/value.scoop
1
package scoop.ui.text3
import scoop.graphics.text.*4
import scoop.window.*6
internal struct EditorValue(7
val input: TextInputState,8
val anchorAffinity: TextAffinity = TextAffinity.Downstream,9
val cursorAffinity: TextAffinity = TextAffinity.Downstream10
) {11
val endpoints: EditorSelection get() =12
EditorSelection(13
TextPosition(input.selection.anchor, anchorAffinity),14
TextPosition(input.selection.cursor, cursorAffinity)15
)16
}18
internal struct EditorSelection(val anchor: TextPosition, val cursor: TextPosition)20
internal fun editorInitial(text: String, selection: Utf8Selection?): EditorValue {21
val input = TextInputState(text, selection ?: Utf8Selection(text.byteLength, text.byteLength))22
input.validate()23
return EditorValue(input)24
}26
internal fun editorVersion(value: EditorValue, revision: Long): EditorValue =27
EditorValue(28
TextInputState(29
value.input.surroundingText,30
value.input.selection,31
value.input.markedRange,32
revision = revision33
),34
value.anchorAffinity,35
value.cursorAffinity36
)38
internal fun editorSelect(input: TextInputState, selection: EditorSelection): EditorValue =39
EditorValue(40
TextInputState(41
input.surroundingText,42
Utf8Selection(selection.anchor.byteOffset, selection.cursor.byteOffset),43
input.markedRange,44
revision = input.revision45
),46
selection.anchor.affinity,47
selection.cursor.affinity48
)