diff --git a/src/ace-lib/ace.ml b/src/ace-lib/ace.ml index 2bbe01e06..951d102c1 100644 --- a/src/ace-lib/ace.ml +++ b/src/ace-lib/ace.ml @@ -88,7 +88,7 @@ let set_synchronized_status editor status = let focus { editor } = editor##focus -let create_editor editor_div check_valid_state = +let create_editor editor_div = let editor = edit editor_div in Js.Unsafe.set editor "$blockScrolling" (Js.Unsafe.variable "Infinity"); let data = @@ -102,8 +102,6 @@ let create_editor editor_div check_valid_state = editor##.customData := (data, None); editor##setOption (Js.string "displayIndentGuides") (Js.bool false); editor##on (Js.string "change") (fun () -> - check_valid_state (set_contents data) (fun () -> focus data) - (fun () -> set_synchronized_status data true); set_synchronized_status data false); data diff --git a/src/ace-lib/ace.mli b/src/ace-lib/ace.mli index 6b922b2c1..32bd13b82 100644 --- a/src/ace-lib/ace.mli +++ b/src/ace-lib/ace.mli @@ -17,8 +17,7 @@ type loc = { loc_end: int * int; } -val create_editor: Dom_html.divElement Js.t - -> ((string -> unit) -> (unit -> unit) -> (unit -> unit) -> unit) -> 'a editor +val create_editor: Dom_html.divElement Js.t -> 'a editor val is_synchronized : 'a editor -> bool diff --git a/src/ace-lib/ocaml_mode.ml b/src/ace-lib/ocaml_mode.ml index 46278c8a7..c5bd1fecb 100644 --- a/src/ace-lib/ocaml_mode.ml +++ b/src/ace-lib/ocaml_mode.ml @@ -514,8 +514,8 @@ let do_delete ace_editor = Ace.remove ace_editor "left" end -let create_ocaml_editor div check_valid_state = - let ace = Ace.create_editor div check_valid_state in +let create_ocaml_editor div = + let ace = Ace.create_editor div in Ace.set_mode ace "ace/mode/ocaml.ocp"; Ace.set_tab_size ace !config.indent.IndentConfig.i_base; let editor = { ace; current_error = None; current_warnings = [] } in diff --git a/src/ace-lib/ocaml_mode.mli b/src/ace-lib/ocaml_mode.mli index c86baae05..035058939 100644 --- a/src/ace-lib/ocaml_mode.mli +++ b/src/ace-lib/ocaml_mode.mli @@ -24,8 +24,7 @@ type error = msg list type warning = error -val create_ocaml_editor: - Dom_html.divElement Js.t -> ((string -> unit) -> (unit -> unit) -> (unit -> unit) -> unit) -> editor +val create_ocaml_editor: Dom_html.divElement Js.t -> editor val get_editor: editor -> editor Ace.editor val report_error: editor -> ?set_class: bool -> error option -> warning list -> unit Lwt.t diff --git a/src/app/learnocaml_common.ml b/src/app/learnocaml_common.ml index 08a10575a..787753f56 100644 --- a/src/app/learnocaml_common.ml +++ b/src/app/learnocaml_common.ml @@ -712,72 +712,11 @@ let mouseover_toggle_signal elt sigvalue setter = in Manip.Ev.onmouseover elt hdl -(* - - If a user has made no change to a solution for the exercise [id] - for 180 seconds, [check_valid_editor_state id] ensures that there is - no more recent version of this solution in the server. If this is - the case, the user is asked if we should download this solution - from the server. - - This function reduces the risk of an involuntary overwriting of a - student solution when the solution is open in several clients. - -*) -let is_synchronized_with_server_callback = ref (fun () -> false) - -let is_synchronized_with_server () = !is_synchronized_with_server_callback () - -let check_valid_editor_state id = - let last_changed = ref (Unix.gettimeofday ()) in - fun update_content focus_back on_sync -> - let update_local_copy checking_time () = - let get_solution () = - Learnocaml_local_storage.(retrieve (exercise_state id)).Answer.solution in - try let mtime = - Learnocaml_local_storage.(retrieve (exercise_state id)).Answer.mtime in - if mtime > checking_time then begin - let buttons = - if is_synchronized_with_server () then - [ - [%i "Fetch from server"], - (fun () -> let solution = get_solution () in - Lwt.return (focus_back (); update_content solution; on_sync ())); - [%i "Ignore & keep editing"], - (fun () -> Lwt.return (focus_back ())); - ] - else - [ - [%i "Ignore & keep editing"], - (fun () -> Lwt.return (focus_back ())); - [%i "Fetch from server & overwrite"], - (fun () -> let solution = get_solution () in - Lwt.return (focus_back (); update_content solution; on_sync ())); - ] - in - lwt_alert ~title:"Question" - ~buttons - [ H.p [H.txt [%i "A more recent answer exists on the server. \ - Do you want to fetch the new version?"] ] ] - end else Lwt.return_unit - with - | Not_found -> Lwt.return () - in - let now = Unix.gettimeofday () in - if now -. !last_changed > 180. then ( - let checking_time = !last_changed in - last_changed := now; - Lwt.async (update_local_copy checking_time) - ) else - last_changed := now - - let ace_display tab = let ace = lazy ( let answer = Ocaml_mode.create_ocaml_editor (Tyxml_js.To_dom.of_div tab) - (fun _ _ _ -> ()) in let ace = Ocaml_mode.get_editor answer in Ace.set_font_size ace 16; @@ -983,12 +922,11 @@ module Editor_button (E : Editor_info) = struct end -let setup_editor id solution = +let setup_editor solution = let editor_pane = find_component "learnocaml-exo-editor-pane" in let editor = Ocaml_mode.create_ocaml_editor (Tyxml_js.To_dom.of_div editor_pane) - (check_valid_editor_state id) in let ace = Ocaml_mode.get_editor editor in Ace.set_contents ace ~reset_undo:true solution; diff --git a/src/app/learnocaml_common.mli b/src/app/learnocaml_common.mli index 754d7f4cc..55a08f86f 100644 --- a/src/app/learnocaml_common.mli +++ b/src/app/learnocaml_common.mli @@ -218,9 +218,7 @@ module Editor_button (_ : Editor_info) : sig val sync : Token.t option Lwt.t -> Learnocaml_data.SMap.key -> (unit -> unit) -> unit end -val setup_editor : string -> string -> Ocaml_mode.editor * Ocaml_mode.editor Ace.editor - -val is_synchronized_with_server_callback : (unit -> bool) ref +val setup_editor : string -> Ocaml_mode.editor * Ocaml_mode.editor Ace.editor val typecheck : Learnocaml_toplevel.t -> diff --git a/src/app/learnocaml_exercise_main.ml b/src/app/learnocaml_exercise_main.ml index bea8bde16..f9130eef9 100644 --- a/src/app/learnocaml_exercise_main.ml +++ b/src/app/learnocaml_exercise_main.ml @@ -179,8 +179,7 @@ let () = Tyxml_js.Html5.[ h1 [ txt ex_meta.Exercise.Meta.title ] ; Tyxml_js.Of_dom.of_iFrame text_iframe ] ; (* ---- editor pane --------------------------------------------------- *) - let editor, ace = setup_editor id solution in - is_synchronized_with_server_callback := (fun () -> Ace.is_synchronized ace); + let editor, ace = setup_editor solution in let module EB = Editor_button (struct let ace = ace let buttons_container = editor_toolbar end) in EB.cleanup (Learnocaml_exercise.(access File.template exo)); EB.sync token id (fun () -> Ace.focus ace; Ace.set_synchronized ace) ; diff --git a/src/app/learnocaml_playground_main.ml b/src/app/learnocaml_playground_main.ml index fd12cc7e0..1f53f0695 100644 --- a/src/app/learnocaml_playground_main.ml +++ b/src/app/learnocaml_playground_main.ml @@ -64,7 +64,7 @@ let main () = (* ---- toplevel pane ------------------------------------------------- *) init_toplevel_pane toplevel_launch top toplevel_buttons_group toplevel_button ; (* ---- editor pane --------------------------------------------------- *) - let editor, ace = setup_editor id solution in + let editor, ace = setup_editor solution in let module EB = Editor_button (struct let ace = ace let buttons_container = editor_toolbar end) in EB.cleanup playground.Playground.template; EB.download id;