Skip to content

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

Merged
Dongbo Wang (daxian-dbw) merged 4 commits into
PowerShell:masterfrom
msftrncs:InsertLineAboveFix
Oct 29, 2019
Merged

Dongbo Wang (daxian-dbw) merged 4 commits into
PowerShell:masterfrom
msftrncs:InsertLineAboveFix

Conversation

@msftrncs

@msftrncs Carl Morris (msftrncs) commented Oct 20, 2019 •

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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().

@lzybkr Jason Shirk (lzybkr) left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Collaborator Author

Closing and reopening to retrigger the CI.

@lzybkr

Copy link
Copy Markdown
Contributor

Carl Morris (@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
Copy Markdown
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 Carl Morris (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
Copy Markdown
Collaborator Author

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

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