Skip to content

Commit 60a2653

Browse files
committed
Merge branch 'remold-insertion_grouting-newline' into grammar_filter_extensions
2 parents e231d5d + 65a2576 commit 60a2653

File tree

11 files changed

+133
-24
lines changed

11 files changed

+133
-24
lines changed

src/core/editor/Modify.re

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -594,9 +594,9 @@ let apply_changes =
594594

595595
let apply_remold = (changes, ctx) => {
596596
open Choice.Syntax;
597-
// P.log("--- Modify.apply_remold");
598-
// P.show("changes", Changes.show(changes));
599-
// P.show("ctx", Ctx.show(ctx));
597+
P.log("--- Modify.apply_remold");
598+
P.show("changes", Changes.show(changes));
599+
P.show("ctx", Ctx.show(ctx));
600600
let+ changed = apply_changes(changes, ctx);
601601
() => {
602602
open Options.Syntax;

src/core/material/precompiled/enter_l_map.txt

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

src/core/material/precompiled/enter_r_map.txt

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

src/core/material/precompiled/nts.txt

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

src/core/material/precompiled/stances.txt

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

src/core/material/precompiled/walk_l_map.txt

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

src/core/material/precompiled/walk_l_no_filter_map.txt

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

src/core/material/precompiled/walk_r_map.txt

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

src/core/material/precompiled/walk_r_no_filter_map.txt

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

src/core/parser/Grouter.re

Lines changed: 65 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
3758
module 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+
203236
let 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
402435
let 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

Comments
 (0)