diff --git a/ogui.ml b/ogui.ml index 00a0dbd..192c9b1 100644 --- a/ogui.ml +++ b/ogui.ml @@ -696,11 +696,10 @@ module Ui = struct let process_events (ui : t) (events : event Lwt_stream.t) : unit = Lwt.async (fun () -> - let rec proc ?(skip : event option) - (r : action list Event.result) : + let rec proc (r : action list Event.result) : action list Event.result Lwt.t = Lwt_stream.last_new events >>= function - | `Key (state, key, mods) -> ( + | `Key (state, key, mods) -> process_key ui r state key mods >>= fun (res : action list Event.result) -> Event.( @@ -710,25 +709,29 @@ module Ui = struct | Accepted _ -> "Accepted" | Continue _ -> "Continue" | Rejected -> "Rejected")); - Lwt_stream.peek events >>= function - | Some (`Char cc) -> ( - match res with - | Accepted _ | Continue _ -> - F.epr - "Ui.process_events Lwt_stream.junk events@."; - proc ~skip:(`Char cc) res - | Rejected -> proc res) - | Some (`Key _) | None -> proc res) - | `Char char -> ( + (match res with + | Accepted _ when mods = [] || mods == [ Shift ] -> ( + (* junk the `Char that is sent with a `Key that has no mods *) + Lwt_stream.peek events + >>= function + | Some (`Char _) -> Lwt_stream.junk events + | _ -> Lwt.return_unit) + | Accepted _ | Continue _ | Rejected -> Lwt.return_unit) + (*Lwt_stream.peek events >>= function + | Some (`Char cc) -> ( + match res with + | Accepted _ | Continue _ -> + F.epr + "Ui.process_events Lwt_stream.junk events@."; + proc ~skip:(`Char cc) res + | Rejected -> ) + | Some (`Key _) | None -> proc res *) + >>= + fun () -> proc res + | `Char char -> F.epr "Ui.process_events `Char '%a'@." pp_uchar (Uchar.of_int char); - match skip with - | Some (`Char c) when c == char -> - F.epr "Ui.process_events skip match@."; - Lwt.return (Event.Accepted []) - | Some _ | None -> - process_char char >>= fun () -> - proc (Event.Accepted [])) + process_char char >>= fun () -> proc (Event.Accepted []) in proc Event.Rejected >>= fun _ -> Lwt.return_unit)