Skip to content

Commit d865a50

Browse files
committed
Move actions down
1 parent e307880 commit d865a50

22 files changed

+315
-172
lines changed

src/web/app/Page.re

Lines changed: 5 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -410,105 +410,6 @@ module Selection = {
410410
~action=inject(Globals(Redo)),
411411
"Redo",
412412
),
413-
/* Navigation */
414-
mk(
415-
~hotkey="F12",
416-
~mdIcon="arrow_forward",
417-
~section="Navigation",
418-
~action=
419-
inject(
420-
Globals(
421-
ActiveEditor(Move(Goal(BindingSiteOfIndicatedVar))),
422-
),
423-
),
424-
"Go to Definition",
425-
),
426-
mk(
427-
~hotkey="shift+tab",
428-
~mdIcon="swipe_left_alt",
429-
~section="Navigation",
430-
~action=inject(Globals(ActiveEditor(Move(Goal(Hole(Left)))))),
431-
"Go to Previous Hole",
432-
),
433-
mk(
434-
~mdIcon="swipe_right_alt",
435-
~section="Navigation",
436-
~action=
437-
inject(Globals(ActiveEditor(Move(Goal(Hole(Right)))))),
438-
"Go To Next Hole",
439-
),
440-
/* Selection */
441-
mk(
442-
~hotkey=meta ++ "+d",
443-
~mdIcon="select_all",
444-
~section="Selection",
445-
~action=inject(Globals(ActiveEditor(Select(Term(Current))))),
446-
"Select current term",
447-
),
448-
mk(
449-
~mdIcon="select_all",
450-
~hotkey=meta ++ "+a",
451-
~section="Selection",
452-
~action=inject(Globals(ActiveEditor(Select(All)))),
453-
"Select All",
454-
),
455-
mk(
456-
~mdIcon="flip_horizontal",
457-
~section="Selection",
458-
~action=inject(Globals(ActiveEditor(Select(ToggleFocus)))),
459-
"Toggle Selection Focus",
460-
),
461-
mk(
462-
~mdIcon="border_left",
463-
~section="Selection",
464-
~hotkey=meta ++ "+alt+shift+left",
465-
~action=inject(Globals(ActiveEditor(Select(SetFocus(Left))))),
466-
"Set Selection Focus Left",
467-
),
468-
mk(
469-
~mdIcon="border_right",
470-
~section="Selection",
471-
~hotkey=meta ++ "+alt+shift+right",
472-
~action=inject(Globals(ActiveEditor(Select(SetFocus(Right))))),
473-
"Set Selection Focus Right",
474-
),
475-
/* Projection */
476-
mk(
477-
~hotkey="alt+f",
478-
~mdIcon="camera",
479-
~section="Projection",
480-
~action=
481-
inject(
482-
Globals(
483-
ActiveEditor(Project(SetIndicated(Specific(Fold)))),
484-
),
485-
),
486-
"Fold",
487-
),
488-
mk(
489-
~hotkey=meta ++ "+e",
490-
~mdIcon="camera",
491-
~section="Projection",
492-
~action=inject(Globals(ActiveEditor(Probe(ToggleManual)))),
493-
"Probe",
494-
),
495-
mk(
496-
~hotkey="alt+t",
497-
~mdIcon="camera",
498-
~section="Projection",
499-
~action=inject(Globals(ActiveEditor(Probe(ToggleStatics)))),
500-
"Statics",
501-
),
502-
mk(
503-
~hotkey="alt+l",
504-
~mdIcon="camera",
505-
~section="Projection",
506-
~action=
507-
inject(
508-
Globals(ActiveEditor(Project(SetIndicated(ChooseLivelit)))),
509-
),
510-
"Livelit",
511-
),
512413
/* Settings */
513414
mk(
514415
~section="Settings",
@@ -600,39 +501,20 @@ module Selection = {
600501
~action=inject(Globals(Set(ExplainThis(ToggleShowFeedback)))),
601502
"Toggle Show Docs Feedback",
602503
),
603-
/* Editor tools */
604-
mk(
605-
~hotkey=meta ++ "+/",
606-
~mdIcon="assistant",
607-
~action=inject(Globals(ActiveEditor(Buffer(Set(TyDi))))),
608-
"TyDi Assistant",
609-
),
504+
/* Export / Diagnostics */
610505
mk(
611506
~mdIcon="download",
612507
~section="Export",
613508
~action=inject(Globals(ExportForInit)),
614509
"Export For Init",
615510
),
616-
mk(
617-
~section="Diagnostics",
618-
~mdIcon="refresh",
619-
~action=inject(Globals(ActiveEditor(Reparse))),
620-
"Reparse Current Editor",
621-
),
622511
mk(
623512
~mdIcon="timer",
624513
~section="Diagnostics",
625514
~hotkey="F7",
626515
~action=inject(Benchmark(Start)),
627516
"Run Benchmark",
628517
),
629-
mk(
630-
~mdIcon="bolt",
631-
~section="Refactoring",
632-
~hotkey=meta ++ "+i",
633-
~action=inject(Globals(ActiveEditor(Introduce))),
634-
"Introduce",
635-
),
636518
]);
637519
};
638520
};
@@ -799,7 +681,10 @@ module View = {
799681
Effect.Ignore;
800682
} else {
801683
copy(cursor);
802-
inject(Globals(ActiveEditor(Destruct(Right))));
684+
switch (cursor.editor_action(Destruct(Right))) {
685+
| Some(action) => inject(Editors(action))
686+
| None => Effect.Ignore
687+
};
803688
};
804689
| None => Effect.Ignore
805690
};

src/web/app/editors/cell/CellEditor.re

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,25 @@ module Selection = {
151151
| MainEditor
152152
| Result(EvalResult.Selection.t);
153153

154-
let get_cursor_info = (~selection, model: Model.t): cursor(Update.t) => {
154+
let get_cursor_info =
155+
(~inject: Update.t => Ui_effect.t(unit), ~selection, model: Model.t)
156+
: cursor(Update.t) => {
155157
switch (selection) {
156158
| MainEditor =>
157159
let+ ci =
158-
CodeEditable.Selection.get_cursor_info(~selection=(), model.editor);
160+
CodeEditable.Selection.get_cursor_info(
161+
~inject=a => inject(MainEditor(a)),
162+
~selection=(),
163+
model.editor,
164+
);
159165
Update.MainEditor(ci);
160166
| Result(selection) =>
161167
let+ ci =
162-
EvalResult.Selection.get_cursor_info(~selection, model.result);
168+
EvalResult.Selection.get_cursor_info(
169+
~inject=a => inject(ResultAction(a)),
170+
~selection,
171+
model.result,
172+
);
163173
Update.ResultAction(ci);
164174
};
165175
};

src/web/app/editors/code/CodeEditable.re

Lines changed: 119 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,130 @@ module Selection = {
136136
[@deriving (show({with_path: false}), sexp, yojson)]
137137
type t = unit;
138138

139-
let get_cursor_info = (~selection as (), model: Model.t): cursor(Update.t) => {
139+
let get_cursor_info =
140+
(
141+
~inject: Update.t => Ui_effect.t(unit),
142+
~selection as (),
143+
model: Model.t,
144+
)
145+
: cursor(Update.t) => {
146+
let sys = Util.Os.is_mac^ ? Util.Key.Mac : PC;
147+
let meta = Keyboard.meta(sys);
148+
let mk = ContextualAction.mk;
149+
let action = a => inject(Perform(a));
140150
{
141151
...
142152
CodeWithStatics.Model.get_cursor_info(model)
143153
|> map(x => Update.Perform(x)),
144154
editor_read_only: false,
145-
};
155+
}
156+
|> Cursor.with_actions([
157+
/* Navigation */
158+
mk(
159+
~hotkey="F12",
160+
~mdIcon="arrow_forward",
161+
~section="Navigation",
162+
~action=action(Move(Goal(BindingSiteOfIndicatedVar))),
163+
"Go to Definition",
164+
),
165+
mk(
166+
~hotkey="shift+tab",
167+
~mdIcon="swipe_left_alt",
168+
~section="Navigation",
169+
~action=action(Move(Goal(Hole(Left)))),
170+
"Go to Previous Hole",
171+
),
172+
mk(
173+
~mdIcon="swipe_right_alt",
174+
~section="Navigation",
175+
~action=action(Move(Goal(Hole(Right)))),
176+
"Go To Next Hole",
177+
),
178+
/* Selection */
179+
mk(
180+
~hotkey=meta ++ "+d",
181+
~mdIcon="select_all",
182+
~section="Selection",
183+
~action=action(Select(Term(Current))),
184+
"Select current term",
185+
),
186+
mk(
187+
~mdIcon="select_all",
188+
~hotkey=meta ++ "+a",
189+
~section="Selection",
190+
~action=action(Select(All)),
191+
"Select All",
192+
),
193+
mk(
194+
~mdIcon="flip_horizontal",
195+
~section="Selection",
196+
~action=action(Select(ToggleFocus)),
197+
"Toggle Selection Focus",
198+
),
199+
mk(
200+
~mdIcon="border_left",
201+
~section="Selection",
202+
~hotkey=meta ++ "+alt+shift+left",
203+
~action=action(Select(SetFocus(Left))),
204+
"Set Selection Focus Left",
205+
),
206+
mk(
207+
~mdIcon="border_right",
208+
~section="Selection",
209+
~hotkey=meta ++ "+alt+shift+right",
210+
~action=action(Select(SetFocus(Right))),
211+
"Set Selection Focus Right",
212+
),
213+
/* Projection */
214+
mk(
215+
~hotkey="alt+f",
216+
~mdIcon="camera",
217+
~section="Projection",
218+
~action=action(Project(SetIndicated(Specific(Fold)))),
219+
"Fold",
220+
),
221+
mk(
222+
~hotkey=meta ++ "+e",
223+
~mdIcon="camera",
224+
~section="Projection",
225+
~action=action(Probe(ToggleManual)),
226+
"Probe",
227+
),
228+
mk(
229+
~hotkey="alt+t",
230+
~mdIcon="camera",
231+
~section="Projection",
232+
~action=action(Probe(ToggleStatics)),
233+
"Statics",
234+
),
235+
mk(
236+
~hotkey="alt+l",
237+
~mdIcon="camera",
238+
~section="Projection",
239+
~action=action(Project(SetIndicated(ChooseLivelit))),
240+
"Livelit",
241+
),
242+
/* Editor tools */
243+
mk(
244+
~hotkey=meta ++ "+/",
245+
~mdIcon="assistant",
246+
~action=action(Buffer(Set(TyDi))),
247+
"TyDi Assistant",
248+
),
249+
mk(
250+
~section="Diagnostics",
251+
~mdIcon="refresh",
252+
~action=inject(Perform(Reparse)),
253+
"Reparse Current Editor",
254+
),
255+
mk(
256+
~mdIcon="bolt",
257+
~section="Refactoring",
258+
~hotkey=meta ++ "+i",
259+
~action=action(Introduce),
260+
"Introduce",
261+
),
262+
]);
146263
};
147264

148265
let handle_key_event =

src/web/app/editors/code/CodeSelectable.re

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,17 @@ module Update = {
6363
module Selection = {
6464
[@deriving (show({with_path: false}), sexp, yojson)]
6565
type t = CodeEditable.Selection.t;
66-
let get_cursor_info = (~selection, model) =>
67-
CodeEditable.Selection.get_cursor_info(~selection, model)
66+
let get_cursor_info = (~inject, ~selection, model) =>
67+
CodeEditable.Selection.get_cursor_info(
68+
~inject=
69+
a =>
70+
switch (Update.convert_action(a)) {
71+
| Some(action) => inject(action)
72+
| None => Ui_effect.Ignore
73+
},
74+
~selection,
75+
model,
76+
)
6877
|> (
6978
ci =>
7079
Cursor.{

src/web/app/editors/mode/ExercisesMode.re

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,21 @@ module Selection = {
445445
let cursor =
446446
switch (current, selection) {
447447
| (Implementation(e), Implementation(selection)) =>
448-
let+ ci = ExerciseMode.Selection.get_cursor_info(~selection, e);
448+
let+ ci =
449+
ExerciseMode.Selection.get_cursor_info(
450+
~inject=a => inject(Exercise(a)),
451+
~selection,
452+
e,
453+
);
449454
Update.Exercise(ci);
450455
| (Implementation(_), _) => Cursor.empty
451456
| (Theorem(e), TheoremExercise(selection)) =>
452457
let+ ci =
453-
TheoremExerciseMode.Selection.get_cursor_info(~selection, e);
458+
TheoremExerciseMode.Selection.get_cursor_info(
459+
~inject=a => inject(TheoremExercise(a)),
460+
~selection,
461+
e,
462+
);
454463
Update.TheoremExercise(ci);
455464
| (Theorem(_), _) => Cursor.empty
456465
};

src/web/app/editors/mode/TutorialsMode.re

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,11 @@ module Selection = {
301301
[@deriving (show({with_path: false}), sexp, yojson)]
302302
type t = TutorialMode.Selection.t;
303303
let get_cursor_info =
304-
(
305-
~inject as _: Update.t => Ui_effect.t(unit),
306-
~selection,
307-
model: Model.t,
308-
)
304+
(~inject: Update.t => Ui_effect.t(unit), ~selection, model: Model.t)
309305
: cursor(Update.t) => {
310306
let+ ci =
311307
TutorialMode.Selection.get_cursor_info(
308+
~inject=a => inject(Tutorial(a)),
312309
~selection,
313310
List.nth(model.exercises, model.current),
314311
);

0 commit comments

Comments
 (0)