aboutsummaryrefslogtreecommitdiffstats
path: root/examples/notes.aup
blob: 214b617eac5a66b76b96eb1c70941d6c6f034679 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# A small text editor. The runtime owns the text: typing inserts at the
# cursor, the cursor and the mark always sit between characters and follow
# edits (text typed at the mark goes after it: the mark stays), and a failed
# event would leave everything as it was.
state title: text = "메모"
state note: text = ""
state at: cursor in note
state mark: mark in note

input typed = text
input left = key ArrowLeft
input right = key ArrowRight
input up = key ArrowUp
input down = key ArrowDown
input back = key Backspace
input forward = key Delete
input home = key Home
input finish = key End
input set_mark = key KeyM

on typed { note.insert(at, typed) }
on left.down { at = at - 1 char }
on right.down { at = at + 1 char }
on up.down { at = at - 1 line }
on down.down { at = at + 1 line }
on back.down { note.remove(at - 1 char .. at) }
on forward.down { note.remove(at .. at + 1 char) }
on home.down { at = note.start }
on finish.down { at = note.end }
on set_mark.down { mark = at }

view header = "{title} · {note.chars}자"
view current = note.line(at)
view position = "line {at.line}, char {at.chars}"
view size = note.bytes
view lines = note.lines