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 4, 2024
2 parents 8a735d5 + f553a16 commit d61517f
Show file tree
Hide file tree
Showing 12 changed files with 153 additions and 174 deletions.
11 changes: 11 additions & 0 deletions src/core/editor/Ctx.re
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@ let push_zigg = (~onto as d: Dir.t, zigg: Zigg.t, ~fill=Cell.empty, ctx: t) => {
map_hd(Frame.Open.cat(rest), ctx);
};

let trim_space = (~side: Dir.t, ctx: t) =>
switch (pull(~from=side, ctx)) {
| (Node(tok), ctx) when Mtrl.is_space(tok.mtrl) =>
let tok =
Strings.chop_prefix(~prefix=" ", tok.text)
|> Option.map(text => {...tok, text})
|> Option.value(~default=tok);
Token.is_empty(tok) ? ctx : push(~onto=side, tok, ctx);
| _ => ctx
};

let zip_toks = (~save_cursor=false, ctx: t): option((Meld.t, t)) => {
let (hd, tl) = uncons(ctx);
Frame.Open.zip_toks(~save_cursor, hd)
Expand Down
2 changes: 2 additions & 0 deletions src/core/editor/Modify.re
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ let expand = (tok: Token.t) =>
let try_expand = (s: string, z: Zipper.t): option(Zipper.t) => {
open Options.Syntax;
let* () = Options.of_bool(String.starts_with(~prefix=" ", s));
// todo: check if in middle of token
let (face, rest) = Ctx.pull(~from=L, z.ctx);
let* tok = Delim.is_tok(face);
// if expandable, consider all expandable const labels
Expand All @@ -314,6 +315,7 @@ let try_expand = (s: string, z: Zipper.t): option(Zipper.t) => {
)
)
|> Ctx.push(~onto=L, Token.space())
|> Ctx.trim_space(~side=R)
|> finalize(~mode=Inserting(" "), ~fill=Cell.point(~dirty=true, Focus))
|> return;
};
Expand Down
20 changes: 4 additions & 16 deletions src/web/view/Code.re
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ let cursor = (~font, z: Zipper.t) => {
switch (ind_lc.meld) {
| None => []
| Some(lm) =>
Dec.Meld.Profile.mk(~whole=lc, ~state, lm) |> snd |> Dec.Meld.mk(~font)
Dec.Meld.Profile.mk(~whole=lc, ~state, lm)
|> snd
|> Dec.Layers.view(~font)
}
| Select(ind_zigg) =>
let sel = Option.get(Cursor.get_select(z.cur));
Expand All @@ -66,24 +68,10 @@ let cursor = (~font, z: Zipper.t) => {
);
ind_zigg
|> Dec.Zigg.Profile.mk(~whole=lc, ~state, ~null, ~eqs, ~rolled)
|> Dec.Zigg.mk(~font);
|> Dec.Layers.view(~font);
};
};

// let cursor = (~font, z: Zipper.t) =>
// switch (z.cur) {
// | Select(_) => []
// | Point(_) =>
// let tree = Layout.mk_cell(Zipper.zip(~save_cursor=true, z));
// let (cell, ctx) = Zipper.zip_indicated(z);
// switch (Cell.get(cell)) {
// | None => []
// | Some(m) =>
// let path = Zipper.path_of_ctx(ctx);
// m |> Dec.Meld.Profile.mk(~tree, ~path) |> Dec.Meld.mk(~font);
// };
// };

let view = (~font: Model.Font.t, ~zipper: Zipper.t): Node.t => {
// print_endline("--- Code.view ---");
// print_endline("z = " ++ Zipper.show(zipper));
Expand Down
2 changes: 1 addition & 1 deletion src/web/view/dec/Child.re
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ let includes_all_but_padding =
};
};

let mk = (~font, p: Profile.t) => {
let view = (~font, p: Profile.t) => {
let end_loc: Loc.t = Dims.skip(p.loc, ~over=p.dims, ~ind=p.ind);
let Dims.{height, widths: (hd, _)} = p.dims;

Expand Down
2 changes: 2 additions & 0 deletions src/web/view/dec/Dec.re
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module DecUtil = DecUtil;

module Layers = Layers;

module Token = Token;
module Meld = Meld;
module Zigg = Zigg;
Expand Down
35 changes: 35 additions & 0 deletions src/web/view/dec/Layers.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
open Sexplib.Std;
open Ppx_yojson_conv_lib.Yojson_conv.Primitives;
open Virtual_dom.Vdom;

[@deriving (show({with_path: false}), sexp, yojson)]
type t = {
outer: list(Silhouette.Outer.Profile.t),
inner: list(Silhouette.Inner.Profile.t),
cells: list(Child.Profile.t),
tokens: list(Token.Profile.t),
};

let mk = (~outer=[], ~inner=[], ~cells=[], ~tokens=[], ()) => {
outer,
inner,
cells,
tokens,
};
let empty = {outer: [], inner: [], tokens: [], cells: []};
let cat = (l: t, r: t) => {
let outer = l.outer @ r.outer;
let inner = l.inner @ r.inner;
let cells = l.cells @ r.cells;
let tokens = l.tokens @ r.tokens;
{outer, inner, tokens, cells};
};
let concat = List.fold_left(cat, empty);

let view = (~font, {outer, inner, tokens, cells}: t): list(Node.t) =>
List.concat([
List.map(Silhouette.Outer.view(~font), outer),
List.concat_map(Silhouette.Inner.view(~font), inner),
List.map(Child.view(~font), cells),
List.map(Token.view(~font), tokens),
]);
30 changes: 11 additions & 19 deletions src/web/view/dec/Meld.re
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ module Profile = {
let s_init = state |> L.State.jump_cell(~over=p_l);
let s_tok = L.State.jump_cell(s_init, ~over=lc_l);

let silhouette =
let inner =
sil
? Some(
Silhouette.Inner.Profile.mk(
~is_space=Mtrl.is_space(LMeld.sort(lm)),
~state=s_init,
LMeld.flatten(~flatten=LCell.flatten, lm),
),
)
: None;
? [
Silhouette.Inner.Profile.mk(
~is_space=Mtrl.is_space(LMeld.sort(lm)),
~state=s_init,
LMeld.flatten(~flatten=LCell.flatten, lm),
),
]
: [];

let l =
Child.Profile.mk(
Expand All @@ -71,16 +71,8 @@ module Profile = {
);
let state =
state |> L.State.jump_cell(~over=lc_r) |> L.State.jump_cell(~over=p_r);
let p = {chain: Chain.consnoc(~hd=l, w, ~ft=r), sil: silhouette};
let p = {...w, inner, cells: [l] @ w.cells @ [r]};
// let p = {chain: Chain.consnoc(~hd=l, w, ~ft=r), sil: silhouette};
(state, p);
};
};

let mk = (~font, p: Profile.t) =>
List.concat([
p.sil
|> Option.map(Silhouette.Inner.mk(~font))
|> Option.value(~default=[]),
List.map(T.mk(~font), Profile.tokens(p)),
List.map(Child.mk(~font), Profile.cells(p)),
]);
5 changes: 3 additions & 2 deletions src/web/view/dec/Silhouette.re
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module Inner = {
let h_pad = 0.1;
let v_trunc = T.v_trunc -. 0.06;

let mk = (~font, p: Profile.t) => {
let view = (~font, p: Profile.t) => {
p.is_space
? []
: Block.flatten(p.block)
Expand Down Expand Up @@ -103,6 +103,7 @@ module Inner = {
module Outer = {
module Profile = {
open Util.Svgs;
[@deriving (show({with_path: false}), sexp, yojson)]
type t = list(Rect.t);
let mk = (~state: L.State.t, block: Block.t) => {
Block.flatten(block)
Expand Down Expand Up @@ -134,7 +135,7 @@ module Outer = {
};
};

let mk = (~font, p: Profile.t) => {
let view = (~font, p: Profile.t) => {
p
|> Util.Svgs.OrthogonalPolygon.mk(~corner_radii=(0.35, 0.15))
|> Util.Svgs.Path.view
Expand Down
32 changes: 25 additions & 7 deletions src/web/view/dec/Terr.re
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ module Profile = {
let ind = L.Indent.curr(state.ind);
// let (null_l, null_r) = ;
// let state = eq ? state : L.State.push_ind(state);
let inner =
sil
? [
Silhouette.Inner.Profile.mk(
~is_space=Mtrl.is_space(LTerr.sort(terr)),
~state,
LTerr.L.flatten(terr),
),
]
: [];
let (state, wald) =
W.Profile.mk(
~sil,
Expand All @@ -41,7 +51,8 @@ module Profile = {
terr.cell,
);
let state = L.State.jump_cell(state, ~over=terr.cell);
(state, {cell, wald});
let p = {...wald, inner, cells: wald.cells @ [cell]};
(state, p);
};

let mk_r =
Expand All @@ -53,6 +64,17 @@ module Profile = {
~eq,
terr: LTerr.t,
) => {
let inner =
sil
? [
Silhouette.Inner.Profile.mk(
~is_space=Mtrl.is_space(LTerr.sort(terr)),
~state,
LTerr.R.flatten(terr),
),
]
: [];

let s_mid = L.State.jump_cell(state, ~over=terr.cell);
let cell =
Child.Profile.mk(
Expand All @@ -72,11 +94,7 @@ module Profile = {
~eq=(false, eq),
Wald.rev(terr.wald),
);
(state, {cell, wald});
let p = {...wald, inner, cells: [cell] @ wald.cells};
(state, p);
};
};

let mk = (~font, p: Profile.t) => [
Child.mk(~font, p.cell),
...W.mk(~font, p.wald),
];
2 changes: 1 addition & 1 deletion src/web/view/dec/Token.re
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ module Sil = {
};
};

let mk = (prof: Profile.t) =>
let view = (prof: Profile.t) =>
prof.style
|> Option.map((style: Style.t) =>
(style.sil ? [Sil.mk(prof.len, style.shape)] : [])
Expand Down
74 changes: 41 additions & 33 deletions src/web/view/dec/Wald.re
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module L = Layout;

module Profile = {
[@deriving (show({with_path: false}), sexp, yojson)]
type t = Chain.t(T.Profile.t, Child.Profile.t);
type t = Layers.t;

let tokens = fst;
let cells = snd;
Expand All @@ -18,43 +18,51 @@ module Profile = {
~state: L.State.t,
~null: (bool, bool),
~eq: (bool, bool),
W(w): LWald.t,
W(w) as lw: LWald.t,
) => {
let state = fst(eq) ? L.State.pop_ind(state) : L.State.push_ind(state);
let ind = L.Indent.curr(state.ind);
// let ind = state.ind + state.rel;
let n = Chain.length(w);
let inner =
sil
? [
Silhouette.Inner.Profile.mk(
~is_space=Mtrl.is_space(LWald.sort(lw)),
~state,
LWald.flatten(~flatten=LCell.flatten, lw),
),
]
: [];
// logic below assumes w won't be space
w
|> Chain.mapi_loop((i, b) => (i, b))
|> Chain.fold_left_map(
((_, b_tok)) => {
let null = (fst(null), n == 1 && snd(null));
let t = T.Profile.mk(~sil, ~loc=state.loc, ~null, b_tok);
let state = L.State.jump_tok(state, ~over=b_tok);
(state, t);
},
(state, cell, (i, b_tok)) => {
let c =
Child.Profile.mk(
~sil,
~whole,
~ind,
~loc=state.loc,
~null=(false, false),
cell,
);
let state = L.State.jump_cell(state, ~over=cell);
let null = (false, i == n - 1 && snd(null));
let t = T.Profile.mk(~sil, ~loc=state.loc, ~null, b_tok);
let state = L.State.jump_tok(state, ~over=b_tok);
(state, c, t);
},
)
|> Stds.Tuples.map_fst(snd(eq) ? Fun.id : L.State.pop_ind);
let (state, (tokens, cells)) =
w
|> Chain.mapi_loop((i, b) => (i, b))
|> Chain.fold_left_map(
((_, b_tok)) => {
let null = (fst(null), n == 1 && snd(null));
let t = T.Profile.mk(~sil, ~loc=state.loc, ~null, b_tok);
let state = L.State.jump_tok(state, ~over=b_tok);
(state, t);
},
(state, cell, (i, b_tok)) => {
let c =
Child.Profile.mk(
~sil,
~whole,
~ind,
~loc=state.loc,
~null=(false, false),
cell,
);
let state = L.State.jump_cell(state, ~over=cell);
let null = (false, i == n - 1 && snd(null));
let t = T.Profile.mk(~sil, ~loc=state.loc, ~null, b_tok);
let state = L.State.jump_tok(state, ~over=b_tok);
(state, c, t);
},
)
|> Stds.Tuples.map_fst(snd(eq) ? Fun.id : L.State.pop_ind);
(state, Layers.mk(~inner, ~cells, ~tokens, ()));
};
};

let mk = (~font, p: Profile.t) =>
List.map(T.mk(~font), Profile.tokens(p))
@ List.map(Child.mk(~font), Profile.cells(p));
Loading

0 comments on commit d61517f

Please sign in to comment.