Skip to content

Commit

Permalink
Merge branch 'autosave4real' of github.com:hazelgrove/tylr into copyp…
Browse files Browse the repository at this point in the history
…aste
  • Loading branch information
disconcision committed Nov 5, 2024
2 parents d61517f + 1ad95b7 commit 39bb3b0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 46 deletions.
74 changes: 28 additions & 46 deletions src/core/structure/Cell.re
Original file line number Diff line number Diff line change
Expand Up @@ -278,54 +278,36 @@ module Space = {
};

let merge = (l: t, ~fill=empty, r: t) => {
if (!is_space(l) || !is_space(r)) {
if (!is_space(l) || Option.is_some(fill.meld) || !is_space(r)) {
raise(Invalid_argument("Cell.Space.merge"));
};
let marks =
r.marks
|> (
switch (l.meld) {
| None => Fun.id
| Some(m) =>
let shift = 2 * List.length(Meld.tokens(m));
Marks.map_paths(
fun
| [] =>
// assert(r.meld == None);
[shift]
| [hd, ...tl] => [hd + shift, ...tl],
);
}
)
|> Marks.union(
switch (l.meld) {
| Some(m) =>
let n = 2 * List.length(Meld.tokens(m));
Marks.cons(n, fill.marks);
| None => fill.marks
},
)
|> Marks.union(l.marks);
let meld =
Options.merge(
l.meld,
r.meld,
~f=(Meld.M(l, w_l, m_l), Meld.M(m_r, w_r, r)) => {
let m = {
...fill,
marks:
Marks.mk(
~degrouted=
m_l.marks.degrouted
|| fill.marks.degrouted
|| m_r.marks.degrouted,
(),
),
};
Meld.M(l, Wald.append(w_l, m, w_r), r);
},
);
Base.{marks, meld};
switch (g(l), g(r)) {
| (None, None) =>
let marks = Marks.union_all([l.marks, fill.marks, r.marks]);
Base.mk(~marks, ());
| (None, Some(_)) =>
let marks =
Marks.(union_all([cons(0, l.marks), cons(0, fill.marks), r.marks]));
{...r, marks};
| (Some(m_l), None) =>
let shift = 2 * List.length(Meld.tokens(m_l));
let marks =
Marks.(
union_all([
l.marks,
cons(shift, fill.marks),
cons(shift, r.marks),
])
);
{...l, marks};
| (Some(M(c_l, w_l, c_m_l)), Some(M(c_m_r, w_r, c_r))) =>
assert(c_m_l.meld == None && c_m_r.meld == None);
let c_m = {
...fill,
marks: Marks.union_all([c_m_l.marks, fill.marks, c_m_r.marks]),
};
put(M(c_l, Wald.append(w_l, c_m, w_r), c_r));
};
};
};

Expand Down
2 changes: 2 additions & 0 deletions src/stds/Strings.re
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ let count = c => Base.String.count(~f=(==)(c));
let split = Base.String.split;

let rev = Base.String.rev;

let chop_prefix = Base.String.chop_prefix;

0 comments on commit 39bb3b0

Please sign in to comment.