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

Correct cursor jumping from line 2 to line 1 due to line 1 being empty. #1108

Merged
merged 4 commits into from Oct 29, 2019

Conversation

msftrncs
Copy link
Collaborator

@msftrncs msftrncs commented Oct 20, 2019

Correct newline search in GetBeginningOfLinePos() (HOME) and InsertLineAbove() (CTRL-ENTER) (by using GetBeginningOfLinePos()) to not ignore first character in the buffer which might be a new line.

Manifests as cursor jumps to line 1, because line 1 is blank, when triggered with cursor anywhere on line 2.

Fixes #1107.
Fixes #1109.

@msftrncs
Copy link
Collaborator Author

I just noticed, a similar issue when pressing home, for which this very same code occurs in GetBeginningOfLinePos(). I could instead fix the issue there, and alter InsertLineAbove() to utilize GetBeginningOfLinePos().

Copy link
Member

@lzybkr lzybkr left a comment

Choose a reason for hiding this comment

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

It'd be good to add a test.

If you are extra motivated, you could add a property based test using FsCheck. It seems property based testing might be a good way to catch cases like this without writing too many tests.

@msftrncs
Copy link
Collaborator Author

Test added.

Any input on this?

I just noticed, a similar issue when pressing home, for which this very same code occurs in GetBeginningOfLinePos(). I could instead fix the issue there, and alter InsertLineAbove() to utilize GetBeginningOfLinePos().

I have this code change ready, including test for it as well.

@msftrncs
Copy link
Collaborator Author

Closing and reopening to retrigger the CI.

@msftrncs msftrncs closed this Oct 28, 2019
@msftrncs msftrncs reopened this Oct 28, 2019
@lzybkr
Copy link
Member

lzybkr commented Oct 28, 2019

@msftrncs - Good catch finding the duplicated code - your proposed fix sounds perfect.

Reduce code duplication by reusing GetBeginningOfLinePos in InsertLineAbove.
Correct newline search in GetBeginningOfLinePos (HOME) and
InsertLineAbove to not ignore first character in the buffer which
might be a new line.
Manifests as cursor jumps to line 1, because line 1 is blank, when
triggered with cursor anywhere on line 2.

Fixes PowerShell#1107.
Fixes PowerShell#1109.
@msftrncs
Copy link
Collaborator Author

I have updated the commits so that GetBeginningOfLinePos() gets the fix, and InsertLineAbove() uses GetBeginningOfLinePos(), and including tests for both issues fixed by this.

@msftrncs msftrncs changed the title Correct InsertLineAbove from switching cursor line. Correct cursor jumping from line 2 to line 1 due to line 1 being empty. Oct 29, 2019
@msftrncs
Copy link
Collaborator Author

Updated Title and PR to reflect the changes in the commits.

@daxian-dbw daxian-dbw merged commit 175d42e into PowerShell:master Oct 29, 2019
@msftrncs msftrncs deleted the InsertLineAboveFix branch November 1, 2019 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants