Skip to content

edit: buffer: don't panic in focus_hint_y on initial conditions

Frans Klaver requested to merge fransklaver/sodium:fix-panic-on-double-dG into master

A panic occurs whenever dG is executed twice somewhere halfway through the buffer:

  • Start sodium
  • Add a couple of lines of text (5 or so)
  • Move to line 3
  • dG
  • dG panic.

This panic occurs when the buffer is remarkably like the initial conditions we get when opening a buffer from_str.

This boils down to an off-by-one-error in the split buffer, where the assumption is that the y coordinate should be equal to the size of before buffer. However, all initial conditions seem to indicate that the before buffer is filled with at least one element (which is the current line), thereby defining y to be self.before.len() - 1. After all, with just one line in the buffer, the y coordinate can never be 1.

Merge request reports