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

Cursor Fix #98

Closed
wants to merge 26 commits into from
Closed

Cursor Fix #98

wants to merge 26 commits into from

Conversation

kirawi
Copy link
Member

@kirawi kirawi commented Jun 3, 2021

Fixes #58, #61, #73, & #74

@kirawi
Copy link
Member Author

kirawi commented Jun 3, 2021

I'm going to look at some easy issues to fix, marking as a draft for now.

@kirawi kirawi marked this pull request as draft June 3, 2021 17:36
@kirawi kirawi marked this pull request as ready for review June 3, 2021 19:34
@kirawi kirawi changed the title Add missing saturating sub Fixing a few issues Jun 3, 2021
@kirawi
Copy link
Member Author

kirawi commented Jun 3, 2021

Found a bug in my code, fixing.

helix-core/src/transaction.rs Show resolved Hide resolved
helix-core/src/movement.rs Outdated Show resolved Hide resolved
@archseer
Copy link
Member

archseer commented Jun 4, 2021

Looks like you also need to run cargo fmt :)

@archseer
Copy link
Member

archseer commented Jun 4, 2021

I think one of the bounds also needs to be adjusted, if you open a larger file there will be a line number in the status line.

@kirawi
Copy link
Member Author

kirawi commented Jun 4, 2021

I found various regressions to the shortcuts as a result of the cursor change, I'll be working on it tomorrow.

@kirawi
Copy link
Member Author

kirawi commented Jun 4, 2021

One issue I'm having is r + r on an empty buffer, I'm going to take a look at that tomorrow. Sadly, I'm a monkey with terminal editors so I'm smashing random keys and hoping it doesn't panic... It's likely related to the change to the cursor allowing it to go past the final character in a line.

@archseer
Copy link
Member

archseer commented Jun 4, 2021

allowing it to go past the final character in a line.

So this does work already on master, you should be able to go past the last char (technically onto the invisible \n) but you shouldn't be able to go past the final line.

@kirawi
Copy link
Member Author

kirawi commented Jun 4, 2021

allowing it to go past the final character in a line.

So this does work already on master, you should be able to go past the last char (technically onto the invisible \n) but you shouldn't be able to go past the final line.

That's interesting... I'll undo those changes then.

@archseer
Copy link
Member

archseer commented Jun 4, 2021

The rest is quite an improvement though :) The off by one line number rendering fix explains why a single line without a trailing \n would have no line number

@kirawi
Copy link
Member Author

kirawi commented Jun 4, 2021

Ah, I see. Okay, so what's happening is that on the current master branch, it considers \n a separate character which allows it to seem like that, while mine doesn't do that. However, I am still running into that annoying bug even after removing all the cursor changes, so I'll look at it tomorrow. I hope you don't mind if I put in my previous changes to the cursor, as it would properly allow it to go beyond the final character of the line? Currently, if you remove that \n with the d or r hotkeys for example, you can't do that.

@kirawi
Copy link
Member Author

kirawi commented Jun 4, 2021

Amusingly, the fix for the bug was the same as the fix for _delete(), somehow I missed that. Basically, it needs this to be correct:

let transaction =
                Transaction::change_by_selection(doc.text(), doc.selection(view.id), |range| {
                    let max_to = doc.text().len_chars(); // This
                    let to = std::cmp::min(max_to, range.to() + 1); // And this
                    (range.from(), to, Some(text.clone()))
                });

@kirawi kirawi marked this pull request as ready for review June 4, 2021 20:23
@kirawi
Copy link
Member Author

kirawi commented Jun 4, 2021

I think it works, but I'm not sure if there are remaining bugs.

edit:

  • It doesn't correctly copy + paste
  • It can't deal with crlf

These are bugs that are also in the master branch, but it might be worth getting this pushed to fix the current panics and then let someone else fix that in a subsequent PR.

@kirawi kirawi marked this pull request as draft June 4, 2021 20:49
@kirawi kirawi marked this pull request as ready for review June 4, 2021 20:52

use Operation::*;
assert_eq!(
changes.changes,
Copy link
Member

Choose a reason for hiding this comment

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

You also want to test that len_after is correct

@archseer
Copy link
Member

archseer commented Jun 4, 2021

It's looking good, I'll do some testing today and then merge.

@archseer
Copy link
Member

archseer commented Jun 5, 2021

A few issues:

  • iasd<Esc>b panics
  • w is unable to go past end of line anymore (positioning either on the last char or past last char)
  • pressing X repeatedly crashes (even in an empty doc)
  • A doesn't append at end of line, but one character before
  • iasd asd<Esc>S (so "asd asd", split on space) no longer selects the last character on the line

Are you testing this on windows? I think that might explain some of the differences. I don't think we can rely on text.line_to_char(line + 1) - 1 to get the end of line anymore since it depends on the line ending (CR = 1 vs CRLF = 2)

@kirawi
Copy link
Member Author

kirawi commented Jun 5, 2021

Agreed. Additionally, I'm wondering if there's a better solution to the cursor thing considering how many bugs are popping up as a result of it, and I can only imagine the nightmare that would happen if someone else had to change something and everything breaks. Since everything seems to be because of 1 off & bounding errors, I'll be looking into a better way to do that. Maybe a field or inline function that determines the "real" current character.

@kirawi kirawi marked this pull request as draft June 5, 2021 01:41
@archseer
Copy link
Member

archseer commented Jun 5, 2021

I agree, there should be some sort of safe wrapper to clamp the range. We already achieve that on one end with saturating_sub, but we need something for the upper bound.

Might be worth splitting some of the fixes out and getting them merged early, specifically the division by zero bug and possibly the ..= fix for line numbers, and the len_after fix.

Also, feel free to join us at https://matrix.to/#/#helix-community:matrix.org to discuss (make sure to join #helix-editor:matrix.org if you're on a client that doesn't support Matrix Spaces yet)

@kirawi
Copy link
Member Author

kirawi commented Jun 7, 2021

Unnecessary after 14830e7, though be aware that let height = self.area.height.saturating_sub(2); // - 2 for statusline was not undone in that commit which is leading to the missing line at the bottom of the viewport.

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

Successfully merging this pull request may close these issues.

Panic when inserting non-ascii character.
3 participants