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
This commit is contained in:
parent
b0726bc0fb
commit
f1ff6c29d6
1 changed files with 35 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue