Skip to content

Commit

Permalink
fix #42 (hack? not sure)
Browse files Browse the repository at this point in the history
  • Loading branch information
dm0n3y committed Nov 5, 2024
1 parent 85fefb2 commit 5e60fa8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/core/editor/Ctx.re
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@ let push_zigg = (~onto as d: Dir.t, zigg: Zigg.t, ~fill=Cell.empty, ctx: t) => {
map_hd(Frame.Open.cat(rest), ctx);
};

let trim_space = (~side: Dir.t, ctx: t) =>
switch (pull(~from=side, ctx)) {
| (Node(tok), ctx) when Mtrl.is_space(tok.mtrl) =>
let tok =
Strings.chop_prefix(~prefix=" ", tok.text)
|> Option.map(text => {...tok, text})
|> Option.value(~default=tok);
Token.is_empty(tok) ? ctx : push(~onto=side, tok, ctx);
| _ => ctx
};

let zip_toks = (~save_cursor=false, ctx: t): option((Meld.t, t)) => {
let (hd, tl) = uncons(ctx);
Frame.Open.zip_toks(~save_cursor, hd)
Expand Down
2 changes: 2 additions & 0 deletions src/core/editor/Modify.re
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ let expand = (tok: Token.t) =>
let try_expand = (s: string, z: Zipper.t): option(Zipper.t) => {
open Options.Syntax;
let* () = Options.of_bool(String.starts_with(~prefix=" ", s));
// todo: check if in middle of token
let (face, rest) = Ctx.pull(~from=L, z.ctx);
let* tok = Delim.is_tok(face);
// if expandable, consider all expandable const labels
Expand All @@ -314,6 +315,7 @@ let try_expand = (s: string, z: Zipper.t): option(Zipper.t) => {
)
)
|> Ctx.push(~onto=L, Token.space())
|> Ctx.trim_space(~side=R)
|> finalize(~mode=Inserting(" "), ~fill=Cell.point(~dirty=true, Focus))
|> return;
};
Expand Down
2 changes: 2 additions & 0 deletions src/stds/Strings.re
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ let count = c => Base.String.count(~f=(==)(c));
let split = Base.String.split;

let rev = Base.String.rev;

let chop_prefix = Base.String.chop_prefix;

0 comments on commit 5e60fa8

Please sign in to comment.