|
|
|
|
@ -1,6 +1,13 @@
|
|
|
|
|
textEditor = name \
|
|
|
|
|
# defaults = {};
|
|
|
|
|
# c = { ...defaults, ...config };
|
|
|
|
|
scale = 2;
|
|
|
|
|
charH = 12;
|
|
|
|
|
charW = 5;
|
|
|
|
|
lineGap = 1;
|
|
|
|
|
charGap = 2;
|
|
|
|
|
lineH = charH * scale + lineGap;
|
|
|
|
|
|
|
|
|
|
buffersKey = "textEditorBuffers";
|
|
|
|
|
|
|
|
|
|
# load from staging buffers if it exists there. if not, load from source
|
|
|
|
|
@ -116,19 +123,9 @@ textEditor = name \
|
|
|
|
|
newState = clampCursor state.{ cursorCol = state.cursorCol + 1 };
|
|
|
|
|
{ state = newState, emit = [] };
|
|
|
|
|
|
|
|
|
|
# todo: scrollHalfDown = state \ ();
|
|
|
|
|
# todo: scrollHalfUp = state \ ();
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
view = ctx \
|
|
|
|
|
|
|
|
|
|
scale = 2;
|
|
|
|
|
charH = 12;
|
|
|
|
|
charW = 5;
|
|
|
|
|
lineGap = 1;
|
|
|
|
|
charGap = 2;
|
|
|
|
|
lineH = charH * scale + lineGap;
|
|
|
|
|
|
|
|
|
|
autoScroll = state \
|
|
|
|
|
cursorY = state.cursorRow * lineH;
|
|
|
|
|
newScrollY = (cursorY < state.scrollY
|
|
|
|
|
@ -143,11 +140,21 @@ textEditor = name \
|
|
|
|
|
| False \ (cursorX + charW * scale > state.scrollX + ctx.w
|
|
|
|
|
| True \ cursorX + charW * scale - ctx.w
|
|
|
|
|
| False \ state.scrollX));
|
|
|
|
|
state.{ scrollY = newScrollY, cursorY = cursorY, scrollX = newScrollX, cursorX = cursorX };
|
|
|
|
|
state.{ scrollY = newScrollY, scrollX = newScrollX };
|
|
|
|
|
|
|
|
|
|
withScroll = result \
|
|
|
|
|
{ state = autoScroll result.state, emit = result.emit };
|
|
|
|
|
|
|
|
|
|
scrollHalfUp = state ctx \ (
|
|
|
|
|
diff = floor ((ctx.h / 2) / lineH);
|
|
|
|
|
newRow = state.cursorRow - diff;
|
|
|
|
|
withScroll { state = clampCursor state.{ cursorRow = newRow }, emit = [] });
|
|
|
|
|
|
|
|
|
|
scrollHalfDown = state ctx \ (
|
|
|
|
|
diff = floor ((ctx.h / 2) / lineH);
|
|
|
|
|
newRow = state.cursorRow + diff;
|
|
|
|
|
withScroll { state = clampCursor state.{ cursorRow = newRow }, emit = [] });
|
|
|
|
|
|
|
|
|
|
ui.stateful {
|
|
|
|
|
focusable = True,
|
|
|
|
|
autoFocus = True,
|
|
|
|
|
@ -198,6 +205,9 @@ textEditor = name \
|
|
|
|
|
| Insert \ insertChar "i" state
|
|
|
|
|
| Normal \ insertMode state)
|
|
|
|
|
|
|
|
|
|
| Key { key = "d", ctrl = True } \ scrollHalfDown state ctx
|
|
|
|
|
| Key { key = "u", ctrl = True } \ scrollHalfUp state ctx
|
|
|
|
|
|
|
|
|
|
| Key { key = "u" } \ (state.mode
|
|
|
|
|
| Insert \ insertChar "u" state
|
|
|
|
|
| Normal \ undo state)
|
|
|
|
|
@ -218,9 +228,6 @@ textEditor = name \
|
|
|
|
|
| Insert \ insertChar "A" state
|
|
|
|
|
| Normal \ apply state)
|
|
|
|
|
|
|
|
|
|
| Key { key = "d", ctrl = True } \ scrollHalfDown state
|
|
|
|
|
| Key { key = "u", ctrl = True } \ scrollHalfUp state
|
|
|
|
|
|
|
|
|
|
| Key { key = "Escape" } \ escape state
|
|
|
|
|
|
|
|
|
|
| Key { key = "Backspace" } \ (state.mode
|
|
|
|
|
@ -239,10 +246,12 @@ textEditor = name \
|
|
|
|
|
| _ \ { state = state, emit = [] },
|
|
|
|
|
|
|
|
|
|
view = state emit \
|
|
|
|
|
_ = debug! "here" state;
|
|
|
|
|
cursorX = state.cursorCol * charW * scale + charGap * state.cursorCol;
|
|
|
|
|
cursorY = state.cursorRow * lineH;
|
|
|
|
|
|
|
|
|
|
cursor = ui.positioned {
|
|
|
|
|
x = state.cursorX,
|
|
|
|
|
y = state.cursorY,
|
|
|
|
|
x = cursorX,
|
|
|
|
|
y = cursorY,
|
|
|
|
|
child = ui.rect { w = charW * scale, h = charH * scale, color = "rgba(255,255,255,0.5)" }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|