Skip to content

Commit

Permalink
Fixed caret scrolling following title-editor branch changes
Browse files Browse the repository at this point in the history
  • Loading branch information
facundoy committed Nov 25, 2024
1 parent 02f21d4 commit 95a7593
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/haz3lschool/Exercise.re
Original file line number Diff line number Diff line change
Expand Up @@ -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.
};
Expand Down
68 changes: 41 additions & 27 deletions src/haz3lweb/Main.re
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
};

Expand Down
1 change: 1 addition & 0 deletions src/haz3lweb/Main.rei
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

16 changes: 8 additions & 8 deletions src/haz3lweb/UpdateAction.re
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -265,12 +271,6 @@ let should_scroll_to_caret =
| Benchmark
| ContextInspector
| InstructorMode
| EditingTitle
| EditingPrompt
| EditingTestValRep
| EditingMutTestRep
| EditingImplGrdRep
| EditingModuleName
| Evaluation(_) => false
}
| SetMeta(meta_action) =>
Expand All @@ -283,8 +283,6 @@ let should_scroll_to_caret =
| UpdateResult(_)
| ToggleStepper(_)
| UpdateTitle(_)
| AddBuggyImplementation
| DeleteBuggyImplementation(_)
| UpdatePrompt(_)
| UpdateTestValRep(_)
| UpdateMutTestRep(_)
Expand All @@ -301,6 +299,8 @@ let should_scroll_to_caret =
| Undo
| Redo
| TAB
| AddBuggyImplementation
| DeleteBuggyImplementation(_)
| Startup => true
| PerformAction(a) =>
switch (a) {
Expand Down
4 changes: 1 addition & 3 deletions src/haz3lweb/view/Page.re
Original file line number Diff line number Diff line change
Expand Up @@ -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)]);
}
};
Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit 95a7593

Please sign in to comment.