From 95a7593de85d10b0675301d962cd6e74a2ea2181 Mon Sep 17 00:00:00 2001 From: facundoy Date: Sun, 24 Nov 2024 20:40:27 -0500 Subject: [PATCH] Fixed caret scrolling following title-editor branch changes --- src/haz3lschool/Exercise.re | 2 +- src/haz3lweb/Main.re | 68 ++++++++++++++++++++++-------------- src/haz3lweb/Main.rei | 1 + src/haz3lweb/UpdateAction.re | 16 ++++----- src/haz3lweb/view/Page.re | 4 +-- 5 files changed, 52 insertions(+), 39 deletions(-) create mode 100644 src/haz3lweb/Main.rei diff --git a/src/haz3lschool/Exercise.re b/src/haz3lschool/Exercise.re index 8b00d84d1f..b37a37eb6d 100644 --- a/src/haz3lschool/Exercise.re +++ b/src/haz3lschool/Exercise.re @@ -150,7 +150,7 @@ module F = (ExerciseEnv: ExerciseEnv) => { // how these fields are saved and loaded to and from local memory // respectively. // NOTE: It may be helpful to look at changes made in the mutant-add-delete and title-editor - // branches in the Hazel repo to see and understand where changes + // branches in the Hazel repository to see and understand where changes // were made. It is likely that new implementations of editble features // will follow a similar route. }; diff --git a/src/haz3lweb/Main.re b/src/haz3lweb/Main.re index af8058b770..51e1db527c 100644 --- a/src/haz3lweb/Main.re +++ b/src/haz3lweb/Main.re @@ -21,35 +21,49 @@ let restart_caret_animation = () => let apply = (model, action, ~schedule_action): Model.t => { restart_caret_animation(); - if (UpdateAction.is_edit(action)) { - last_edit_action := JsUtil.timestamp(); - edit_action_applied := true; - }; - if (Update.should_scroll_to_caret(action)) { - scroll_to_caret := true; - }; - last_edit_action := JsUtil.timestamp(); - switch ( - try({ - let new_model = Update.apply(model, action, ~schedule_action); - Log.update(action); - new_model; - }) { - | exc => + + let get_settings = (model: Model.t): Settings.t => model.settings; + + switch (action, get_settings(model).editing_title) { + | (UpdateAction.PerformAction(Insert(_)), true) => model + | (UpdateAction.PerformAction(Destruct(_)), true) => model + | (action, _) => + if (UpdateAction.is_edit(action)) { + last_edit_action := JsUtil.timestamp(); + edit_action_applied := true; + }; + let old_scroll = scroll_to_caret.contents; + if (Update.should_scroll_to_caret(action)) { + scroll_to_caret := true; Printf.printf( - "ERROR: Exception during apply: %s\n", - Printexc.to_string(exc), + "DEBUG: Scroll set to true for action: %s (was: %b)\n", + UpdateAction.show(action), + old_scroll, ); - Error(Exception(Printexc.to_string(exc))); - } - ) { - | Ok(model) => model - | Error(FailedToPerform(err)) => - print_endline(Update.Failure.show(FailedToPerform(err))); - model; - | Error(err) => - print_endline(Update.Failure.show(err)); - model; + }; + last_edit_action := JsUtil.timestamp(); + switch ( + try({ + let new_model = Update.apply(model, action, ~schedule_action); + Log.update(action); + new_model; + }) { + | exc => + Printf.printf( + "ERROR: Exception during apply: %s\n", + Printexc.to_string(exc), + ); + Error(Exception(Printexc.to_string(exc))); + } + ) { + | Ok(model) => model + | Error(FailedToPerform(err)) => + print_endline(Update.Failure.show(FailedToPerform(err))); + model; + | Error(err) => + print_endline(Update.Failure.show(err)); + model; + }; }; }; diff --git a/src/haz3lweb/Main.rei b/src/haz3lweb/Main.rei new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/src/haz3lweb/Main.rei @@ -0,0 +1 @@ + diff --git a/src/haz3lweb/UpdateAction.re b/src/haz3lweb/UpdateAction.re index 30cd8a7f9f..b611f4c44e 100644 --- a/src/haz3lweb/UpdateAction.re +++ b/src/haz3lweb/UpdateAction.re @@ -254,6 +254,12 @@ let should_scroll_to_caret = fun | Set(s_action) => switch (s_action) { + | EditingTitle => false + | EditingPrompt => false + | EditingTestValRep => false + | EditingMutTestRep => false + | EditingImplGrdRep => false + | EditingModuleName => false | Mode(_) => true | Captions | SecondaryIcons @@ -265,12 +271,6 @@ let should_scroll_to_caret = | Benchmark | ContextInspector | InstructorMode - | EditingTitle - | EditingPrompt - | EditingTestValRep - | EditingMutTestRep - | EditingImplGrdRep - | EditingModuleName | Evaluation(_) => false } | SetMeta(meta_action) => @@ -283,8 +283,6 @@ let should_scroll_to_caret = | UpdateResult(_) | ToggleStepper(_) | UpdateTitle(_) - | AddBuggyImplementation - | DeleteBuggyImplementation(_) | UpdatePrompt(_) | UpdateTestValRep(_) | UpdateMutTestRep(_) @@ -301,6 +299,8 @@ let should_scroll_to_caret = | Undo | Redo | TAB + | AddBuggyImplementation + | DeleteBuggyImplementation(_) | Startup => true | PerformAction(a) => switch (a) { diff --git a/src/haz3lweb/view/Page.re b/src/haz3lweb/view/Page.re index 42e3f57ef1..ad2f6f6604 100644 --- a/src/haz3lweb/view/Page.re +++ b/src/haz3lweb/view/Page.re @@ -31,7 +31,7 @@ let key_handler = || settings.editing_mut_test_rep || settings.editing_impl_grd_rep || settings.editing_module_name - ? Many([inject(action)]) + ? Many([Stop_propagation, inject(action)]) : Many([Prevent_default, Stop_propagation, inject(action)]); } }; @@ -111,9 +111,7 @@ let main_view = ~inject: UpdateAction.t => Ui_effect.t(unit), {settings, editors, explainThisModel, results, ui_state, _}: Model.t, ) => { - print_endline("here, at main view, getting editor"); let editor = Editors.get_editor(editors); - print_endline("got editor!"); let cursor_info = Indicated.ci_of(editor.state.zipper, editor.state.meta.statics.info_map); let highlights =