init.ml
This commit is contained in:
78
toplevel.ml
78
toplevel.ml
@ -377,7 +377,8 @@ module History = struct
|
||||
textbox##.value := Js.string !data.(!idx))
|
||||
end
|
||||
|
||||
let run ~init ~output () =
|
||||
let run ~init ~output () :
|
||||
?pp_code:Format.formatter -> string -> unit -> unit Lwt.t =
|
||||
Firebug.console##log "run";
|
||||
|
||||
let container = by_id "toplevel-container" in
|
||||
@ -410,66 +411,6 @@ let run ~init ~output () =
|
||||
textbox##focus;
|
||||
Lwt.return_unit
|
||||
in
|
||||
let history_down _e =
|
||||
let txt = Js.to_string textbox##.value in
|
||||
let pos = textbox##.selectionStart in
|
||||
try
|
||||
if String.length txt = pos then raise Not_found;
|
||||
let _ = String.index_from txt pos '\n' in
|
||||
Js._true
|
||||
with Not_found ->
|
||||
History.current txt;
|
||||
History.next textbox;
|
||||
Js._false
|
||||
in
|
||||
let history_up _e =
|
||||
let txt = Js.to_string textbox##.value in
|
||||
let pos = textbox##.selectionStart - 1 in
|
||||
try
|
||||
if pos < 0 then raise Not_found;
|
||||
let _ = String.rindex_from txt pos '\n' in
|
||||
Js._true
|
||||
with Not_found ->
|
||||
History.current txt;
|
||||
History.previous textbox;
|
||||
Js._false
|
||||
in
|
||||
let meta e =
|
||||
let b = Js.to_bool in
|
||||
b e##.ctrlKey || b e##.altKey || b e##.metaKey
|
||||
in
|
||||
let shift e = Js.to_bool e##.shiftKey in
|
||||
(* setup handlers *)
|
||||
textbox##.onkeyup :=
|
||||
Dom_html.handler (fun _ ->
|
||||
Lwt.async (resize ~container ~textbox);
|
||||
Js._true);
|
||||
textbox##.onchange :=
|
||||
Dom_html.handler (fun _ ->
|
||||
Lwt.async (resize ~container ~textbox);
|
||||
Js._true);
|
||||
textbox##.onkeydown :=
|
||||
Dom_html.handler (fun e ->
|
||||
match e##.keyCode with
|
||||
| 13 when not (meta e || shift e) ->
|
||||
Lwt.async (fun () ->
|
||||
execute (Js.to_string textbox##.value##trim) ());
|
||||
Js._false
|
||||
| 13 ->
|
||||
Lwt.async (resize ~container ~textbox);
|
||||
Js._true
|
||||
| 09 ->
|
||||
Indent.textarea textbox;
|
||||
Js._false
|
||||
| 76 when meta e ->
|
||||
output##.innerHTML := Js.string "";
|
||||
Js._true
|
||||
| 75 when meta e ->
|
||||
setup_toplevel ();
|
||||
Js._false
|
||||
| 38 -> history_up e
|
||||
| 40 -> history_down e
|
||||
| _ -> Js._true);
|
||||
(Lwt.async_exception_hook :=
|
||||
fun exc ->
|
||||
Format.eprintf "exc during Lwt.async: %s@."
|
||||
@ -522,14 +463,15 @@ let run ~init ~output () =
|
||||
(Js.string ".config/init.ml exception")
|
||||
(Js.string (Printexc.to_string exc))
|
||||
exc);
|
||||
try
|
||||
let code = List.assoc "code" (parse_hash ()) in
|
||||
textbox##.value := Js.string (B64.decode code);
|
||||
Lwt.async (fun () ->
|
||||
execute (Js.to_string textbox##.value##trim) ())
|
||||
with
|
||||
(try
|
||||
let code = List.assoc "code" (parse_hash ()) in
|
||||
textbox##.value := Js.string (B64.decode code);
|
||||
Lwt.async (fun () ->
|
||||
execute (Js.to_string textbox##.value##trim) ())
|
||||
with
|
||||
| Not_found -> ()
|
||||
| exc ->
|
||||
Firebug.console##log_3 (Js.string "exception")
|
||||
(Js.string (Printexc.to_string exc))
|
||||
exc
|
||||
exc);
|
||||
execute
|
||||
|
||||
Reference in New Issue
Block a user