ocaml-community / zed

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

`kill_next_word` should not raise `Out_of_bound` #55

Closed Lucccyo closed 1 year ago

Lucccyo commented 1 year ago

In Zed_edit, function default_match_word (which is used by default in Zed_edit.create) returns the next end-of-word position as relative to the current cursor. However, the users of default_match_word, such as kill_next_word, prev_word, next_word, etc., interpret the returned value as an absolute position.

Fixes #49.

Lucccyo commented 1 year ago

I'm very sorry about that. I finished the PR description yesterday. This PR was still in progress, but many thanks for the review!

tmattio commented 1 year ago

I'm very sorry about that. I finished the PR description yesterday.

No worries at all 🙂

The change looks good, could you also add a test to demonstrate the issue and that the patch fixes it? Possibly by re-using the example in #49:

let () =
  let engine = Zed_edit.create () in
  let cursor = Zed_edit.new_cursor engine in
  let ctxt = Zed_edit.context engine cursor in
  Zed_edit.insert ctxt (Zed_rope.of_string (Zed_string.of_utf8 "hello"));
  Zed_edit.set_mark ctxt;
  Zed_edit.insert ctxt (Zed_rope.of_string (Zed_string.of_utf8 " world"));
  Zed_edit.goto_mark ctxt;
  Zed_edit.kill_next_word ctxt
Lucccyo commented 1 year ago

Yes, good idea!

tmattio commented 1 year ago

Merging without the test, I'll have a look at the test suite in a follow up PR.