Commit 45bd8fc7 authored by Guillaume Melquiond's avatar Guillaume Melquiond

Use the undo stack to detect unsaved changes.

parent bc0077ec
......@@ -38,11 +38,19 @@ module Ace () = struct
method setSelectionRange : range t -> bool t -> unit meth
end
class type undoManager =
object
method hasRedo : bool t meth
method hasUndo : bool t meth
method reset : unit meth
end
class type editSession =
object
method addMarker : range t -> js_string t -> js_string t -> bool t -> marker meth
method clearAnnotations : unit meth
method getLength : int meth
method getUndoManager : undoManager t meth
method removeMarker : marker -> unit meth
method setAnnotations : annotation t js_array t -> unit meth
method setMode : js_string t -> unit meth
......
......@@ -128,7 +128,6 @@ module Ace = Ace ()
module Editor =
struct
let name = ref (Js.string "")
let saved = ref false
let editor =
let e = Ace.edit (Js.string "why3-editor") in
......@@ -178,7 +177,8 @@ module Editor =
editor ## getValue
let set_value ?(editor=editor) str =
editor ## setValue str ~-1
editor ## setValue str ~-1;
editor ## getSession ## getUndoManager ## reset
let mk_range l1 c1 l2 c2 =
new%js Ace.range l1 c1 l2 c2
......@@ -234,7 +234,7 @@ module Editor =
let confirm_unsaved () =
if not !saved then
if Js.to_bool (editor ## getSession ## getUndoManager ## hasUndo) then
Js.to_bool
(Dom_html.window ## confirm (Js.string "You have unsaved changes in your editor, proceed anyway ?"))
else
......@@ -565,7 +565,6 @@ module TaskList =
Editor.set_on_event "change"
(Js.wrap_callback (fun () ->
clear ();
Editor.saved := false;
ExampleList.unselect ();
Editor.clear_annotations ();
Editor.update_error_marker None))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment