Skip to content

Commit e231d5d

Browse files
committed
update the molding on insertion behavior and change the grouting around a newline
1 parent bc4e072 commit e231d5d

File tree

3 files changed

+144
-60
lines changed

3 files changed

+144
-60
lines changed

src/core/parser/Grouter.re

Lines changed: 100 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,21 @@ let rec split_cell_padding = (~side: Dir.t, c: Cell.t) =>
88
switch (Cell.get(c)) {
99
| None => Cell.(empty, c)
1010
| Some(m) when Option.is_some(Meld.Space.get(m)) =>
11-
Cell.Space.split(~side, c) |> Option.value(~default=(c, Cell.empty))
11+
switch (Cell.Space.split(~side, c)) {
12+
| Some(s) => s
13+
| None =>
14+
// P.show("Cell.space.split results in none with c:", Cell.show(c));
15+
switch (side) {
16+
| L =>
17+
// P.show("split_cell_padding edge left c", Cell.show(c));
18+
(c, Cell.empty) /* |> Option.value(~default=) */
19+
| R =>
20+
let (c, rest) = Cell.split_edge(~side=L, c);
21+
// P.show("split_cell_padding split_edge right c", Cell.show(c));
22+
// P.show("rest", Cell.show(rest));
23+
(rest, c);
24+
}
25+
}
1226
| Some(M(l, w, r)) =>
1327
switch (side) {
1428
| L =>
@@ -61,21 +75,48 @@ module Cells = {
6175
// where c holds the meld {} " " {|} " " {}, the caret | will be pulled
6276
// left side of any grout inserted between the spaces, which is afaict always
6377
// what we want after any modification (except maybe forward delete)
64-
let (l, cs) =
65-
switch (cs) {
66-
| [c, ...cs] =>
67-
let (l, c) = split_cell_padding(~side=L, c);
68-
(l, cons(c, cs));
69-
| [] => (Cell.empty, cs)
70-
};
71-
let (cs, r) =
72-
switch (Lists.Framed.ft(cs)) {
73-
| Some((cs, c)) =>
74-
let (r, c) = split_cell_padding(~side=R, c);
75-
(List.rev(cons(c, cs)), r);
76-
| None => (cs, Cell.empty)
77-
};
78-
(l, squash(cs), r);
78+
switch (cs) {
79+
| [c] when Cell.Space.is_space(c) =>
80+
// P.log("Special split_padding case");
81+
// P.show("r: ", Cell.show(r));
82+
// P.show("c: ", Cell.show(c));
83+
84+
let (cs, r) =
85+
switch (Lists.Framed.ft(cs)) {
86+
| Some((cs, c)) =>
87+
let (r, c) = split_cell_padding(~side=R, c);
88+
(List.rev(cons(c, cs)), r);
89+
| None => (cs, Cell.empty)
90+
};
91+
// P.show("cs: ", show(cs));
92+
// P.show("r: ", Cell.show(r));
93+
let (l, cs) =
94+
switch (cs) {
95+
| [c, ...cs] =>
96+
let (l, c) = split_cell_padding(~side=L, c);
97+
(l, cons(c, cs));
98+
| [] => (Cell.empty, cs)
99+
};
100+
// P.show("l: ", Cell.show(l));
101+
// P.show("final cs: ", show(cs));
102+
(l, squash(cs), r);
103+
| _ =>
104+
let (l, cs) =
105+
switch (cs) {
106+
| [c, ...cs] =>
107+
let (l, c) = split_cell_padding(~side=L, c);
108+
(l, cons(c, cs));
109+
| [] => (Cell.empty, cs)
110+
};
111+
let (cs, r) =
112+
switch (Lists.Framed.ft(cs)) {
113+
| Some((cs, c)) =>
114+
let (r, c) = split_cell_padding(~side=R, c);
115+
(List.rev(cons(c, cs)), r);
116+
| None => (cs, Cell.empty)
117+
};
118+
(l, squash(cs), r);
119+
};
79120
};
80121

81122
// output Some(b) if bounded, where b indicates whether pre/post grout needed
@@ -112,12 +153,12 @@ let rec degrout = (c: Cell.t): Cells.t =>
112153
switch (Cell.get(c)) {
113154
//open the cell
114155
| Some(M(l, w, r)) when Option.is_some(Wald.is_grout(w)) =>
115-
P.log("degrout hit some case");
156+
// P.log("degrout hit some case");
116157
//pull the inner cells out ("base")
117158
let W((toks, cells)) = w;
118-
P.show("l: ", Cell.show(l));
119-
P.show("w: ", Wald.show(w));
120-
P.show("r: ", Cell.show(r));
159+
// P.show("l: ", Cell.show(l));
160+
// P.sexp("w: ", Wald.sexp_of_t(w));
161+
// P.show("r: ", Cell.show(r));
121162
List.iter(Effects.remove, toks);
122163
// we wish to maximally stabilize grout positioning, ie grout that is removed
123164
// in this pass, if reinserted, should be reinserted in the same position.
@@ -137,7 +178,9 @@ let rec degrout = (c: Cell.t): Cells.t =>
137178
P.show("degrout cells_l", Cell.show(l));
138179
let l = Cell.mark_degrouted(l, ~side=R);
139180
[l];
140-
| _ => [l, ...cells]
181+
| _ =>
182+
let l = Cell.mark_degrouted(l, ~side=R);
183+
[l, ...cells];
141184
};
142185
let cells_lr =
143186
switch (Lists.Framed.ft(cells_l)) {
@@ -149,7 +192,9 @@ let rec degrout = (c: Cell.t): Cells.t =>
149192
let r = Cell.mark_degrouted(~side=L, r);
150193
P.show("degrout cells_r", Cell.show(l));
151194
[r];
152-
| _ => cells_l @ [r]
195+
| _ =>
196+
let r = Cell.mark_degrouted(r, ~side=L);
197+
cells_l @ [r];
153198
};
154199
List.concat_map(degrout, cells_lr);
155200
| _ => [c]
@@ -188,10 +233,10 @@ let fill_default =
188233
let fill_swing = (cs: Cells.t, sw: Walk.Swing.t, ~from: Dir.t) => {
189234
let cs = Dir.pick(from, (List.rev, Fun.id), cs);
190235
// if (dbg^) {
191-
// P.log("--- Grouter.fill_swing");
192-
// P.show("from", Dir.show(from));
193-
// P.show("sw", Walk.Swing.show(sw));
194-
// P.show("cs", Cells.show(cs));
236+
P.log("--- Grouter.fill_swing");
237+
P.show("from", Dir.show(from));
238+
P.show("sw", Walk.Swing.show(sw));
239+
P.show("cs", Cells.show(cs));
195240
// };
196241
let (bot, top) = Walk.Swing.(bot(sw), top(sw));
197242
switch (bot) {
@@ -244,28 +289,29 @@ let fill_swing = (cs: Cells.t, sw: Walk.Swing.t, ~from: Dir.t) => {
244289
//NOTE: split padding is a possible candidate for newline bug fix
245290
switch (Cells.split_padding(cs)) {
246291
| (l, cs, r) when List.for_all(Cell.Space.is_space, cs) =>
247-
if (dbg^) {
248-
P.log("--- Grouter.fill_swing/Tile/all space");
249-
P.show("l", Cell.show(l));
250-
P.show("cs", Cells.show(cs));
251-
P.show("r", Cell.show(r));
252-
};
292+
// if (dbg^) {
293+
P.log("--- Grouter.fill_swing/Tile/all space");
294+
P.show("l", Cell.show(l));
295+
P.show("cs", Cells.show(cs));
296+
P.show("r", Cell.show(r));
297+
// };
253298
// prioritize getting any carets in cs over to the left for now.
254299
// todo: parametrize this based on parsing mode
255300
let l = List.hd(Cells.squash([l, ...cs]));
301+
P.show("squashed l", Cell.show(l));
256302
// let r = List.hd(Cells.squash(cs @ [r]));
257-
let r = Cell.pad(~l, fill_default(bot), ~r);
258-
if (dbg^) {
259-
P.show("padded", Cell.show(r));
260-
};
261-
r;
303+
let ret = Cell.pad(~l, fill_default(bot), ~r);
304+
// if (dbg^) {
305+
P.show("padded", Cell.show(ret));
306+
// };
307+
ret;
262308
| (l, cs, r) =>
263-
if (dbg^) {
264-
P.log("--- Grouter.fill_swing/Tile/not all space");
265-
P.show("l", Cell.show(l));
266-
P.show("cs", Cells.show(cs));
267-
P.show("r", Cell.show(r));
268-
};
309+
// if (dbg^) {
310+
P.log("--- Grouter.fill_swing/Tile/not all space");
311+
P.show("l", Cell.show(l));
312+
P.show("cs", Cells.show(cs));
313+
P.show("r", Cell.show(r));
314+
// };
269315
//cells is list of children cells for target grout form
270316
//cons/scnoc here effectively add l/r as children of prefix/postfix grout
271317
let cells =
@@ -318,12 +364,12 @@ let fill_swing = (cs: Cells.t, sw: Walk.Swing.t, ~from: Dir.t) => {
318364

319365
let fill_swings =
320366
(~repair, ~from, cells: list(Cell.t), swings: list(Walk.Swing.t)) => {
321-
if (dbg^) {
322-
P.log("--- Grouter.fill_swings");
323-
P.show("from", Dir.show(from));
324-
P.show("cells", Cells.show(Dir.pick(from, (List.rev, Fun.id), cells)));
325-
// P.show("swings", Fmt.to_to_string(Fmt.list(Walk.Swing.pp), swings));
326-
};
367+
// if (dbg^) {
368+
P.log("--- Grouter.fill_swings");
369+
// P.show("from", Dir.show(from));
370+
// P.show("cells", Cells.show(Dir.pick(from, (List.rev, Fun.id), cells)));
371+
// P.show("swings", Fmt.to_to_string(Fmt.list(Walk.Swing.pp), swings));
372+
// };
327373
cells
328374
|> Dir.pick(from, (List.rev, Fun.id))
329375
|> (repair ? List.concat_map(degrout) : Fun.id)
@@ -355,15 +401,14 @@ let fill = (~repair, ~from, cs, (swings, stances): Walk.t) => {
355401
//cs should be a singleton cell
356402
let pick = (~repair=false, ~from: Dir.t, cs: list(Cell.t), ws: list(Walk.t)) => {
357403
// if (dbg^) {
358-
// P.log("--- Grouter.pick");
404+
P.log("--- Grouter.pick");
359405
// P.show("from", Dir.show(from));
360406
// P.show("cs", Cells.show(cs));
361407
// P.log("ws");
362408
// ws |> List.iter(w => P.show("w", Walk.show(w)));
363409
// };
364-
Oblig.Delta.minimize(
365-
~to_zero=!repair,
366-
fill(~repair, ~from, cs),
367-
ws,
368-
);
410+
let r =
411+
Oblig.Delta.minimize(~to_zero=!repair, fill(~repair, ~from, cs), ws);
412+
P.log("Grouter.pick done");
413+
r;
369414
};

src/core/parser/Melder.re

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ let complete_wald = (~side: Dir.t, ~fill=Cell.empty, w: Wald.t): Terr.t => {
2323
};
2424
// onto confusing here when considered alone, same onto piped from push(~onto)
2525
let complete_terr = (~onto: Dir.t, ~fill=Cell.empty, terr: Terr.t): Cell.t => {
26+
P.log("--- Melder.complete_terr");
27+
P.show("onto", Dir.show(onto));
28+
P.show("fill", Cell.show(fill));
29+
P.show("terr", Terr.show(terr));
30+
2631
let orient = Dir.pick(onto, (Meld.rev, Fun.id));
2732
let exited = Walker.exit(~from=onto, Node(Terr.face(terr).mtrl));
2833
let grouted = Grouter.pick(~repair=true, ~from=onto, [fill], exited);
2934
// if (debug^) {
30-
// P.log("--- Melder.complete_terr");
31-
// P.show("onto", Dir.show(onto));
32-
// P.show("fill", Cell.show(fill));
33-
// P.show("terr", Terr.show(terr));
3435
// };
3536
switch (grouted) {
3637
| Some(grouted) =>

src/core/structure/Cell.re

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,35 @@ let get = (~distribute=true, c: t) =>
225225
(distribute ? distribute_marks : Fun.id)(c).meld;
226226
let put = (meld: Meld.t(_)) => aggregate_marks(mk(~meld, ()));
227227

228+
let rec split_edge = (~side: Dir.t, c: t) =>
229+
switch (get(c)) {
230+
| None =>
231+
// P.log("------ split_edge none ------");
232+
// P.show("c: ", show(c));
233+
(c, {
234+
...c,
235+
marks: {
236+
...c.marks,
237+
cursor: None,
238+
},
239+
})
240+
//NOTE: this is somehow the problem - the l & r are empty
241+
| Some(M(l, w, r)) =>
242+
// P.log("----- split_edge some ---- from: " ++ Dir.show(side));
243+
// P.sexp("init c: ", sexp_of_t(c));
244+
// P.show("r: ", show(r));
245+
// P.show("w: ", Wald.show(Token.pp, pp, w));
246+
// P.show("marks: ", Marks.show(c.marks));
247+
// P.sexp("l: ", sexp_of_t(l));
248+
let (d, b) = Dir.order(side, (l, r));
249+
// P.show("recursive split_edge d:", show(d));
250+
let (c, d) = split_edge(~side, d);
251+
// P.show("post rec split_edge c:", show(c));
252+
let (l, r) = Dir.order(side, (d, b));
253+
let rest = put(M(l, w, r));
254+
(c, rest);
255+
};
256+
228257
let caret = (car: Path.Caret.t) =>
229258
mk(~marks=Marks.mk(~cursor=Point(car), ()), ());
230259

@@ -293,7 +322,9 @@ module Space = {
293322
cs
294323
|> Lists.split_while(~f=(c: t) => Path.Map.is_empty(c.marks.degrouted));
295324
switch (cs_d, cs_b) {
325+
//we failed to find a degrouted mark
296326
| (_, []) => None
327+
//immediately encounter degrout on the "d" side
297328
| ([], [b_hd, ...b_tl]) =>
298329
//ensuring no cursor duplication in cells with degrouted mark
299330
let b_hd_dup = {
@@ -303,21 +334,28 @@ module Space = {
303334
cursor: None,
304335
},
305336
};
337+
338+
//logic to handle the cursor jumping when coming from the left
339+
let (b_hd, b_hd_dup) = Dir.order(d, (b_hd, b_hd_dup));
340+
306341
let rest =
307342
Meld.of_chain(([b_hd_dup, ...b_tl], ts))
308343
|> Dir.pick(d, (Fun.id, Meld.rev))
309344
|> put;
310345
Some((b_hd, rest));
311346
| ([_, ..._], [b_hd, ...b_tl]) =>
312347
let (ts_d, ts_b) = Lists.split_n(ts, List.length(cs_d));
313-
let cs_d = cs_d @ [b_hd];
314348
let b_hd_dup = {
315349
...b_hd,
316350
marks: {
317351
...b_hd.marks,
318352
cursor: None,
319353
},
320354
};
355+
//logic to handle the cursor jumping when coming from the left
356+
let (b_hd, b_hd_dup) = Dir.order(d, (b_hd, b_hd_dup));
357+
358+
let cs_d = cs_d @ [b_hd];
321359
let cs_b = [b_hd_dup, ...b_tl];
322360
let split =
323361
(cs_d, ts_d)

0 commit comments

Comments
 (0)