Skip to content

Commit

Permalink
have unroll emit final cell in case it has caret and propagate that a…
Browse files Browse the repository at this point in the history
…s fill when inserting pending ghosts at newline
  • Loading branch information
dm0n3y committed Oct 3, 2024
1 parent 0148487 commit d9c09c0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
13 changes: 7 additions & 6 deletions src/core/editor/Modify.re
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ let rec remold = (~fill=Cell.dirty, ctx: Ctx.t): (Cell.t, Ctx.t) => {
switch (Slope.unlink(r.slope)) {
| Some((tok, cell, up)) when Token.Grout.is(tok) =>
Effects.remove(tok);
let up = Slope.cat(Slope.Up.unroll(cell), up);
let up = Slope.cat(snd(Slope.Up.unroll(cell)), up);
let r = {...r, slope: up};
Some(remold(~fill, Ctx.link_stacks((l, r), tl)));
| _ => None
Expand All @@ -126,26 +126,27 @@ let rec remold = (~fill=Cell.dirty, ctx: Ctx.t): (Cell.t, Ctx.t) => {
(cell, ctx);
| [hd_up, ...tl_up] =>
// insert any pending ghosts if next terr has newlines
let l =
let (l, fill) =
Terr.tokens(hd_up)
|> List.map(Token.height)
|> List.fold_left((+), 0) == 0
? l
? (l, fill)
: {
let bounds = (l.bound, r.bound);
let cell =
Melder.complete_bounded(~bounds, ~onto=L, l.slope, ~fill);
{...l, slope: Slope.Dn.unroll(cell)};
let (fill, slope) = Slope.Dn.unroll(cell);
({...l, slope}, fill);
};
let r_tl = {...r, slope: tl_up};
let (hd_w, tl_w) = Wald.uncons(hd_up.wald);
let unrolled = () =>
Chain.Affix.uncons(tl_w)
|> Option.map(((cell, (ts, cs))) =>
Slope.Up.unroll(cell)
snd(Slope.Up.unroll(cell))
@ [{wald: Wald.mk(ts, cs), cell: hd_up.cell}]
)
|> Option.value(~default=Slope.Up.unroll(hd_up.cell));
|> Option.value(~default=snd(Slope.Up.unroll(hd_up.cell)));
switch (Molder.mold(l, ~fill, Token.unmold(hd_w))) {
| None =>
tl
Expand Down
14 changes: 11 additions & 3 deletions src/core/editor/Zigg.re
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,20 @@ let put_dn = dn => map_dn(_ => dn);
let of_dn = dn =>
Stds.Lists.Framed.ft(dn)
|> Option.map(((dn, t: Terr.t)) =>
mk(~up=Slope.Up.unroll(t.cell), Wald.rev(t.wald), ~dn=List.rev(dn))
mk(
~up=snd(Slope.Up.unroll(t.cell)),
Wald.rev(t.wald),
~dn=List.rev(dn),
)
);
let of_up = up =>
Stds.Lists.Framed.ft(up)
|> Option.map(((up, t: Terr.t)) =>
mk(~up=List.rev(up), Wald.rev(t.wald), ~dn=Slope.Up.unroll(t.cell))
mk(
~up=List.rev(up),
Wald.rev(t.wald),
~dn=snd(Slope.Up.unroll(t.cell)),
)
);

let roll = (~l=Cell.empty, ~r=Cell.empty, {up, top, dn}: t) =>
Expand Down Expand Up @@ -160,7 +168,7 @@ let pull = (~side as d: Dir.t, zigg: t): (Token.t, option(t)) => {
switch (rest) {
| ([], _) => (tok, Dir.pick(b, (of_up, of_dn), s_b))
| ([c, ...cs], ts) =>
let s_d = Slope.unroll(~from=b, c);
let (_, s_d) = Slope.unroll(~from=b, c);
(tok, Some(unorient(d, (s_d, Wald.mk(ts, cs), s_b))));
};
};
Expand Down
4 changes: 3 additions & 1 deletion src/core/editor/Zipper.re
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ let mk = (~cur=Cursor.point(Caret.focus()), ctx) => Base.{cur, ctx};

let unroll = (~ctx=Ctx.empty, side: Dir.t, cell: Cell.t) => {
let f_open =
side == L ? ([], Slope.Up.unroll(cell)) : (Slope.Dn.unroll(cell), []);
side == L
? ([], snd(Slope.Up.unroll(cell)))
: (snd(Slope.Dn.unroll(cell)), []);
Ctx.map_hd(Frame.Open.cat(f_open), ctx);
};
let mk_unroll = (~ctx=Ctx.empty, side: Dir.t, cell: Cell.t) =>
Expand Down
6 changes: 3 additions & 3 deletions src/core/structure/Slope.re
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ let fold: (('acc, Terr.t) => 'acc, 'acc, t) => 'acc = List.fold_left;
let unroll = (~from: Dir.t, cell: Cell.t) => {
let rec go = (cell: Cell.t, unrolled) =>
switch (Cell.get(cell)) {
| None => unrolled
| None => (cell, unrolled)
| Some(M(l, w, r)) =>
let (cell, terr) =
switch (from) {
Expand All @@ -93,10 +93,10 @@ let pull_terr = (~from: Dir.t, terr: Terr.t): (Token.t, t) => {
let (tok, rest) = Wald.uncons(terr.wald);
let slope =
switch (rest) {
| ([], _) => unroll(~from, terr.cell)
| ([], _) => snd(unroll(~from, terr.cell))
| ([cell, ...cells], toks) =>
let terr = {...terr, wald: Wald.mk(toks, cells)};
cat(unroll(~from, cell), [terr]);
cat(snd(unroll(~from, cell)), [terr]);
};
(tok, slope);
};
Expand Down
1 change: 1 addition & 0 deletions src/core/structure/Token.re
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module Base = {
let put_marks = (marks, tok) => {...tok, marks};
let clear_marks = tok => put_marks(None, tok);
let pop_marks = tok => (tok.marks, clear_marks(tok));
let height = tok => Strings.count('\n', tok.text);
};

module Molded = {
Expand Down

0 comments on commit d9c09c0

Please sign in to comment.