asottile / babi

a text editor
MIT License
396 stars 46 forks source link

jump-by-word (^+right) goes too far when tabs are involved #237

Open asottile opened 2 years ago

asottile commented 2 years ago

compare the following press ^+right when cursor is at left edge depending on whether it's a tab or a space

   word-here
   ^    ^
   |    + tabs stop here
   + spaces stops here
maltarouti commented 2 years ago

I would like to take this issue, but I'm not totally sure if I get it right. May you please explain it a bit more?

asottile commented 2 years ago

^-right from beginning of the line goes to the wrong place when the line is indented with a tab -- it should go to the same position as if the line were indented with spaces

maltarouti commented 2 years ago

I couldn't reproduce this, it seems just the same for me. I tested it on the given example above and one on a random example

asottile commented 2 years ago

do you have an actual tab character?

maltarouti commented 2 years ago

Yes, I do. Probably I'm doing something wrong!

asottile commented 2 years ago

try these two (press ^Right after opening either of them)

babi +2 - <<< $'\n\thello world\n\n    hello world\n'
babi +4 - <<< $'\n\thello world\n\n    hello world\n'
maltarouti commented 2 years ago

First: 2

Second: 4

asottile commented 2 years ago

yeah see how they are not the same?

maltarouti commented 2 years ago

Oh, I get it now. That was so hard to notice for me!

maltarouti commented 2 years ago

I tried to run Pytest before changing anything just to ensure that everything is working fine before I start but I get the following for some reason: E FileNotFoundError: [Errno 2] No such file or directory: 'tmux'

Also, I should not trust test_ctrl_right_jump_by_word after changing right?

asottile commented 2 years ago

going to assume you're new to software development -- usually the response to "No such file or directory: X" should be to figure out why you don't have X

the existing tests should all pass after your change

maltarouti commented 2 years ago

Clearly, the issue is from line 378 or it's because of the wrong value of comparison between tp and the current x. I tried to remove that and it was working fine for me, though I cannot ensure that will be right for all cases since I'm still not able to run the tests because of a problem with Hecate. https://github.com/asottile/babi/blob/c51484c0fceca8e79ace00f9b20243d756afc604/babi/file.py#L376-L381

Marsma13 commented 2 years ago

As Murtada-Altarouti stop working on this issue. I want to ask what is expected behaviour on this? Couse now tab works the same as single space. And the code works becouse we normally use 4 spaces. What should happen when we have \t\t in our code editor?