Skip to content

Commit

Permalink
activate tab to obligation (need to fix overkill prevent_default on k…
Browse files Browse the repository at this point in the history
…eyboard events)
  • Loading branch information
dm0n3y committed Aug 26, 2024
1 parent 38c2582 commit 7d95426
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
9 changes: 8 additions & 1 deletion src/core/editor/Move.re
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,20 @@ let jump = loc => map_focus(Fun.const(loc));
let hole = (d: Dir.t, z: Zipper.t): option(Zipper.t) => {
open Options.Syntax;
let c = Zipper.zip(~save_cursor=true, z);
let normal = Zipper.normalize(~cell=c);
switch (Options.get_exn(Zipper.Bug__lost_cursor, c.marks.cursor)) {
| Select(_) => hstep(d, z)
| Point({path, _}) =>
let+ (path, _) =
c.marks.obligs
|> Path.Map.filter((_, mtrl: Mtrl.T.t) => mtrl != Space(Unmolded))
|> Path.Map.find_first_opt(p => Dir.pick(d, Path.(lt, gt), p, path));
|> Dir.pick(
d,
(
Path.Map.find_last_opt(p => Path.lt(normal(p), path)),
Path.Map.find_first_opt(p => Path.gt(normal(p), path)),
),
);
c |> Cell.put_cursor(Point(Caret.focus(path))) |> Zipper.unzip_exn;
};
};
Expand Down
13 changes: 12 additions & 1 deletion src/core/editor/Zipper.re
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ let cursor_site = (z: t): (Site.Cursor.t, Ctx.t) =>
(Cur.Select((l, r)), ctx);
};

// assumes normalized cursor
let rec unzip = (~ctx=Ctx.empty, cell: Cell.t) => {
open Options.Syntax;
let* hd = Option.map(Path.Cursor.hd, cell.marks.cursor);
Expand Down Expand Up @@ -132,6 +131,7 @@ let rec unzip = (~ctx=Ctx.empty, cell: Cell.t) => {
};
};
}
// assumes normalized cursor
and unzip_select = (~ctx=Ctx.empty, sel: Path.Selection.t, meld: Meld.t) => {
let get = Options.get_exn(Marks.Invalid);
let (l, r) = sel.range;
Expand Down Expand Up @@ -260,3 +260,14 @@ let button = (z: t): t => {
let ctx = Ctx.cons(Frame.Open.empty, tl);
Option.get(unzip(cell, ~ctx));
};

let normalize = (~cell: Cell.t, path: Path.t): Path.t => {
let cell = Cell.put_cursor(Point(Caret.focus(path)), cell);
let zipped =
unzip(cell)
|> Options.get_exn(Invalid_argument("Cell.normalize"))
|> zip(~save_cursor=true);
let cur = Option.get(zipped.marks.cursor);
let car = Option.get(Cursor.get_point(cur));
car.path;
};
2 changes: 2 additions & 0 deletions src/web/update/Update.re
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ let handle_key_event = (k: Util.Key.t, ~model as _: Model.t): list(t) => {
| (Up, "Backspace") => now_save(Delete(L))
| (Up, "Delete") => now_save(Delete(R))
| (Up, "Escape") => now(Select(Un(L)))
| (Up, "Tab") => now(Move(Hole(R)))
// | (Up, "Tab") => now_save(Put_down) //TODO: if empty, move to next hole
| (Down, "Tab") => now(Move(Hole(L)))
| (Down, "ArrowLeft") => now(Select(Move(Step(H(L)))))
| (Down, "ArrowRight") => now(Select(Move(Step(H(R)))))
| (Down, "ArrowUp") => now(Select(Move(Step(V(L)))))
Expand Down
26 changes: 14 additions & 12 deletions src/web/view/Page.re
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,22 @@ let on_key = (~inject, ~model) =>
Attr.[
on_keypress(_ => Effect.Prevent_default),
on_keyup(evt =>
Effect.Many(
List.map(
inject,
Update.handle_key_event(Util.Key.mk(KeyUp, evt), ~model),
),
)
Effect.Many([
Effect.Prevent_default,
...List.map(
inject,
Update.handle_key_event(Util.Key.mk(KeyUp, evt), ~model),
),
])
),
on_keydown(evt =>
Effect.Many(
List.map(
inject,
Update.handle_key_event(Util.Key.mk(KeyDown, evt), ~model),
),
)
Effect.Many([
Effect.Prevent_default,
...List.map(
inject,
Update.handle_key_event(Util.Key.mk(KeyDown, evt), ~model),
),
])
),
];

Expand Down

0 comments on commit 7d95426

Please sign in to comment.