ocaml-community / zed

Abstract engine for text edition in OCaml
Other
121 stars 16 forks source link

lambda-term 3.3.x regression: broken alt-b/alt-f key bindings #58

Closed Armael closed 1 year ago

Armael commented 2 years ago

Lambda-term version 3.3.x seems to have broken the behavior of the alt-b / alt-f keybindings for moving with word-level granularity.

Minimal (?) example:

class read_line ~term ~prompt = object(self)
  inherit LTerm_read_line.read_line ()
  inherit [Zed_string.t] LTerm_read_line.term term

  method! show_box = false

  initializer
    self#set_prompt
      (React.S.const
         (LTerm_text.of_string_maybe_invalid prompt))
end

let read_line ?(prompt = "") ?(initial_text = "") () =
  let open Lwt in
  let main =
    Lazy.force LTerm.stdout >>= fun term ->
    let engine = new read_line ~term ~prompt:(Zed_string.of_utf8 prompt) in
    Uutf.String.fold_utf_8 (fun () _ elt ->
      match elt with
(* the following line works with lambda-term 3.3.x *)
      | `Uchar c -> engine#insert c
(* with lambda-term 3.2.0, use the following line instead: *)
(*      | `Uchar c -> engine#insert (CamomileLibrary.UChar.of_int (Uchar.to_int c)) *)
      | `Malformed _ -> ()
    ) () initial_text;
    engine#run
  in
  Lwt_main.run main |> Zed_string.to_utf8

let () = print_endline @@ read_line ~initial_text:"hello world" ()

With lambda-term 3.2.0 (modulo tweaking the relevant line), everything works fine. With lambda-term 3.3.0, hitting alt-b then alt-f repeatedly jumps between the e and o letters of hello, instead of behaving as expected.

Armael commented 2 years ago

(I hit enter too fast initially submitting an issue with empty text, so apologies in advance for anyone who received an empty mail. I've now edited the text of the initial post.)

dunrix commented 1 year ago

bump

Same issue, manifesting in utop, a lambda-term based app.

kandu commented 1 year ago

This bug comes from when switching from camomile to uuseg,

function https://github.com/ocaml-community/zed/blob/79b4b9b0d31c09f4fb58ed44713570752b7d994d/src/zed_edit.ml#L106-L109

was replaced by https://github.com/ocaml-community/zed/blob/bb78fec8999a7c205fd060288544a0065dc1cc14/src/zed_edit.ml#L86-L106

This new function doesn't deal with some conditions well.

And because the previous function do word matching by regexp `Alphabetic plus 1 2 3 4 5 6 7 8 9 0, but the new function do it by uuseg's word segmentation algorithm. Other depending functions also need some tweaks.

kandu commented 1 year ago

The new opam package is waiting to be merged here.