Skip to content

Commit

Permalink
fix #80
Browse files Browse the repository at this point in the history
  • Loading branch information
dm0n3y committed Nov 10, 2024
1 parent 039c3dd commit f151bd0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
22 changes: 20 additions & 2 deletions src/core/editor/Move.re
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,32 @@ let hstep_tok = (d: Dir.t, tok: Token.t): (Token.t, bool) => {
};
};

let push_site = (~onto: Dir.t, site: Zipper.Site.t, ctx: Ctx.t) =>
switch (site) {
| Between => ctx
| Within(tok) => Ctx.push(~onto, tok, ctx)
};
let push_sites = (site: Zipper.Site.cursor, ctx: Ctx.t) =>
switch (site) {
| Point(Between) => ctx
| Point(Within(tok)) =>
ctx |> Ctx.push(~onto=L, tok) |> Ctx.push(~onto=R, tok)
| Select((l, r)) => ctx |> push_site(~onto=L, l) |> push_site(~onto=R, r)
};

let hstep = (d: Dir.t, z: Zipper.t): option(Zipper.t) => {
open Options.Syntax;
let b = Dir.toggle(d);
let+ ctx =
switch (z.cur) {
| Select({range: zigg, _}) =>
// move to d end of selection
return(Ctx.push_zigg(~onto=b, zigg, z.ctx))
// move to d end of selection, taking care to update any token marks
let (_, ctx_sans_sites) = Zipper.cursor_site(z);
let zigg =
zigg
|> Zigg.map_face(~side=d, Token.focus_point)
|> Zigg.map_face(~side=b, Token.clear_marks);
return(Ctx.push_zigg(~onto=b, zigg, ctx_sans_sites));
| Point(_) =>
let (face, ctx) = Ctx.pull(~from=d, z.ctx);
let+ tok = Bound.to_opt(face);
Expand Down
9 changes: 9 additions & 0 deletions src/core/editor/Zigg.re
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ let face = (~side: Dir.t, zigg: t) => {
| Root => Wald.hd(top)
};
};
let map_face = (~side: Dir.t, f, zigg: t) => {
let (s_d, top, s_b) = orient(side, zigg);
let (s_d, top) =
switch (Slope.map_face(f, s_d)) {
| Some(s_d) => (s_d, top)
| None => (s_d, Wald.map_hd(f, top))
};
unorient(side, (s_d, top, s_b));
};

// let x = (1 + [a + b ? c / d : e * f] + 3) + 4 * 5 in x + 1

Expand Down
4 changes: 3 additions & 1 deletion src/core/structure/Token.re
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ module Base = {
...tok,
marks: Some(cursor),
};
let put_marks = (marks, tok) => {...tok, marks};
let map_marks = (f, tok: t(_)): t(_) => {...tok, marks: f(tok.marks)};
let put_marks = marks => map_marks(Fun.const(marks));
let clear_marks = tok => put_marks(None, tok);
let pop_marks = tok => (tok.marks, clear_marks(tok));
let height = tok => Strings.count('\n', tok.text);
Expand All @@ -43,6 +44,7 @@ module Molded = {
[@deriving (sexp, yojson)]
type t = Base.t(Mtrl.T.t);

let focus_point: t => t = map_marks(Marks.focus_point);
let pp = (out, tok: t) =>
switch (tok.mtrl) {
| Space(t) =>
Expand Down
4 changes: 4 additions & 0 deletions src/core/structure/marks/Marks.re
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ module Token = {
};
let shift = n => Option.map(Step.Cursor.map(Step.shift(n)));
let union = Options.merge(~f=Step.Cursor.union);
let focus_point: t => t =
Option.map(
Cursor.map((car: Step.Caret.t) => Step.Caret.focus(car.path), Fun.id),
);
};

module Cell = {
Expand Down

0 comments on commit f151bd0

Please sign in to comment.