textEditor can save to a textEditorBuffers list with the W command. it can apply back to the original store ref with the A command. Crazy man

master
Dustin Swan 17 hours ago
parent b0726bc0fb
commit f1ff6c29d6
Signed by: dustinswan
GPG Key ID: 30D46587E2100467

@ -1,10 +1,31 @@
textEditor = name \ textEditor = name \
# defaults = {}; # defaults = {};
# c = { ...defaults, ...config }; # 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; 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 \ insertChar = char state \
newLines = updateAt state.cursorRow (line \ newLines = updateAt state.cursorRow (line \
insertCharAt line state.cursorCol char insertCharAt line state.cursorCol char
@ -146,9 +167,21 @@ textEditor = name \
| Normal \ undo state) | Normal \ undo state)
| Key { key = "r", ctrl = True } \ (state.mode | Key { key = "r", ctrl = True } \ (state.mode
| Insert \ insertChar "R" state | Insert \ { state = state, emit = [] }
| Normal \ redo state) | 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 = "Escape" } \ escape state
| Key { key = "Backspace" } \ (state.mode | Key { key = "Backspace" } \ (state.mode

Loading…
Cancel
Save