Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change of behavour of Right command for 1 space at the start of line #242

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion babi/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,15 @@ def ctrl_right(self, dim: Dim) -> None:
else:
self.buf.right(dim)
tp = line[self.buf.x].isalnum()
while self.buf.x < len(line) and tp == line[self.buf.x].isalnum():
while (
self.buf.x < len(line) and
tp == line[self.buf.x].isalnum() and
not (
self.buf.x == 1 and
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is sufficient -- the same problem would happen halfway through an indent if I understand correctly

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think of case when we have \t\tSome words
And when we are on the 2nd tab we will jump to the end of "Some" word. I done it the same as spaces works, if you are on the space before the word you jump at the end of the word, and that is included in test. If you think behaviour should be different i can think of solution. I do not want to differentitate behaviour for space and space like chcaracters ( tab ) included.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or cursor is at position 3 of a 4 space tab

Copy link
Author

@Marsma13 Marsma13 May 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok so you have in maind case when we have characters in intedn from tab? I still do not know what is expected behaviour from this.
You want to treat \t as 4 spaces and it should work the same? so when we have situatuation like this:

sad     indent
   ^    ^    ^
   |    |    |    + when use tab as work separator
   |    |    + when spaces as word separator
   |    + cursor postion

Do you want to override default behavior and when we have words separated by tab we should go to the start od the word?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I think I understand what you are thinking off. I will try to solve that :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that doesn't look like the right direction at all. I suspect what actually should be done is to find the "break" points in the line and navigate to the next one

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Understand but without knowing the width of the tab, i do not think that I will be able to determine if i should go to the begginig of the word or the postion after the word. Let look at examples:

tabsize:4
HI! Anthony
   ^       ^
   |       |  should be here after ^right
   |  cursor position
tabsize:5
HI!  Anthony
   ^ ^
   | |  should be here after ^right
   |  cursor position

I could use buf.x to differentiate that but problem is when we have something like that:

tabsize:4
HI  Be  thony
      ^ ^
      | |  should be here after ^right
      |  cursor position
tabsize:5
HI   Be   thony
       ^  ^
       |  |  should be here after ^right
       |  cursor position

In that case we have just bad value in buf.x which is not corresponding to the screen position.

Question is if we have left with one "space" when using tab should we jump to the nearest word (easy fix) or to the space after the word ?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the width of the tab doesn't matter

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. So you want it working like in nano? So when tab is used it is alweys go to the start of the next word?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I make it the most trivial now how it can be. I do not really get the better idea of how to find break points without knowing the tab lenght. Current solution resolve most cases except one when we have something like that:
asd\tasd -> it will go to the a of the asd instead of the end. But i do not really know how i should find if we should go after the word or not without knowing the tab size and counting characters in the string.

line[self.buf.x - 1].isspace() and
not line[self.buf.x].isspace()
)
):
self.buf.right(dim)

@action
Expand Down
40 changes: 40 additions & 0 deletions tests/features/movement_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,3 +545,43 @@ def another_test():

h.press('M-Down')
h.await_cursor_position(x=0, y=12)


def test_ctrl_right_jump_by_word_with_tabs(run, tmpdir):
src = '''\
\tHello\tWorld
\t\tGoodday
hi\t\tAnthonk

\t\t\tthis(is_some_code) # comment
'''
f = tmpdir.join('f')
f.write(src)
with run(str(f)) as h, and_exit(h):
h.press('^Right')
h.await_cursor_position(x=4, y=1)
h.press('^Right')
h.await_cursor_position(x=9, y=1)
h.press('Left')
h.await_cursor_position(x=8, y=1)
h.press('^Right')
h.await_cursor_position(x=12, y=1)
h.press('^Right')
h.await_cursor_position(x=17, y=1)
h.press('^Right')
h.await_cursor_position(x=8, y=2)
h.press('^Right')
h.await_cursor_position(x=15, y=2)
h.press('^Right')
h.await_cursor_position(x=0, y=3)
h.press('^Right')
h.await_cursor_position(x=2, y=3)
h.press('^Right')
h.await_cursor_position(x=8, y=3)
h.press('^Right')
h.await_cursor_position(x=15, y=3)
h.press('^Right')
h.await_cursor_position(x=12, y=5)
h.press('Down')
h.press('^Right')
h.await_cursor_position(x=0, y=6)