Skip to content

Commit

Permalink
Prevented caret scrolling (through switch in main.apply function) whe…
Browse files Browse the repository at this point in the history
…n editing title
  • Loading branch information
russell-rozenbaum committed Nov 17, 2024
1 parent fa62a34 commit 4dae0f6
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/haz3lschool/Exercise.re
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,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 @@

6 changes: 3 additions & 3 deletions src/haz3lweb/UpdateAction.re
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ let should_scroll_to_caret =
fun
| Set(s_action) =>
switch (s_action) {
| EditingTitle => false
| Mode(_) => true
| Captions
| SecondaryIcons
Expand All @@ -235,7 +236,6 @@ let should_scroll_to_caret =
| Benchmark
| ContextInspector
| InstructorMode
| EditingTitle
| Evaluation(_) => false
}
| SetMeta(meta_action) =>
Expand All @@ -248,8 +248,6 @@ let should_scroll_to_caret =
| UpdateResult(_)
| ToggleStepper(_)
| UpdateTitle(_)
| AddBuggyImplementation
| DeleteBuggyImplementation(_)
| StepperAction(_, StepBackward | StepForward(_)) => false
| FinishImportScratchpad(_)
| FinishImportAll(_)
Expand All @@ -261,6 +259,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 @@ -25,7 +25,7 @@ let key_handler =
| None => Ignore
| Some(action) =>
get_settings(model).editing_title
? Many([inject(action)])
? Many([Stop_propagation, inject(action)])
: Many([Prevent_default, Stop_propagation, inject(action)])
}
};
Expand Down Expand Up @@ -100,9 +100,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 4dae0f6

Please sign in to comment.