asottile / babi

a text editor
MIT License
396 stars 46 forks source link

fix Alt-UP crash if first line empty #219

Closed gryzus24 closed 2 years ago

gryzus24 commented 2 years ago

fixes #218

asottile commented 2 years ago

this fix is fairly invasive (essentially a rewrite) -- is there a simpler change that can be done? also this will need a test to demonstrate the breakage -- you can find examples in tests/features/movement_test.py

gryzus24 commented 2 years ago

Yes, we can just add:

if self.buf.y < 0:
    self.buf.y = 0

after every assignment to self.buf.y. Sorry for being too invasive, I just find this implementation slightly more readable. Also I'm not sure how to write a test for this, because for some reason they fail on my machine: FAILED tests/features/movement_test.py::test_indentation_using_tabs[tmux] - AssertionError: Timeout ... ... 44 failed, 586 passed I have tmux installed. Not sure what causes it.

ClasherKasten commented 2 years ago

For me changing the first while-loop to

while (
    self.buf[self.buf.y - offset] == '' and
    self.buf.y - offset - 1 >= 0
):

worked too. I ran coverage and it said 100%.

asottile commented 2 years ago

@gryzus24 I ended up adding you as a co-author on #220

@ClasherKasten in the future it's bad form to attempt a patch while another is in progress -- it's better to work collaboratively instead!