@@ -11,15 +11,10 @@ let rec split_cell_padding = (~side: Dir.t, c: Cell.t) =>
1111 switch (Cell . Space . split(~side, c)) {
1212 | Some (s ) => s
1313 | None =>
14- // P.show("Cell.space.split results in none with c:", Cell.show(c));
1514 switch (side) {
16- | L =>
17- // P.show("split_cell_padding edge left c", Cell.show(c));
18- (c, Cell . empty) /* |> Option.value(~default=) */
15+ | L => (c, Cell . empty)
1916 | R =>
2017 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));
2318 (rest, c);
2419 }
2520 }
@@ -34,6 +29,32 @@ let rec split_cell_padding = (~side: Dir.t, c: Cell.t) =>
3429 }
3530 };
3631
32+ let rec extract_cell_padding = (~side: Dir . t , c: Cell . t ) =>
33+ switch (Cell . get(c)) {
34+ | None => (Cell . empty, c)
35+ | Some (m ) when Option . is_some(Meld . Space . get(m)) =>
36+ P . show("hit extract_cell_padding.space" , Cell . show(c));
37+ switch (Cell . Space . split_cursor(c)) {
38+ | Some (s ) =>
39+ P . show(
40+ "hit extract_cell_padding.split_cursor some fst: " ,
41+ Cell . show(fst(s)),
42+ );
43+ P . show("snd: " , Cell . show(snd(s)));
44+ s;
45+ | None => (c, Cell . empty)
46+ };
47+ | Some (M (l , w , r )) =>
48+ switch (side) {
49+ | L =>
50+ let (p_l , l ) = extract_cell_padding(~side= L , l);
51+ Cell . (p_l, put(M (l, w, r)));
52+ | R =>
53+ let (p_r , r ) = extract_cell_padding(r, ~side= R );
54+ Cell . (p_r, put(M (l, w, r)));
55+ }
56+ };
57+
3758module Cells = {
3859 [@ deriving (show({with_path: false }), sexp, yojson)]
3960 type t = list (Cell . t );
@@ -77,28 +98,20 @@ module Cells = {
7798 // what we want after any modification (except maybe forward delete)
7899 switch (cs) {
79100 | [ 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-
84101 let (cs , r ) =
85102 switch (Lists . Framed . ft(cs)) {
86103 | Some ((cs , c )) =>
87104 let (r , c ) = split_cell_padding(~side= R , c);
88105 (List . rev(cons(c, cs)), r);
89106 | None => (cs, Cell . empty)
90107 };
91- // P.show("cs: ", show(cs));
92- // P.show("r: ", Cell.show(r));
93108 let (l , cs ) =
94109 switch (cs) {
95110 | [ c , ... cs ] =>
96111 let (l , c ) = split_cell_padding(~side= L , c);
97112 (l, cons(c, cs));
98113 | [] => (Cell . empty, cs)
99114 };
100- // P.show("l: ", Cell.show(l));
101- // P.show("final cs: ", show(cs));
102115 (l, squash(cs), r);
103116 | _ =>
104117 let (l , cs ) =
@@ -200,6 +213,26 @@ let rec degrout = (c: Cell.t): Cells.t =>
200213 | _ => [ c]
201214 };
202215
216+ let extract_newline = (~from: Dir . t , cs: Cells . t ) => {
217+ switch (cs) {
218+ | [ c ] =>
219+ switch (from) {
220+ | L =>
221+ let (pad , c ) = extract_cell_padding(~side= R , c);
222+ ([ c] , pad);
223+ | R => (cs, Cell . empty)
224+ }
225+ | _ => (cs, Cell . empty)
226+ };
227+ };
228+
229+ let reinsert_newline = (~from: Dir . t , grouted: Grouted . t , nl: Cell . t ) => {
230+ switch (from) {
231+ | L => Chain . map_hd(Tuples . map_snd(Cell . pad(~r= nl)), grouted)
232+ | R => grouted
233+ };
234+ };
235+
203236let fill_default =
204237 fun
205238 | Mtrl . Space (_ ) => Cell . dirty
@@ -400,15 +433,26 @@ let fill = (~repair, ~from, cs, (swings, stances): Walk.t) => {
400433// given walks according to from.
401434// cs should be a singleton cell
402435let pick = (~repair= false , ~from: Dir . t , cs: list (Cell . t ), ws: list (Walk . t )) => {
436+ open Options . Syntax ;
403437 // if (dbg^) {
404438 P . log("--- Grouter.pick" );
405- // P.show("from", Dir.show(from));
406- // P.show("cs", Cells.show(cs));
407- // P.log("ws");
408- // ws |> List.iter(w => P.show("w", Walk.show(w)));
439+ P . show("from" , Dir . show(from));
440+ P . show("cs" , Cells . show(cs));
441+ // P.log("ws");
442+ // ws |> List.iter(w => P.show("w", Walk.show(w)));
409443 // };
410- let r =
444+
445+ let (cs , nl ) = extract_newline(~from, cs);
446+
447+ P . show("cs post newline extract" , Cells . show(cs));
448+ P . show("nl" , Cell . show(nl));
449+
450+ let + grouted =
411451 Oblig . Delta . minimize (~to_zero =!repair , fill (~repair , ~from , cs ), ws );
412- P . log("Grouter.pick done" );
413- r;
452+
453+ P . show("grouted no nl" , Grouted . show(grouted));
454+
455+ let reinsert = reinsert_newline(~from, grouted, nl);
456+ P . show("grouted with nl " , Grouted . show(reinsert));
457+ reinsert;
414458};
0 commit comments