Skip to content

Preserve and clear the saved current line properly #1259

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

Merged
merged 7 commits into from
Jan 2, 2020

Conversation

daxian-dbw
Copy link
Member

@daxian-dbw daxian-dbw commented Dec 20, 2019

Fix #1257

Major changes:

  1. Preserve the saved current line and the history index while in a series of history commands.
    So when switching between different history command, such as from F8/Shift+F8 (HistorySearchBackward and HistorySearchForward) to UpArrow/DownArrow (recall history) or from Ctrl+r/Ctrl+s to UpArrow/DownArrow, the history command can continue to work as expected.
  2. Clear the saved current line when we are out of a series of history commands.
    So the saved line will not leak to another unrelated history search.

@daxian-dbw daxian-dbw requested a review from msftrncs December 20, 2019 21:23
@@ -633,7 +638,7 @@ private void HistorySearch(int direction)
continue;
}

var line = newHistoryIndex == _history.Count ? _savedCurrentLine.CommandLine : _history[newHistoryIndex].CommandLine;
var line = _history[newHistoryIndex].CommandLine;
Copy link
Member Author

@daxian-dbw daxian-dbw Dec 20, 2019

Choose a reason for hiding this comment

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

The newHistoryIndex == _history.Count is removed because that was already checked above:

if (newHistoryIndex < 0 || newHistoryIndex >= _history.Count)
{
    break;
}

@msftrncs
Copy link
Collaborator

I added to #1257 some minor points. While the changes to RevertLine() seem to prevent the exception, its not the only vector to the source of the issue.

I'm wondering if SaveCurrentLine() needs to rely on something other than a line having not already having been saved ... such as _searchHistoryCommandCount == 0, to allow it to overwrite the previously saved line.

@daxian-dbw
Copy link
Member Author

Thanks for the additional details. You are right, it’s not just RevertLine, but a more general issue. Basically the saved line is not properly cleared after any history operation.
I will think a bit more and update the fix.

@daxian-dbw daxian-dbw changed the title Clear the saved current line in RevertLine WIP: Clear the saved current line when we are not in a series of history commands Dec 31, 2019
@daxian-dbw daxian-dbw changed the title WIP: Clear the saved current line when we are not in a series of history commands Clear the saved current line when we are not in a series of history commands Jan 1, 2020
@daxian-dbw daxian-dbw changed the title Clear the saved current line when we are not in a series of history commands Preserve and clear the saved current line properly Jan 1, 2020
@daxian-dbw
Copy link
Member Author

@msftrncs I think the PR is ready for another review :) Happy new year!

Copy link
Collaborator

@msftrncs msftrncs left a comment

Choose a reason for hiding this comment

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

All LGTM.

@daxian-dbw
Copy link
Member Author

Thanks @msftrncs!

@daxian-dbw daxian-dbw merged commit fd13554 into PowerShell:master Jan 2, 2020
@daxian-dbw daxian-dbw deleted the f8 branch January 2, 2020 06:45
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.

ArgumentOutOfRangeException in RevertLine after F8 then Shift-F8 after second search term was used
2 participants