Skip to content

Commit 6b2c526

Browse files
author
i2cjak
authored
Merge pull request #7 from i2cjak/backplane/textarea-scrollbar
Composer grows with its draft up to 8 lines, then scrolls with a bar
2 parents 6b1829b + 458b070 commit 6b2c526

4 files changed

Lines changed: 150 additions & 30 deletions

File tree

‎src/app/layout.bend‎

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,28 +1139,52 @@ def Comp.sel(on: Bool, +ty: Ty, +shown: List<&2, String>, +top: Nat, +draft: Str
11391139
case False{}:
11401140
Out.none()
11411141

1142-
def Lay.composer(+ty: Ty, +draft: String, +caret: Nat, +mark: Nat, +focused: Bool, +blink: Bool, +x0: U32, +x1: U32, +h: U32, running: Bool, +models: String, +picking: Bool, +ms: List<&2, String>, +model: String, +info: String, +prov: String,
1142+
# how much taller than two lines the composer is for n wrapped lines
1143+
def Comp.eh(+n: Nat) -> U32:
1144+
(U32.from_nat(Nat.sub(S.Cs.rows(n), 2n)) * 23 : U32)
1145+
1146+
# the draft wrapped as the composer shows it, cw wide
1147+
def Comp.wrap(+ty: Ty, +draft: String, +cw: U32) -> List<&2, String>:
1148+
Ty.wrap(ty, 3n, draft, (cw - 40 : U32))
1149+
1150+
# a scrollbar at x beside v of n lines from top, the view th tall
1151+
def Comp.bar(on: Bool, +n: Nat, +v: Nat, +top: Nat, +x: U32, +y: U32, +th: U32) -> Out:
1152+
match on:
1153+
case True{}:
1154+
+bh = {U32.max(16, U32.from_nat(Nat.div(Nat.mul(U32.to_nat(th), v), n))) : U32}
1155+
+by = {U32.from_nat(Nat.div(Nat.mul(U32.to_nat((th - bh : U32)), top), Nat.sub(n, v))) : U32}
1156+
Out.ops([D.Draw.rect(D.Clip.all(), x, y, 4, th, T.Th.raise(), 255), D.Draw.rect(D.Clip.all(), x, (y + by : U32), 4, bh, T.Th.dim(), 255)])
1157+
case False{}:
1158+
Out.none()
1159+
1160+
# the composer grows upward with its draft (its footer stays put); held
1161+
# is the wheel's choice of first line (nui.bend's Cs)
1162+
def Lay.composer(+ty: Ty, +draft: String, +ls: List<&2, String>, +held: String, +caret: Nat, +mark: Nat, +focused: Bool, +blink: Bool, +x0: U32, +x1: U32, +h: U32, running: Bool, +models: String, +picking: Bool, +ms: List<&2, String>, +model: String, +info: String, +prov: String,
11431163
+es: List<&2, String>, +effort: String, +rs: List<&2, U.SkillRow>) -> Out:
11441164
+tw = {(x1 - x0 - 40 : U32) : U32}
1145-
+ls = Ty.wrap(ty, 3n, draft, tw)
1165+
+n = List.length(&2, String, ls)
1166+
+v = S.Cs.rows(n)
1167+
+eh = Comp.eh(n)
11461168
+crow = Comp.row(ty, draft, caret, tw)
1147-
+top = Nat.min(Nat.sub(List.length(&2, String, ls), 2n), Nat.sub(crow, 1n))
1148-
+shown = List.take(&2, String, List.drop(&2, String, ls, top), 2n)
1169+
+top = S.Cs.top(held, n, crow)
1170+
+shown = List.take(&2, String, List.drop(&2, String, ls, top), v)
11491171
+row = Nat.sub(crow, top)
11501172
+cx = Comp.x(ty, draft, caret, tw)
1151-
+y = {(h - 120 : U32) : U32}
1173+
+y = {(h - 120 - eh : U32) : U32}
1174+
+fy = {(h - 56 : U32) : U32}
11521175
+send = Bool.pick(String, running, "Queue", "Send")
11531176
Out.all([
1154-
Out.ops(Lay.box(D.Clip.all(), x0, y, (x1 - x0 : U32), 100, 10, T.Th.panel(), Bool.pick(U32, focused, T.Th.focus(), T.Th.line()))),
1177+
Out.ops(Lay.box(D.Clip.all(), x0, y, (x1 - x0 : U32), (100 + eh : U32), 10, T.Th.panel(), Bool.pick(U32, focused, T.Th.focus(), T.Th.line()))),
11551178
Comp.sel(Bool.and(focused, Bool.not(Nat.is_eq(caret, mark))), ty, shown, top, draft, ED.Edit.lo(caret, mark), ED.Edit.hi(caret, mark), tw, (x0 + 16 : U32), (y + 12 : U32)),
11561179
Bool.pick(Out, String.is_empty(draft),
11571180
Out.ops(Ty.text(ty, 3n, "Ask anything, @tag files, $skill, or describe the change", D.Clip.all(), (x0 + 16 : U32), (y + 10 : U32), 23, T.Th.faint())),
1158-
Lay.lines(ty, shown, D.Clip{(x0 + 1 : U32), (y + 1 : U32), (x1 - 1 : U32), (y + 60 : U32)}, (x0 + 16 : U32), (y + 10 : U32))),
1159-
Bool.pick(Out, Bool.and(focused, blink), Out.ops([D.Draw.rect(D.Clip.all(), (x0 + 16 + cx : U32), (y + 14 + (U32.from_nat(row) * 23 : U32) : U32), 1, 16, T.Th.accent(), 255)]), Out.none()),
1160-
Out{Nil{}, [Lay.hit(x0, y, (x1 - x0 : U32), 64, "focus", "composer")]},
1161-
Out{List.append(&2, R.Op, Ty.text(ty, 2n, models, D.Clip.all(), (x0 + 16 : U32), (y + 64 : U32), 28, T.Th.dim()), Lay.icon(ty, "chevron-down", D.Clip.all(), (x0 + 22 + Ty.width(ty, 2n, models) : U32), (y + 70 : U32), T.Th.dim())), [Lay.hit((x0 + 8 : U32), (y + 64 : U32), (Ty.width(ty, 2n, models) + 36 : U32), 28, "flag", "models")]},
1162-
Lay.button(ty, D.Clip.all(), (x1 - 12 - Lay.button.w(ty, send) : U32), (y + 64 : U32), send, T.Th.accent(), "send", ""),
1163-
Lay.picker(ty, picking, "" <> ms, model, info, prov, (x0 + 8 : U32), (y + 64 : U32), es, effort),
1181+
Lay.lines(ty, shown, D.Clip{(x0 + 1 : U32), (y + 1 : U32), (x1 - 1 : U32), (y + 60 + eh : U32)}, (x0 + 16 : U32), (y + 10 : U32))),
1182+
Bool.pick(Out, Bool.and(Bool.and(focused, blink), Bool.and(Nat.is_ge(crow, top), Nat.is_lt(row, v))), Out.ops([D.Draw.rect(D.Clip.all(), (x0 + 16 + cx : U32), (y + 14 + (U32.from_nat(row) * 23 : U32) : U32), 1, 16, T.Th.accent(), 255)]), Out.none()),
1183+
Comp.bar(Nat.is_gt(n, v), n, v, top, (x1 - 12 : U32), (y + 12 : U32), (U32.from_nat(v) * 23 - 4 : U32)),
1184+
Out{Nil{}, [Lay.hit(x0, y, (x1 - x0 : U32), (64 + eh : U32), "focus", "composer"), Lay.hit(0, 0, 0, 0, "cs", Nat.show(top) ++ "," ++ Nat.show(Nat.sub(n, v)))]},
1185+
Out{List.append(&2, R.Op, Ty.text(ty, 2n, models, D.Clip.all(), (x0 + 16 : U32), fy, 28, T.Th.dim()), Lay.icon(ty, "chevron-down", D.Clip.all(), (x0 + 22 + Ty.width(ty, 2n, models) : U32), (fy + 6 : U32), T.Th.dim())), [Lay.hit((x0 + 8 : U32), fy, (Ty.width(ty, 2n, models) + 36 : U32), 28, "flag", "models")]},
1186+
Lay.button(ty, D.Clip.all(), (x1 - 12 - Lay.button.w(ty, send) : U32), fy, send, T.Th.accent(), "send", ""),
1187+
Lay.picker(ty, picking, "" <> ms, model, info, prov, (x0 + 8 : U32), fy, es, effort),
11641188
Lay.skills(ty, rs, x0, x1, (y - 4 : U32))])
11651189

11661190
# whether the head line ends above top (it is out of view)
@@ -2115,17 +2139,18 @@ def Lay.attach_field(+ty: Ty, on: Bool, +path: String, +caret: Nat, +mark: Nat,
21152139
Out.none()
21162140

21172141
# the composer with its attachments
2118-
def Lay.composer.a(+ty: Ty, +draft: String, +caret: Nat, +mark: Nat, +focus: String, +blink: Bool, +x0: U32, +x1: U32, +h: U32, +running: Bool, +models: String, +picking: Bool, +ms: List<&2, String>, +model: String,
2142+
def Lay.composer.a(+ty: Ty, +draft: String, +ls: List<&2, String>, +held: String, +caret: Nat, +mark: Nat, +focus: String, +blink: Bool, +x0: U32, +x1: U32, +h: U32, +running: Bool, +models: String, +picking: Bool, +ms: List<&2, String>, +model: String,
21192143
+info: String, +prov: String, +es: List<&2, String>, +effort: String, +rs: List<&2, U.SkillRow>, +atts: List<&2, String>, +up: String, +path: String) -> Out:
21202144
+send = Bool.pick(String, running, "Queue", "Send")
2121-
+y = {(h - 120 : U32) : U32}
2145+
+y = {(h - 120 - Comp.eh(List.length(&2, String, ls)) : U32) : U32}
2146+
+fy = {(h - 56 : U32) : U32}
21222147
Out.all([
2123-
Lay.composer(ty, draft, caret, mark, String.eq(focus, "composer"), blink, x0, x1, h, running, models, picking, ms, model, info, prov, es, effort, rs),
2124-
Lay.atts(ty, atts, up, (x0 + 24 + Ty.width(ty, 2n, models) + 36 : U32), (y + 64 : U32)),
2125-
Lay.ibutton(ty, D.Clip.all(), (x1 - 20 - Lay.button.w(ty, send) - 28 : U32), (y + 64 : U32), "paperclip", T.Th.soft(), "focus", "attach-path"),
2148+
Lay.composer(ty, draft, ls, held, caret, mark, String.eq(focus, "composer"), blink, x0, x1, h, running, models, picking, ms, model, info, prov, es, effort, rs),
2149+
Lay.atts(ty, atts, up, (x0 + 24 + Ty.width(ty, 2n, models) + 36 : U32), fy),
2150+
Lay.ibutton(ty, D.Clip.all(), (x1 - 20 - Lay.button.w(ty, send) - 28 : U32), fy, "paperclip", T.Th.soft(), "focus", "attach-path"),
21262151
Lay.attach_field(ty, String.eq(focus, "attach-path"), path, caret, mark, x0, x1, (y - 36 : U32))])
21272152

2128-
def Lay.thread.k(+ty: Ty, +memo: TLMemo, t: M.Thread, +draft: String, +st: M.State, +sel: String, +live: String, +caret: Nat, +mark: Nat, +focus: String, +blink: Bool,
2153+
def Lay.thread.k(+ty: Ty, +memo: TLMemo, t: M.Thread, +draft: String, +held: String, +st: M.State, +sel: String, +live: String, +caret: Nat, +mark: Nat, +focus: String, +blink: Bool,
21292154
+x0: U32, +x1: U32, +h: U32, +sc: U32, pa: Bool, +info: String, +picking: Bool, +pend: List<&2, String>, +rs: List<&2, U.SkillRow>, +now: Nat,
21302155
+atts: List<&2, String>, +up: String, +path: String, +pics: Map<&2, String>, del: Bool, +tsel: TSel) -> Out:
21312156
match t:
@@ -2139,38 +2164,42 @@ def Lay.thread.k(+ty: Ty, +memo: TLMemo, t: M.Thread, +draft: String, +st: M.Sta
21392164
+asks = U.Asks.open(st, sel)
21402165
+ah = Asks.h(ty, asks, (cw - 32 : U32))
21412166
+qh = {Bool.pick(U32, String.is_empty(M.Queue.of(st, sel)), 0, 30) : U32}
2167+
# the composer grows by eh, and all above it moves up
2168+
+ls = Comp.wrap(ty, draft, cw)
2169+
+eh = Comp.eh(List.length(&2, String, ls))
21422170
# the timeline and what sits around it are laid out at once
21432171
tl ch = Lay.timeline(ty,
21442172
List.concat(&2, TLine, [TL.memo.shown(ty, memo, st, sel, cw, pics), TL.sending(ty, pend, cw),
21452173
TL.live.k(ty, String.is_empty(live), Lay.running(turn), live, cw)]),
2146-
cx0, cx1, top, (h - ah - qh : U32), sc, tsel, Out.none()) Out.all([Lay.header(ty, M.Thread{id, p, ti, c, a, turn, pe, ar, o, sa, ua, pi, en, br, wt, pr, mo, rm, im, se, de}, x0, x1, pa, M.Snooze.on(now, U.Side.until(st, sel)), del),
2174+
cx0, cx1, top, (h - ah - qh - eh : U32), sc, tsel, Out.none()) Out.all([Lay.header(ty, M.Thread{id, p, ti, c, a, turn, pe, ar, o, sa, ua, pi, en, br, wt, pr, mo, rm, im, se, de}, x0, x1, pa, M.Snooze.on(now, U.Side.until(st, sel)), del),
21472175
Lay.parent(ty, st, sel, cx0, 58),
21482176
Lay.tasks(ty, ts, st, cx0, cx1, (60 + pl : U32)),
2149-
Lay.composer.a(ty, draft, caret, mark, focus, blink, cx0, cx1, h, Lay.running(turn), U.Effort.label(U.Models.label(pr, mo), U.Effort.of(st, sel)), picking, U.Models.list(info, pr), mo, info, pr,
2177+
Lay.composer.a(ty, draft, ls, held, caret, mark, focus, blink, cx0, cx1, h, Lay.running(turn), U.Effort.label(U.Models.label(pr, mo), U.Effort.of(st, sel)), picking, U.Models.list(info, pr), mo, info, pr,
21502178
U.Effort.chips(info, pr, mo), U.Effort.of(st, sel), rs, atts, up, path),
2151-
Lay.queued(ty, M.Queue.of(st, sel), cx0, cx1, h),
2152-
Lay.asks(ty, asks, draft, cx0, cx1, (h - 132 - ah - qh + 4 : U32))])
2179+
Lay.queued(ty, M.Queue.of(st, sel), cx0, cx1, (h - eh : U32)),
2180+
Lay.asks(ty, asks, draft, cx0, cx1, (h - 132 - ah - qh - eh + 4 : U32))])
21532181
Out.cat(tl, ch)
21542182

21552183
# while files dragged in hover over the window, an accent ring around the
21562184
# composer (placed as Lay.thread.k places it) shows where they drop
2157-
def Lay.drop_mark(on: Bool, +x0: U32, +x1: U32, +h: U32) -> Out:
2185+
def Lay.drop_mark(on: Bool, +ty: Ty, +draft: String, +x0: U32, +x1: U32, +h: U32) -> Out:
21582186
match on:
21592187
case True{}:
21602188
+cw = {U32.min((x1 - x0 - 64 : U32), 780) : U32}
21612189
+cx0 = {(x0 + U32.shr((x1 - x0 - cw : U32)) - 5 : U32) : U32}
2162-
+y = {(h - 125 : U32) : U32}
2190+
+eh = Comp.eh(List.length(&2, String, Comp.wrap(ty, draft, cw)))
2191+
+y = {(h - 125 - eh : U32) : U32}
21632192
Out.ops([D.Draw.rect(D.Clip.all(), cx0, y, (cw + 10 : U32), 2, T.Th.accent(), 255),
2164-
D.Draw.rect(D.Clip.all(), cx0, (y + 108 : U32), (cw + 10 : U32), 2, T.Th.accent(), 255),
2165-
D.Draw.rect(D.Clip.all(), cx0, y, 2, 110, T.Th.accent(), 255),
2166-
D.Draw.rect(D.Clip.all(), (cx0 + cw + 8 : U32), y, 2, 110, T.Th.accent(), 255)])
2193+
D.Draw.rect(D.Clip.all(), cx0, (y + 108 + eh : U32), (cw + 10 : U32), 2, T.Th.accent(), 255),
2194+
D.Draw.rect(D.Clip.all(), cx0, y, 2, (110 + eh : U32), T.Th.accent(), 255),
2195+
D.Draw.rect(D.Clip.all(), (cx0 + cw + 8 : U32), y, 2, (110 + eh : U32), T.Th.accent(), 255)])
21672196
case False{}:
21682197
Out.none()
21692198

21702199
def Lay.thread(+ty: Ty, +memo: TLMemo, +n: S.Nui, +x0: U32, +x1: U32) -> Out:
21712200
match n:
21722201
case S.Nui{U.Ui{+st, +sel, _, +live, +op, _, _, _, pa, _, _, _, _, _, +nf, _, _}, _, +h, _, _, _, +sc, +caret, +focus, +path, _, _, _}:
2173-
Out.cat(Lay.drop_mark(U.Flag.get(op, "drop"), x0, x1, h), Lay.thread.k(ty, memo, U.Ui.thread(st, sel), U.Ui.draft_text(S.Nui.ui(n)), st, sel, U.Str.get(live, sel), caret, S.Nui.mark(n), focus, S.Blink.on(n), x0, x1, h, sc, pa,
2202+
Out.cat(Lay.drop_mark(U.Flag.get(op, "drop"), ty, U.Ui.draft_text(S.Nui.ui(n)), x0, x1, h), Lay.thread.k(ty, memo, U.Ui.thread(st, sel), U.Ui.draft_text(S.Nui.ui(n)), S.Cs.held(n), st, sel, U.Str.get(live, sel), caret, S.Nui.mark(n), focus, S.Blink.on(n), x0, x1, h, sc, pa,
21742203
U.Str.get(nf, "models"), U.Flag.get(op, "models"), U.Ui.pending(S.Nui.ui(n), sel), U.Ui.skills(S.Nui.ui(n)), U.Side.now(S.Nui.ui(n)),
21752204
U.Ui.atts(S.Nui.ui(n), sel), U.Ui.uploading(S.Nui.ui(n), sel), path, nf, U.Ui.deleting(S.Nui.ui(n)), TSel.of(U.Ui.scratch(S.Nui.ui(n), "@ts"), sel)))
21762205

‎src/app/nui.bend‎

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1274,12 +1274,81 @@ def Nui.move.k(drag: Bool, +n: Nui, +x: U32, +y: U32) -> Step:
12741274
case False{}:
12751275
Row.move(Bool.not(String.is_empty(Row.id(n))), n, x, y)
12761276

1277+
# The composer grows with its draft from 2 to Cs.most() lines; a longer
1278+
# draft scrolls. Its first shown line follows the caret unless the wheel
1279+
# chose one: "@cs" holds that choice while the field, thread and caret it
1280+
# was made with do (as "@mark" does). Layout names the composer's current
1281+
# top and furthest top in a zero-size "cs" region ("top,max").
1282+
1283+
def Cs.most() -> Nat:
1284+
8n
1285+
1286+
# how many lines the composer shows for a draft of n wrapped lines
1287+
def Cs.rows(+n: Nat) -> Nat:
1288+
Bool.pick(Nat, Nat.is_le(n, 2n), 2n, Bool.pick(Nat, Nat.is_ge(n, Cs.most()), Cs.most(), n))
1289+
1290+
# the first shown line that keeps the caret's line (crow) in view
1291+
def Cs.follow(+n: Nat, +crow: Nat) -> Nat:
1292+
+m = Nat.sub(n, Cs.rows(n))
1293+
+c = Nat.sub(crow, Nat.sub(Cs.rows(n), 1n))
1294+
Bool.pick(Nat, Nat.is_le(m, c), m, c)
1295+
1296+
# the first shown line: the wheel's choice (held) while it holds, else
1297+
# the caret's; never past the last full view
1298+
def Cs.top(+held: String, +n: Nat, +crow: Nat) -> Nat:
1299+
+m = Nat.sub(n, Cs.rows(n))
1300+
+t = Maybe.default(&2, Nat, Nat.read(held), Cs.follow(n, crow))
1301+
Bool.pick(Nat, Nat.is_le(t, m), t, m)
1302+
1303+
# the first shown line after a wheel notch, 3 lines, within 0..max
1304+
def Cs.wheel(up: Bool, +top: Nat, +max: Nat) -> Nat:
1305+
match up:
1306+
case True{}:
1307+
Nat.sub(top, 3n)
1308+
case False{}:
1309+
Bool.pick(Nat, Nat.is_le(Nat.add(top, 3n), max), Nat.add(top, 3n), max)
1310+
1311+
# the wheel's choice while it still holds ("" when it does not)
1312+
def Cs.held(+n: Nui) -> String:
1313+
+r = U.Ui.scratch(Nui.ui(n), "@cs")
1314+
Bool.pick(String, String.starts_with(r, Mark.sig(n)), String.drop(r, String.length(Mark.sig(n))), "")
1315+
1316+
def Cs.region(hs: List<&2, Hit>) -> String:
1317+
match hs:
1318+
case Nil{}:
1319+
""
1320+
case Hit{_, _, _, _, +a, +v} <> t:
1321+
Bool.pick(String, String.eq(a, "cs"), v, Cs.region(t))
1322+
1323+
def Cs.num(+v: String, +i: Nat) -> Nat:
1324+
Maybe.default(&2, Nat, Nat.read(Maybe.default(&2, String, List.get(&2, String, String.split(v, ','), i), "")), 0n)
1325+
1326+
def Cs.over(m: Maybe<&2, Hit>) -> Bool:
1327+
match m:
1328+
case Some{Hit{_, _, _, _, +a, +v}}:
1329+
Bool.and(String.eq(a, "focus"), String.eq(v, "composer"))
1330+
case None{}:
1331+
False{}
1332+
1333+
def Cs.spin.k(on: Bool, +n: Nui, +x: U32, +dir: U32, +v: String) -> Step:
1334+
match on:
1335+
case True{}:
1336+
Step{Nui.with_ui(n, U.Ui.scratch_set(Nui.ui(n), "@cs", Mark.sig(n) ++ Nat.show(Cs.wheel(U32.is_eq(dir, 0), Cs.num(v, 0n), Cs.num(v, 1n))))), Nil{}, True{}}
1337+
case False{}:
1338+
Nui.wheel(n, x, dir)
1339+
1340+
# the wheel over a composer too short for its draft scrolls the draft;
1341+
# anywhere else it moves the sidebar or the timeline
1342+
def Cs.spin(+n: Nui, +x: U32, +y: U32, +dir: U32) -> Step:
1343+
+v = Cs.region(Nui.hits(n))
1344+
Cs.spin.k(Bool.and(Cs.over(Hit.find(Nui.hits(n), x, y)), Nat.is_gt(Cs.num(v, 1n), 0n)), n, x, dir, v)
1345+
12771346
def Nui.spin(viewer: Bool, +n: Nui, +x: U32, +y: U32, +dir: U32) -> Step:
12781347
match viewer:
12791348
case True{}:
12801349
Nui.view_wheel(n, x, y, dir)
12811350
case False{}:
1282-
Nui.wheel(n, x, dir)
1351+
Cs.spin(n, x, y, dir)
12831352

12841353
def Nui.ms_of(n: Nui) -> Nat:
12851354
match n:

‎src/web/style.css‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ button.fold:hover { color: var(--text); }
9797
button.fold span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
9898
.working { color: var(--faint); font-size: 12px; }
9999
.composer { position: relative; display: flex; flex-direction: column; gap: 6px; padding: 10px 16px 14px; border-top: 1px solid var(--line); }
100-
.composer textarea { resize: none; background: var(--panel); border: 1px solid var(--line); padding: 8px 10px; min-height: 60px; max-height: 40vh; }
100+
.composer textarea { resize: none; background: var(--panel); border: 1px solid var(--line); padding: 8px 10px; min-height: 60px; max-height: 40vh; field-sizing: content; overflow-y: auto; }
101101
.composer-foot { display: flex; justify-content: space-between; align-items: center; }
102102
.model-chip { background: none; border-color: transparent; color: var(--dim); padding-left: 0; }
103103
.picker { position: absolute; bottom: 100%; left: 16px; display: flex; flex-direction: column; min-width: 200px; background: var(--panel); border: 1px solid var(--line); padding: 4px; }

‎test/cscroll_test.bend‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Base
2+
import ./check.bend as C
3+
import ../src/app/nui.bend as N
4+
5+
# The window's composer: how many lines it shows for a draft, which line
6+
# comes first (the caret's, or the wheel's choice), and a wheel notch.
7+
8+
def main() -> IO(Unit):
9+
do IO<Unit>:
10+
C.Check.str("empty shows two", Nat.show(N.Cs.rows(0n)), "2")
11+
C.Check.str("grows with the draft", Nat.show(N.Cs.rows(5n)), "5")
12+
C.Check.str("stops at most", Nat.show(N.Cs.rows(40n)), "8")
13+
C.Check.str("short draft never scrolls", Nat.show(N.Cs.top("", 5n, 4n)), "0")
14+
C.Check.str("caret at start shows the start", Nat.show(N.Cs.top("", 20n, 0n)), "0")
15+
C.Check.str("caret at the end shows the end", Nat.show(N.Cs.top("", 20n, 19n)), "12")
16+
C.Check.str("caret mid-way is the last line shown", Nat.show(N.Cs.top("", 20n, 10n)), "3")
17+
C.Check.str("wheel choice holds", Nat.show(N.Cs.top("5", 20n, 19n)), "5")
18+
C.Check.str("wheel choice clamps", Nat.show(N.Cs.top("30", 20n, 0n)), "12")
19+
C.Check.str("wheel up", Nat.show(N.Cs.wheel(True{}, 5n, 12n)), "2")
20+
C.Check.str("wheel up stops at 0", Nat.show(N.Cs.wheel(True{}, 1n, 12n)), "0")
21+
C.Check.str("wheel down", Nat.show(N.Cs.wheel(False{}, 5n, 12n)), "8")
22+
C.Check.str("wheel down stops at max", Nat.show(N.Cs.wheel(False{}, 11n, 12n)), "12")

0 commit comments

Comments
 (0)