|
|
|
|
@ -138,6 +138,11 @@ textEditor = name \
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
update = state event \ event
|
|
|
|
|
| Scrolled delta \ (
|
|
|
|
|
newY = max 0 (state.scrollY + delta.deltaY);
|
|
|
|
|
newX = max 0 (state.scrollX + delta.deltaX);
|
|
|
|
|
{ state = state.{ scrollY = newY, scrollX = newX }, emit = [] })
|
|
|
|
|
|
|
|
|
|
| Key { key = "ArrowDown" } \ downArrow state
|
|
|
|
|
| Key { key = "j" } \ (state.mode
|
|
|
|
|
| Insert \ insertChar "j" state
|
|
|
|
|
@ -200,27 +205,46 @@ textEditor = name \
|
|
|
|
|
| _ \ { state = state, emit = [] },
|
|
|
|
|
|
|
|
|
|
view = state emit \
|
|
|
|
|
buffer = map (l \ text l) state.lines;
|
|
|
|
|
|
|
|
|
|
scale = 2;
|
|
|
|
|
charH = 12;
|
|
|
|
|
charW = 5;
|
|
|
|
|
lineGap = 1;
|
|
|
|
|
charGap = 2;
|
|
|
|
|
lineH = charH * scale + lineGap;
|
|
|
|
|
|
|
|
|
|
cursorY = state.cursorRow * lineH;
|
|
|
|
|
scrollY = (cursorY < state.scrollY
|
|
|
|
|
| True \ cursorY
|
|
|
|
|
| False \ (cursorY + lineH > state.scrollY + ctx.h
|
|
|
|
|
| True \ cursorY + lineH - ctx.h
|
|
|
|
|
| False \ state.scrollY));
|
|
|
|
|
|
|
|
|
|
cursorX = state.cursorCol * charW * scale + charGap * state.cursorCol;
|
|
|
|
|
scrollX = (cursorX < state.scrollX
|
|
|
|
|
| True \ cursorX
|
|
|
|
|
| False \ (cursorX + charW * scale > state.scrollX + ctx.w
|
|
|
|
|
| True \ cursorX + charW * scale - ctx.w
|
|
|
|
|
| False \ state.scrollX));
|
|
|
|
|
|
|
|
|
|
buffer = map (l \ text l) state.lines;
|
|
|
|
|
|
|
|
|
|
cursor = ui.positioned {
|
|
|
|
|
x = state.cursorCol * charW * scale + charGap * state.cursorCol,
|
|
|
|
|
y = state.cursorRow * charH * scale + lineGap * state.cursorRow,
|
|
|
|
|
x = cursorX,
|
|
|
|
|
y = cursorY,
|
|
|
|
|
child = ui.rect { w = charW * scale, h = charH * scale, color = "rgba(255,255,255,0.5)" }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
maxLineLen = fold (acc line \ max acc (len line)) 0 state.lines;
|
|
|
|
|
totalWidth = maxLineLen * charW * scale + maxLineLen * charGap;
|
|
|
|
|
totalHeight = len state.lines * lineH;
|
|
|
|
|
|
|
|
|
|
scrollable {
|
|
|
|
|
w = ctx.w,
|
|
|
|
|
h = ctx.h,
|
|
|
|
|
totalWidth = 1000,
|
|
|
|
|
totalHeight = 1000,
|
|
|
|
|
scrollX = state.scrollX,
|
|
|
|
|
scrollY = state.scrollY,
|
|
|
|
|
totalWidth = totalWidth,
|
|
|
|
|
totalHeight = totalHeight,
|
|
|
|
|
scrollX = scrollX,
|
|
|
|
|
scrollY = scrollY,
|
|
|
|
|
child = ui.stack {
|
|
|
|
|
children = [
|
|
|
|
|
ui.column {
|
|
|
|
|
|