Implement conditional autoscroll in log monitor

Improves the user experience in the monitor tab by making the log output autoscroll conditional.

Autoscrolling is now disabled when the user selects a log entry other than the last one, allowing them to inspect previous output without interruption. Selecting the last item in the list re-enables autoscrolling.
This commit is contained in:
rbalsleyMSFT
2025-07-14 17:56:51 -07:00
parent 315f0f3858
commit ca84f4dfea
2 changed files with 40 additions and 2 deletions
@@ -778,5 +778,30 @@ function Register-EventHandlers {
$keyEventArgs.Handled = $true
}
})
$State.Controls.lstLogOutput.Add_SelectionChanged({
param($eventSource, $selectionChangedEventArgs)
$listBox = $eventSource
$window = [System.Windows.Window]::GetWindow($listBox)
if ($null -eq $window) { return }
$localState = $window.Tag
# If nothing is selected or the list is empty, do nothing.
if ($listBox.SelectedIndex -eq -1 -or $listBox.Items.Count -eq 0) {
return
}
# Check if the last item is selected
$isLastItemSelected = ($listBox.SelectedIndex -eq ($listBox.Items.Count - 1))
# Update the flag
$localState.Flags.autoScrollLog = $isLastItemSelected
if ($isLastItemSelected) {
WriteLog "Monitor tab autoscroll enabled (last item selected)."
}
else {
WriteLog "Monitor tab autoscroll disabled (user selected item #$($listBox.SelectedIndex))."
}
})
}
Export-ModuleMember -Function *