Skip to content

Commit

Permalink
Disable projector panel in read-only editors
Browse files Browse the repository at this point in the history
(for now)
  • Loading branch information
Negabinary committed Nov 22, 2024
1 parent cea32f1 commit da47c27
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/haz3lweb/app/Cursor.re
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/haz3lweb/app/editors/code/CodeEditable.re
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
Expand Down
1 change: 1 addition & 0 deletions src/haz3lweb/app/editors/code/CodeSelectable.re
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
1 change: 1 addition & 0 deletions src/haz3lweb/app/editors/code/CodeWithStatics.re
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 12 additions & 10 deletions src/haz3lweb/app/inspector/ProjectorPanel.re
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand All @@ -107,16 +110,15 @@ 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=[
Attr.on_change((_, name) =>
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)),
);
Expand All @@ -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")],
Expand Down

0 comments on commit da47c27

Please sign in to comment.