Skip to content

Commit a3d44d3

Browse files
committed
Engine: fix exception when unfocusing too much
1 parent aa938b9 commit a3d44d3

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

src/engine/actions.ml

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ module AttributeActions = struct
5353
let unfocus window elem =
5454
let action _elem =
5555
let> coord = State.Focus.pop () in
56-
Window.move window coord ~delay:1.0
56+
match coord with
57+
| None -> UndoMonad.return ()
58+
| Some coord -> Window.move window coord ~delay:1.0
5759
in
5860
act_on_elem "unfocus-at-unpause" action elem
5961

src/engine/state.ml

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ module Focus = struct
2525
UndoMonad.return ~undo (Stack.push c stack)
2626

2727
let pop () =
28-
let value = Stack.pop stack in
29-
let undo () = Fut.return @@ Stack.push value stack in
28+
let value = Stack.pop_opt stack in
29+
let undo () =
30+
Fut.return @@ Option.iter (fun v -> Stack.push v stack) value
31+
in
3032
UndoMonad.return ~undo value
3133
end

src/engine/state.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ val incr_step : unit -> unit UndoMonad.t
55

66
module Focus : sig
77
val push : Coordinates.window -> unit UndoMonad.t
8-
val pop : unit -> Coordinates.window UndoMonad.t
8+
val pop : unit -> Coordinates.window option UndoMonad.t
99
end

0 commit comments

Comments
 (0)