Skip to content

Commit

Permalink
fix broken delete
Browse files Browse the repository at this point in the history
  • Loading branch information
dm0n3y committed Nov 12, 2024
1 parent 54e6ed4 commit 81d521b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/core/editor/Modify.re
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@ let delete = (d: Dir.t, z: Zipper.t) => {
// };
// P.log("--- delete");
// P.show("z", Zipper.show(z));
let+ z = Cursor.is_point(z.cur) ? Select.hstep(d, z) : return(z);
let+ z =
Cursor.is_point(z.cur) ? Select.hstep(~char=true, d, z) : return(z);
// P.show("selected", Zipper.show(z));
delete_sel(d, z);
};
Expand Down
25 changes: 11 additions & 14 deletions src/core/editor/Select.re
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ let push_site = (~onto: Dir.t, site: Zipper.Site.t, ctx: Ctx.t) =>
| Within(tok) => Ctx.push(~onto, tok, ctx)
};

let hstep = (d: Dir.t, z: Zipper.t): option(Zipper.t) => {
let hstep = (~char=false, d: Dir.t, z: Zipper.t): option(Zipper.t) => {
open Options.Syntax;
// let b = Dir.toggle(d);
let b = Dir.toggle(d);
let (cur_site, ctx_sans_site) = Zipper.cursor_site(z);
let growing =
switch (z.cur) {
| Point(_) => true
| Select({focus, _}) => focus == d
};
// let hstep_tok = hstep_tok(~is_selected=Cursor.is_select(z.cur));
let hstep_tok = hstep_tok(~is_selected=Cursor.is_select(z.cur));
if (growing) {
let (delim, ctx_sans_delim) =
switch (cur_site) {
Expand All @@ -91,19 +91,18 @@ let hstep = (d: Dir.t, z: Zipper.t): option(Zipper.t) => {
}
};
let+ tok = Delim.is_tok(delim);
// let (stepped, exited) = hstep_tok(d, tok);
let stepped = tok;
let (stepped, exited) = char ? hstep_tok(d, tok) : (tok, true);
let zigg =
switch (z.cur) {
| Point(_) => Zigg.of_tok(stepped)
| Select(sel) => Zigg.grow(~side=sel.focus, stepped, sel.range)
};
let sel = Selection.{focus: d, range: zigg};
// let ctx =
// ctx_sans_delim
// |> (exited ? Fun.id : Ctx.push(~onto=d, stepped))
// |> (!Token.has_anchor(stepped) ? Fun.id : Ctx.push(~onto=b, stepped));
Zipper.mk(~cur=Select(sel), ctx_sans_delim);
let ctx =
ctx_sans_delim
|> (exited ? Fun.id : Ctx.push(~onto=d, stepped))
|> (!Token.has_anchor(stepped) ? Fun.id : Ctx.push(~onto=b, stepped));
Zipper.mk(~cur=Select(sel), ctx);
} else {
// points always grow, only selections can shrink.
// d points from selection focus toward anchor.
Expand All @@ -112,14 +111,12 @@ let hstep = (d: Dir.t, z: Zipper.t): option(Zipper.t) => {
let (_site_foc, site_anc) = Dir.order(sel.focus, sites);

let (tok, rest) = Zigg.pull(~side=sel.focus, sel.range);
// let (stepped, exited) = hstep_tok(d, tok);
let stepped = tok;
let (stepped, exited) = char ? hstep_tok(d, tok) : (tok, true);

switch (rest) {
// sel spanned more than one token
| Some(rest) =>
// let zigg = exited ? rest : Zigg.grow(~side=sel.focus, stepped, rest);
let zigg = rest;
let zigg = exited ? rest : Zigg.grow(~side=sel.focus, stepped, rest);
let cur = Cursor.Select({...sel, range: zigg});
let ctx =
ctx_sans_site
Expand Down

0 comments on commit 81d521b

Please sign in to comment.