|
|
|
|
@ -1,10 +1,31 @@
|
|
|
|
|
textEditor = name \
|
|
|
|
|
# defaults = {};
|
|
|
|
|
# c = { ...defaults, ...config };
|
|
|
|
|
buffersKey = "textEditorBuffers";
|
|
|
|
|
|
|
|
|
|
# load from staging buffers if it exists there. if not, load from source
|
|
|
|
|
source = getAt [buffersKey, name]
|
|
|
|
|
| None \ getSource name
|
|
|
|
|
| Some v \ v;
|
|
|
|
|
|
|
|
|
|
source = getSource name;
|
|
|
|
|
lines = split "\n" source;
|
|
|
|
|
|
|
|
|
|
write = state \
|
|
|
|
|
content = join "\n" state.lines;
|
|
|
|
|
{ state = state, emit = [rebindAt [buffersKey, name] content] };
|
|
|
|
|
|
|
|
|
|
apply = state \
|
|
|
|
|
content = name & " = " & (join "\n" state.lines) & ";";
|
|
|
|
|
result = eval! content;
|
|
|
|
|
_ = debug! "apply" [content, result];
|
|
|
|
|
result
|
|
|
|
|
| Defined _ \ { state = state, emit = [] }
|
|
|
|
|
| Err msg \ (
|
|
|
|
|
_ = debug! "error applying" [];
|
|
|
|
|
{ state = state, emit = [] }
|
|
|
|
|
)
|
|
|
|
|
| _ \ { state = state, emit = [] };
|
|
|
|
|
|
|
|
|
|
insertChar = char state \
|
|
|
|
|
newLines = updateAt state.cursorRow (line \
|
|
|
|
|
insertCharAt line state.cursorCol char
|
|
|
|
|
@ -146,9 +167,21 @@ textEditor = name \
|
|
|
|
|
| Normal \ undo state)
|
|
|
|
|
|
|
|
|
|
| Key { key = "r", ctrl = True } \ (state.mode
|
|
|
|
|
| Insert \ insertChar "R" state
|
|
|
|
|
| Insert \ { state = state, emit = [] }
|
|
|
|
|
| Normal \ redo state)
|
|
|
|
|
|
|
|
|
|
| Key { key = "W", shift = True } \ (state.mode
|
|
|
|
|
| Insert \ insertChar "W" state
|
|
|
|
|
| Normal \ write state)
|
|
|
|
|
|
|
|
|
|
| Key { key = "W", shift = True } \ (state.mode
|
|
|
|
|
| Insert \ insertChar "W" state
|
|
|
|
|
| Normal \ write state)
|
|
|
|
|
|
|
|
|
|
| Key { key = "A", shift = True } \ (state.mode
|
|
|
|
|
| Insert \ insertChar "A" state
|
|
|
|
|
| Normal \ apply state)
|
|
|
|
|
|
|
|
|
|
| Key { key = "Escape" } \ escape state
|
|
|
|
|
|
|
|
|
|
| Key { key = "Backspace" } \ (state.mode
|
|
|
|
|
|