Skip to content

Commit ac3cf6d

Browse files
committed
Fix loading history
Changes to support undo broke loading history.
1 parent 1db4656 commit ac3cf6d

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

PSReadLine/ReadLine.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ private string InputLoop()
307307
ProcessOneKey(key, _dispatchTable, ignoreIfNoAction: false);
308308
if (_inputAccepted)
309309
{
310-
return MaybeAddToHistory(_buffer.ToString());
310+
return MaybeAddToHistory(_buffer.ToString(), _edits, _undoEditIndex);
311311
}
312312

313313
if (killCommandCount == _killCommandCount)
@@ -361,7 +361,7 @@ void ProcessOneKey(ConsoleKeyInfo key, Dictionary<ConsoleKeyInfo, KeyHandler> di
361361
PostKeyHandler();
362362
}
363363

364-
private string MaybeAddToHistory(string result)
364+
private string MaybeAddToHistory(string result, List<EditItem> edits, int undoEditIndex)
365365
{
366366
bool addToHistory = !string.IsNullOrWhiteSpace(result) && ((_addToHistoryHandler == null) || _addToHistoryHandler(result));
367367
if (addToHistory && _historyNoDuplicates)
@@ -375,9 +375,9 @@ private string MaybeAddToHistory(string result)
375375
{
376376
_history.Enqueue(new HistoryItem
377377
{
378-
_line = _buffer.ToString(),
379-
_edits = _edits,
380-
_undoEditIndex = _undoEditIndex
378+
_line = result,
379+
_edits = edits,
380+
_undoEditIndex = undoEditIndex
381381
});
382382
_currentHistoryIndex = _history.Count;
383383
}
@@ -876,7 +876,8 @@ public static void EmacsBackwardWord(ConsoleKeyInfo? key = null, object arg = nu
876876
/// </summary>
877877
public static void AddToHistory(string command)
878878
{
879-
_singleton.MaybeAddToHistory(command);
879+
command = command.Replace("\r\n", "\n");
880+
_singleton.MaybeAddToHistory(command, new List<EditItem>(), 0);
880881
}
881882

882883
/// <summary>

0 commit comments

Comments
 (0)