Skip to content

Commit

Permalink
paste works. internalized token splitting into Insert in Edit.re
Browse files Browse the repository at this point in the history
  • Loading branch information
disconcision committed Nov 4, 2024
1 parent ad1c917 commit 8a735d5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
7 changes: 6 additions & 1 deletion src/core/editor/Edit.re
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ let perform = (a: t, z: Zipper.t): option(Zipper.t) => {
switch (a) {
| Move(a) => Move.perform(a, z)
| Select(a) => Select.perform(a, z)
| Insert(s) => Some(Modify.insert(s, z))
| Insert(s) =>
s
|> Labeler.label
|> List.map((x: Token.Unmolded.t) => x.text)
|> List.fold_left((x, y) => Modify.insert(y, x), z)
|> Option.some
| Delete(d) => Modify.delete(d, z)
};
};
6 changes: 1 addition & 5 deletions src/web/Store.re
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ let insert: (Zipper.t, string) => Zipper.t =
};
};

let parse = (str: string): Zipper.t =>
str
|> Labeler.label
|> List.map((x: Token.Unmolded.t) => x.text)
|> List.fold_left(insert, Zipper.empty);
let parse = insert(Zipper.empty);

let serialize = z => z |> Zipper.sexp_of_t |> Sexplib.Sexp.to_string;

Expand Down
2 changes: 0 additions & 2 deletions src/web/update/Update.re
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ let handle_key_event = (k: Util.Key.t, ~model as _: Model.t): list(t) => {
switch (key) {
| "z" => now_save_u(Undo)
// | "x" => now(Pick_up)
| "v" => now(Insert(LocalStorage.get_from_clipboard()))
| "a" => now(Move(Skip(V(L)))) @ now(Select(Move(Skip(V(R)))))
// | _ when is_digit(key) => [SwitchEditor(int_of_string(key))]
| "ArrowLeft" => now(Move(Skip(H(L))))
Expand All @@ -115,7 +114,6 @@ let handle_key_event = (k: Util.Key.t, ~model as _: Model.t): list(t) => {
switch (key) {
| "z" => now_save_u(Undo)
// | "x" => now(Pick_up)
| "v" => now(Insert("blahblahblah"))
| "a" => now(Move(Skip(V(L)))) @ now(Select(Move(Skip(V(R)))))
// | _ when is_digit(key) => [SwitchEditor(int_of_string(key))]
| "ArrowLeft" => now(Move(Skip(H(L))))
Expand Down
20 changes: 20 additions & 0 deletions src/web/view/Page.re
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,26 @@ let view = (~inject, model: Model.t) => {
Util.Dom.get_elem_by_id("page")##focus;
Effect.Prevent_default;
}),
Attr.on_copy(_ => {
print_endline("TODO: copying");
//JsUtil.copy(Printer.to_string_selection(editor));
Effect.Ignore;
}),
Attr.on_cut(_ => {
print_endline("TODO: cutting");
//JsUtil.copy(Printer.to_string_selection(editor));
//inject(UpdateAction.PerformAction(Destruct(Left)));
Effect.Ignore;
}),
Attr.on_paste(evt => {
print_endline("TODO: pasting");
open Js_of_ocaml;
let pasted_text =
Js.to_string(evt##.clipboardData##getData(Js.string("text")));
//|> Util.StringUtil.trim_leading;
Dom.preventDefault(evt);
inject(Update.PerformAction(Insert(pasted_text)));
}),
...on_key(~inject, ~model),
],
[
Expand Down

0 comments on commit 8a735d5

Please sign in to comment.