Scoop API

scoop:scoop.ui:0.1.0

src/text/editor/value.scoop

Selected production source · src/text/editor/value.scoop

1package scoop.ui.text
3import scoop.graphics.text.*
4import scoop.window.*
6internal struct EditorValue(
7 val input: TextInputState,
8 val anchorAffinity: TextAffinity = TextAffinity.Downstream,
9 val cursorAffinity: TextAffinity = TextAffinity.Downstream
10) {
11 val endpoints: EditorSelection get() =
12 EditorSelection(
13 TextPosition(input.selection.anchor, anchorAffinity),
14 TextPosition(input.selection.cursor, cursorAffinity)
15 )
18internal struct EditorSelection(val anchor: TextPosition, val cursor: TextPosition)
20internal 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)
26internal 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 = revision
33 ),
34 value.anchorAffinity,
35 value.cursorAffinity
36 )
38internal 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.revision
45 ),
46 selection.anchor.affinity,
47 selection.cursor.affinity
48 )