From da47c2795ac1be9f71d46009065435e21ccb82a2 Mon Sep 17 00:00:00 2001 From: Matt Keenan Date: Fri, 22 Nov 2024 12:03:12 -0500 Subject: [PATCH] Disable projector panel in read-only editors (for now) --- src/haz3lweb/app/Cursor.re | 2 ++ src/haz3lweb/app/editors/code/CodeEditable.re | 1 + .../app/editors/code/CodeSelectable.re | 1 + .../app/editors/code/CodeWithStatics.re | 1 + src/haz3lweb/app/inspector/ProjectorPanel.re | 22 ++++++++++--------- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/haz3lweb/app/Cursor.re b/src/haz3lweb/app/Cursor.re index f5a483c60e..9265d154fc 100644 --- a/src/haz3lweb/app/Cursor.re +++ b/src/haz3lweb/app/Cursor.re @@ -2,6 +2,7 @@ type cursor('update) = { info: option(Haz3lcore.Info.t), selected_text: option(unit => string), editor: option(Haz3lcore.Editor.t), + editor_read_only: bool, editor_action: Haz3lcore.Action.t => option('update), undo_action: option('update), redo_action: option('update), @@ -25,6 +26,7 @@ let empty = { info: None, selected_text: None, editor: None, + editor_read_only: false, editor_action: _ => None, undo_action: None, redo_action: None, diff --git a/src/haz3lweb/app/editors/code/CodeEditable.re b/src/haz3lweb/app/editors/code/CodeEditable.re index 9745fb3809..3764fdb2dd 100644 --- a/src/haz3lweb/app/editors/code/CodeEditable.re +++ b/src/haz3lweb/app/editors/code/CodeEditable.re @@ -105,6 +105,7 @@ module Selection = { ... CodeWithStatics.Model.get_cursor_info(model) |> map(x => Update.Perform(x)), + editor_read_only: false, undo_action: Some(Update.Undo), redo_action: Some(Update.Redo), }; diff --git a/src/haz3lweb/app/editors/code/CodeSelectable.re b/src/haz3lweb/app/editors/code/CodeSelectable.re index 36c30af2d4..e063a74903 100644 --- a/src/haz3lweb/app/editors/code/CodeSelectable.re +++ b/src/haz3lweb/app/editors/code/CodeSelectable.re @@ -60,6 +60,7 @@ module Selection = { type t = CodeEditable.Selection.t; let get_cursor_info = (~selection, model) => CodeEditable.Selection.get_cursor_info(~selection, model) + |> (ci => Cursor.{...ci, editor_read_only: true}) |> Cursor.map_opt(Update.convert_action); let handle_key_event = (~selection, model: Model.t, key: Key.t): option(Update.t) => diff --git a/src/haz3lweb/app/editors/code/CodeWithStatics.re b/src/haz3lweb/app/editors/code/CodeWithStatics.re index b183e3c861..56d2d15ecc 100644 --- a/src/haz3lweb/app/editors/code/CodeWithStatics.re +++ b/src/haz3lweb/app/editors/code/CodeWithStatics.re @@ -33,6 +33,7 @@ module Model = { selected_text: Some(() => Printer.to_string_selection(model.editor.state.zipper)), editor: Some(model.editor), + editor_read_only: true, editor_action: x => Some(x), undo_action: None, redo_action: None, diff --git a/src/haz3lweb/app/inspector/ProjectorPanel.re b/src/haz3lweb/app/inspector/ProjectorPanel.re index 3fc7fbd0a0..6a19da402c 100644 --- a/src/haz3lweb/app/inspector/ProjectorPanel.re +++ b/src/haz3lweb/app/inspector/ProjectorPanel.re @@ -88,13 +88,16 @@ let id = (editor: option(Editor.t)) => { |> Option.value(~default=Id.invalid); }; -let might_project: option(Editor.t) => bool = - fun - | None => false - | Some(editor) => - switch (Indicated.piece''(editor.state.zipper)) { +let might_project: Cursor.cursor(Editors.Update.t) => bool = + cursor => + switch (cursor.editor) { + | _ when cursor.editor_read_only => false | None => false - | Some((p, _, _)) => minimum_projection_condition(p) + | Some(editor) => + switch (Indicated.piece''(editor.state.zipper)) { + | None => false + | Some((p, _, _)) => minimum_projection_condition(p) + } }; let currently_selected = editor => @@ -107,8 +110,7 @@ let currently_selected = editor => let view = (~inject, cursor: Cursor.cursor(Editors.Update.t)) => { let applicable_projectors = applicable_projectors(cursor.info); - let should_show = - might_project(cursor.editor) && applicable_projectors != []; + let should_show = might_project(cursor) && applicable_projectors != []; let select_view = Node.select( ~attrs=[ @@ -116,7 +118,7 @@ let view = (~inject, cursor: Cursor.cursor(Editors.Update.t)) => { inject(Action.SetIndicated(ProjectorView.of_name(name))) ), ], - (might_project(cursor.editor) ? applicable_projectors : []) + (might_project(cursor) ? applicable_projectors : []) |> List.map(ProjectorView.name) |> List.map(currently_selected(cursor.editor)), ); @@ -126,7 +128,7 @@ let view = (~inject, cursor: Cursor.cursor(Editors.Update.t)) => { cursor.info, id(cursor.editor), kind(cursor.editor) != None, - might_project(cursor.editor), + might_project(cursor), ); div( ~attrs=[Attr.id("projectors")],