Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions src/LogExpert.UI/Controls/LogWindow/LogWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ internal partial class LogWindow : DockContent, ILogPaintContextUI, ILogView, IL
private bool _noSelectionUpdates;

private ReloadMemento _reloadMemento;
private int? _lineCountBeforeAutomaticReload;
private int _reloadOverloadCounter;
private SortedList<int, RowHeightEntry> _rowHeightList = [];
private int _selectedCol; // set by context menu event for column headers only
Expand Down Expand Up @@ -928,6 +929,7 @@ private void OnLogFileReaderFinishedLoading (object sender, EventArgs e)
}

_reloadMemento = null;
_lineCountBeforeAutomaticReload = null;
}

[SupportedOSPlatform("windows")]
Expand Down Expand Up @@ -3091,9 +3093,20 @@ private void EnterLoadFileStatus ()
private void PositionAfterReload (ReloadMemento reloadMemento)
{
var lineCount = _logFileReader.LineCount;
if (_lineCountBeforeAutomaticReload is int previousLineCount)
{
// A tail edit can lose at most one line; a rotation to a short new file should reset the view.
if (lineCount < previousLineCount - 1 || reloadMemento.FirstDisplayedLine >= lineCount)
{
return;
}

FollowTailChanged(false, false);
}

RestorePositionWithoutTimeSync(new GridPosition(
_reloadMemento.CurrentLine < lineCount ? _reloadMemento.CurrentLine : -1,
_reloadMemento.FirstDisplayedLine < lineCount ? _reloadMemento.FirstDisplayedLine : -1));
reloadMemento.CurrentLine < lineCount ? reloadMemento.CurrentLine : -1,
reloadMemento.FirstDisplayedLine < lineCount ? reloadMemento.FirstDisplayedLine : -1));
}

[SupportedOSPlatform("windows")]
Expand Down Expand Up @@ -3222,6 +3235,17 @@ private void ReloadNewFile ()
if (_reloadOverloadCounter <= 1)
{
CancelPendingLineNavigation();
var firstDisplayedLine = RowToLine(dataGridView.FirstDisplayedScrollingRowIndex);
if (!_guiStateArgs.FollowTail && firstDisplayedLine >= 0)
{
_lineCountBeforeAutomaticReload = _visibleRows.Map.LineCount;
_reloadMemento = new ReloadMemento
{
CurrentLine = CurrentLineNum,
FirstDisplayedLine = firstDisplayedLine
};
}

SavePersistenceData(false);
_ = _loadingFinishedEvent.Reset();
_ = _externaLoadingFinishedEvent.Reset();
Expand Down Expand Up @@ -7742,6 +7766,8 @@ public void Reload ()
CancelPendingLineNavigation();
SavePersistenceData(false);

_lineCountBeforeAutomaticReload = null;

_reloadMemento = new ReloadMemento
{
CurrentLine = CurrentLineNum,
Expand Down
Loading