diff --git a/PSReadLine/History.cs b/PSReadLine/History.cs index c0f8cb8c..693c15d7 100644 --- a/PSReadLine/History.cs +++ b/PSReadLine/History.cs @@ -95,6 +95,8 @@ public class HistoryItem private HistoryItem _previousHistoryItem; private Dictionary _hashedHistory; private int _currentHistoryIndex; + // A helper field for getting next history, specifically for AcceptAndGetNext. + // It's considered unset when its value is 0 private int _getNextHistoryIndex; private int _searchHistoryCommandCount; private int _recallHistoryCommandCount; @@ -1140,6 +1142,9 @@ private void UpdateHistoryDuringInteractiveSearch(string toMatch, int direction, _emphasisStart = startIndex; _emphasisLength = toMatch.Length; _currentHistoryIndex = searchFromPoint; + // setting next index so that when AcceptAndGetNext is triggered it can properly load next history + _getNextHistoryIndex = _currentHistoryIndex < _history.Count - 1 ? _currentHistoryIndex + 1 : 0; + var moveCursor = Options.HistorySearchCursorMovesToEnd ? HistoryMoveCursor.ToEnd : HistoryMoveCursor.DontMove;