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

Backspacing across lines leaves first character on line showing #7

Closed
clark800 opened this issue Oct 7, 2021 · 14 comments
Closed

Backspacing across lines leaves first character on line showing #7

clark800 opened this issue Oct 7, 2021 · 14 comments

Comments

@clark800
Copy link

clark800 commented Oct 7, 2021

In insert mode, when I type: 'x', enter, 'x', enter, backspace, backspace, backspace, the second x remains until escape is pressed.

@kyx0r
Copy link
Owner

kyx0r commented Oct 7, 2021

Hello Chris, thank you for the report.
This is a recent regression due to invalid assumption of vi_mod == 2 redrawing 1 line,
the comment in vi.c isn't absolute in that regard, I'll see how to also mention that in the comment.
Try last commit now, it should work ok.
Also if you find a behavior such as when the cursor is right at the last
character of the line, going into insert and deleting with backspace will delete the last
character in the line instead of deleting the previous character. This is intended behavior.

@clark800
Copy link
Author

clark800 commented Oct 7, 2021

Thanks for the quick response. I tried it and the character gets deleted now, but the cursor still jumps to the previous line rather than going to the first column.

Regarding the other point you made, why is that the intended behavior? It seems inconsistent and it's easy to backspace over the last character using a to enter insert mode. It also differs from vim behavior.

@kyx0r
Copy link
Owner

kyx0r commented Oct 7, 2021

Hm, I am not sure. Maybe has to do something with the way X key works in normal mode. There was good reason why I implemented it this way. Perhaps now with the current way the source code is laid out there must be a cleaner way to implement this feature without such behaviors. I shall have a look.

@kyx0r
Copy link
Owner

kyx0r commented Oct 7, 2021

Ok, i've pushed a fix for the a command, and also added s command because it seems to work fine with that for the most part. The problem is that we are reusing the X and x keybind functionality to achieve this feature and it's not enough to accomodate for all the cases of cursor being at the end of the line or at the beginning, but in my opinion it's actually small price to pay since it works fine in most general use cases now.

(I tend to (re)force push last few commits if I make a mistake, so make sure to reset last few commits before pull if
you have to)

@clark800
Copy link
Author

clark800 commented Oct 7, 2021

Looks like it's still jumping from column 2 to the previous line rather than backspacing to column 1.

For the second issue, I'm seeing strange behavior. If I type from insert mode: 'a', 'b', 'c', escape, 'a', backspace, it shows "ac" rather than "ab" and the cursor jumps two columns on the backspace. And when using 'i' to enter insert mode backspace doesn't move the cursor the first time.

@kyx0r
Copy link
Owner

kyx0r commented Oct 7, 2021

Yeah that's the issue I was talking about. It would do that on line endings. It is what it is :(

@kyx0r
Copy link
Owner

kyx0r commented Oct 7, 2021

It basically does the same thing a command $X would do or $x. We don't have any means of aserting those cases since command a moves forward to a '\n' character. Builing a specialized solution to solve those edge cases may be too much trouble adding lots of new lines of code which a project like this tries to avoid.

@kyx0r
Copy link
Owner

kyx0r commented Oct 7, 2021

I'll see maybe I add if statement just for those, since when we at the end xoff is bigger than k-1 and we can catch that by reversing the condition for next instruction. Try the last commit, let me know if this helps.

@clark800
Copy link
Author

clark800 commented Oct 7, 2021

Cool, append-backspace works perfectly now.

Remaining issues:

  1. Insert mode: 'x', enter, 'x', enter, backspace, backspace - cursor jumps from line 2 column 2 to line 1 column 2 instead of line 2 column 1.
  2. Insert mode: 'a', 'b', 'c', escape, 'i', backspace - cursor does not move, should delete the 'b' leaving "ac" (like vim).

@kyx0r
Copy link
Owner

kyx0r commented Oct 8, 2021

Actually append backspace still have an edge case, try doing:

inset mode: 'a' 'b' 'c' escape, h (to move left), a (enters insert), backspace

this will delete 'c' instead of 'b'

  1. The issue with colums is interesting but I think it only happens when there is 1 character only in the line, I'll take a look.
  2. Issue with last char and 'i' don't know if I will ever fix

You see the problem may also be that you fix 1 thing but break other keybind. That code has to handle lots of
situations.

@kyx0r
Copy link
Owner

kyx0r commented Nov 19, 2021

Hello Chris, I think commit 87ef32f fixes some of the edge cases including 1.

I tested it somewhat, please report if you find anything else odd.

@kyx0r
Copy link
Owner

kyx0r commented Nov 19, 2021

hm. it only fixes the problem if there is space on line above, which would delete wrong character after join. to fix 1. I still have to see what gives.

@kyx0r
Copy link
Owner

kyx0r commented Nov 19, 2021

Ok I don't know, there may still be some edge cases but at least for now none too bad that I see right now. This thing is a pain in the ass to debug but at least with the last few patches I was able to get rid of a lot of lines of code from that implementation. Seems like the join point does not work correctly with c command in some cases (but its not like it ever worked correctly to begin with)

@clark800
Copy link
Author

Nice, looks like the backspacing across lines issue is fixed.

@kyx0r kyx0r closed this as completed Dec 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants