Skip to content

Commit

Permalink
copy partially working
Browse files Browse the repository at this point in the history
  • Loading branch information
disconcision committed Nov 4, 2024
1 parent 602d9ef commit 90aa88f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 19 deletions.
24 changes: 24 additions & 0 deletions src/web/LocalStorage.re
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,27 @@ let set = (k: string, v: string): unit => {
Js.Optdef.get(Dom_html.window##.localStorage, () => assert(false));
local_store##setItem(Js.string(k), Js.string(v));
};
let get_from_clipboard = (): string => {
/* WIP(andrew):
This sorta works, somewhat hackily and inconsistently (requires a dom element
called blorg to be present and ideally hidden). However it prompts the user
for permissions each time.
*/
let _ =
Js.Unsafe.js_expr(
"window.navigator.clipboard.readText().then(
function(text)
{var guy = document.getElementById('blorg'); guy.innerHTML = text; console.log('Clipboard content is: ', text)}).catch
(function(err)
{console.error('Failed to read clipboard contents: ', err)})",
);
let doc = Dom_html.document;
let elem =
Js.Opt.get(doc##getElementById(Js.string("blorg")), () => {
assert(false)
});
let result: Js.t('a) = Js.Unsafe.get(elem, "innerHTML");
let result = Js.to_string(result);
print_endline(result);
result;
};
2 changes: 2 additions & 0 deletions src/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<link rel="stylesheet" href="style.css">
</head>

<div id="blorg"></div>

<body spellcheck="false">
<div class="container" id="container"></div>
</body>
Expand Down
34 changes: 15 additions & 19 deletions src/web/update/Update.re
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ type t =
| PerformAction(Edit.t)
// | FailedInput(FailedInput.reason) //TODO(andrew): refactor as failure?
| Undo
| Redo;
| Redo
| Reset;

let is_f_key = s => Re.Str.(string_match(regexp("^F[0-9][0-9]*$"), s, 0));

let handle_key_event = (k: Util.Key.t, ~model as _: Model.t): list(t) => {
// let zipper = model.zipper;
Expand All @@ -39,22 +42,14 @@ let handle_key_event = (k: Util.Key.t, ~model as _: Model.t): list(t) => {
// | "Alt" => [SetShowBackpackTargets(false)]
// | _ => [UpdateDoubleTap(None)]
// }
// | {key: D(key), sys: _, shift: Down, meta: Up, ctrl: Up, alt: Up}
// when is_f_key(key) =>
// switch (key) {
// | "F1" => print(Log.get_json_update_log_string())
// | "F2" => print(Zipper.show(zipper))
// | "F3" => toggle(Log.debug_update)
// | "F4" => toggle(Log.debug_keystoke)
// | "F5" => toggle(Log.debug_zipper)
// | "F6" => [Load]
// | "F7" => []
// | "F8" => []
// | "F10" =>
// Log.reset_json_log();
// [];
// | _ => []
// }
| {key: D(key), sys: _, shift: Down, meta: Up, ctrl: Up, alt: Up}
when is_f_key(key) =>
switch (key) {
| "F1" =>
print_endline("F1: Resetting Model");
now_save_u(Reset);
| _ => []
}
| {key: D(key), sys: _, shift, meta: Up, ctrl: Up, alt: Up} =>
switch (shift, key) {
| (Up, "ArrowLeft") => now(Move(Step(H(L))))
Expand Down Expand Up @@ -110,7 +105,7 @@ 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(Put_down)
| "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 @@ -123,7 +118,7 @@ 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(Put_down)
| "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 Expand Up @@ -235,6 +230,7 @@ let apply =
| None => Error(CantRedo)
| Some((zipper, history)) => Ok({...model, zipper, history})
}
| Reset => Ok({...model, zipper: Zipper.empty, history: History.empty})
// | Set(s_action) =>
// Ok({...model, settings: update_settings(s_action, model.settings)})
// | LoadInit =>
Expand Down

0 comments on commit 90aa88f

Please sign in to comment.