From c81fc753742056150e324ca3ddc16656247cab8f Mon Sep 17 00:00:00 2001 From: David Moon Date: Tue, 2 Jul 2024 01:43:57 -0400 Subject: [PATCH] fix cursor dec not applying contextual indentation --- src/core/layout/Layout.re | 11 ++++++----- src/web/view/Code.re | 17 ++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/core/layout/Layout.re b/src/core/layout/Layout.re index b5d582a2..d6bb7053 100644 --- a/src/core/layout/Layout.re +++ b/src/core/layout/Layout.re @@ -126,9 +126,10 @@ let path_of_loc = }; // todo: reorg this as unzipping layout zipper let rec state_of_path = - (~state=State.init, ~tree: Tree.t, path: Path.t): State.t => + (~state=State.init, ~tree: Tree.t, path: Path.t) + : (State.t, option(Tree.t)) => switch (path) { - | [] => state + | [] => (state, Some(tree)) // let s_end = State.jump_block(state, ~over=Tree.flatten(tree)); // (state.ind, (state.loc, s_end.loc)); | [hd, ...tl] => @@ -145,13 +146,13 @@ let rec state_of_path = | Link((pre, b_tok, _)) => let state = State.jump_block(state, ~over=Tree.flatten_chain(pre)); switch (tl) { - | [] => state + | [] => (state, None) // let s_end = State.jump_block(state, ~over=b_tok); // (state.ind, (state.loc, s_end.loc)); | [hd, ..._] => let loc = loc_of_step(~state, ~block=b_tok, hd); // (state.ind, (loc, loc)); - {...state, loc}; + ({...state, loc}, None); }; } }; @@ -160,7 +161,7 @@ let rec state_of_path = // Dir.pick(side, (fst, snd), snd(range_of_path(~state, ~tree, path))); let map = (~tree: Tree.t, f: Loc.t => Loc.t, path: Path.t): Path.t => - switch (path_of_loc(~tree, f(state_of_path(~tree, path).loc))) { + switch (path_of_loc(~tree, f(fst(state_of_path(~tree, path)).loc))) { | Ok(path) => path | Error(_) => Tree.end_path(tree, ~side=R) }; diff --git a/src/web/view/Code.re b/src/web/view/Code.re index 0c10cd9d..89050362 100644 --- a/src/web/view/Code.re +++ b/src/web/view/Code.re @@ -16,16 +16,15 @@ let cursor = (~font, z: Zipper.t) => print_endline("0"); []; | Point(_) => + let tree = Layout.Tree.of_cell(Zipper.zip(~save_cursor=true, z)); let (cell, ctx) = Zipper.zip_indicated(z); - switch (Cell.get(cell)) { - | Some(m) when !Cell.Space.is_space(cell) => - let lyt = Layout.Tree.of_meld(m); - let state = - Layout.state_of_path( - ~tree=Layout.Tree.of_cell(Zipper.zip(~save_cursor=true, z)), - Zipper.path_of_ctx(ctx), - ); - Dec.Meld.(mk(~font, Profile.mk(~state, lyt, m))); + switch (Layout.state_of_path(~tree, Zipper.path_of_ctx(ctx))) { + | (state, Some(t)) => + switch (Cell.get(cell), t) { + | (Some(m), Some(lyt)) when !Cell.Space.is_space(cell) => + Dec.Meld.(mk(~font, Profile.mk(~state, lyt, m))) + | _ => [] + } | _ => [] }; };