Skip to content

Commit

Permalink
fix #26
Browse files Browse the repository at this point in the history
  • Loading branch information
dm0n3y committed Nov 2, 2024
1 parent 503279d commit 90a1254
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/core/editor/Ctx.re
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ let push_opt =
};
};

let push = (~onto: Dir.t, tok: Token.t, ctx) =>
switch (push_opt(~onto, tok, ctx)) {
let push = (~onto: Dir.t, ~fill=Cell.empty, tok: Token.t, ctx) =>
switch (push_opt(~onto, tok, ~fill, ctx)) {
| Some(ctx) => ctx
| None => raise(Invalid_argument("Ctx.push"))
};
Expand Down
34 changes: 32 additions & 2 deletions src/core/editor/Modify.re
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,22 @@ let delete_sel = (d: Dir.t, z: Zipper.t): Zipper.t => {
fill => (ctx, fill),
((ctx, fill), tok, next_fill) =>
switch (mold(ctx, ~fill, tok)) {
| Some(ctx) => (ctx, next_fill)
| Some(ctx) =>
let (face, rest) = Ctx.pull(~from=L, ctx);
switch (face, next_fill.marks.cursor) {
| (Node(molded), Some(Point({hand, path: []})))
when Token.length(molded) > Token.Unmolded.length(tok) =>
let marks = {...next_fill.marks, cursor: None};
let next_fill = {...next_fill, marks};
let molded =
Token.put_cursor(
Point(Caret.mk(hand, Token.Unmolded.length(tok))),
molded,
);
let ctx = Ctx.push(~onto=L, molded, ~fill=Cell.dirty, rest);
(ctx, next_fill);
| _ => (ctx, next_fill)
};
| None =>
let next_fill =
Option.is_some(fill.marks.cursor)
Expand Down Expand Up @@ -442,7 +457,22 @@ let insert = (s: string, z: Zipper.t) => {
fill => (ctx, fill),
((ctx, fill), tok, next_fill) =>
switch (mold(ctx, ~fill, tok)) {
| Some(ctx) => (ctx, next_fill)
| Some(ctx) =>
let (face, rest) = Ctx.pull(~from=L, ctx);
switch (face, next_fill.marks.cursor) {
| (Node(molded), Some(Point({hand, path: []})))
when Token.length(molded) > Token.Unmolded.length(tok) =>
let marks = {...next_fill.marks, cursor: None};
let next_fill = {...next_fill, marks};
let molded =
Token.put_cursor(
Point(Caret.mk(hand, Token.Unmolded.length(tok))),
molded,
);
let ctx = Ctx.push(~onto=L, molded, ~fill=Cell.dirty, rest);
(ctx, next_fill);
| _ => (ctx, next_fill)
};
| None =>
let next_fill =
Option.is_some(fill.marks.cursor)
Expand Down
3 changes: 2 additions & 1 deletion src/core/parser/Melder.re
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ let connect_eq =
}
and rm_ghost_and_go = (onto, fill) =>
switch (Terr.unlink(onto)) {
| (hd, cell, Some(tl)) when Option.is_some(Token.Tile.is_ghost(hd)) =>
| (hd, cell, Some(tl))
when Option.is_some(Token.Tile.is_ghost(~require_empty=true, hd)) =>
go(tl, [cell, ...fill]) |> Effects.perform_if(Remove(hd))
| _ => None
};
Expand Down
6 changes: 4 additions & 2 deletions src/core/structure/Token.re
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ module Unmolded = {
type t = Base.t(Mtrl.t(Space.T.t, unit, list(Label.t)));
let mk = (~id=?, ~text="", ~marks=?, mtrl: Mtrl.t(_)): t =>
Base.mk(~id?, ~text, ~marks?, mtrl);
let length = (tok: t) => Utf8.length(tok.text);
let defer = (tok: t): Molded.t =>
Molded.mk(~id=tok.id, ~text=tok.text, Space(Unmolded));
let has_lbl = (lbl: Label.t, tok: t) =>
Expand Down Expand Up @@ -344,11 +345,12 @@ module Grout = {
let in_ = (~id=?) => mk(~id?, (Conc, Conc));
};
module Tile = {
let is_ghost = (tok: t) =>
let is_ghost = (~require_empty=false, tok: t) =>
switch (tok.mtrl) {
| Space(_)
| Grout(_) => None
| Tile((lbl, _) as t) =>
Label.is_complete(tok.text, lbl) ? None : Some(t)
!Label.is_complete(tok.text, lbl) && (!require_empty || tok.text == "")
? Some(t) : None
};
};

0 comments on commit 90a1254

Please sign in to comment.