[pycharm] PY-87579 Tweak autoscroll logic

Reliance on `selectableLazyListState`'s `canScrollBackward` sometimes
ceases to trigger snapshot flow updates. Reference solution uses
`firstVisibleItemIndex` instead, which seems to behave more predictably.


Merge-request: IJ-MR-191437
Merged-by: David Lysenko <david.lysenko@jetbrains.com>

GitOrigin-RevId: 69f2b0904dad21acf7b04e312cb7eb8304ee72f3
This commit is contained in:
David Lysenko
2026-02-16 18:26:49 +00:00
committed by intellij-monorepo-bot
parent 40ab77d1f3
commit 3bc73f0be0

View File

@@ -560,13 +560,13 @@ class ProcessOutputControllerService(
private fun ensureProcessTreeScroll() {
coroutineScope.launch(Dispatchers.EDT) {
combine(
snapshotFlow { processTreeUiState.selectableLazyListState.canScrollBackward },
snapshotFlow { processTreeUiState.selectableLazyListState.firstVisibleItemIndex },
shouldScrollToTop,
) { canScrollBackwards, processes -> canScrollBackwards to processes }
) { firstVisibleIndex, processes -> (firstVisibleIndex > 0) to processes }
.collect { (canScrollBackwards, shouldScrollToTopValue) ->
if (canScrollBackwards && shouldScrollToTopValue) {
shouldScrollToTop.value = false
processTreeUiState.selectableLazyListState.lazyListState.scrollToItem(0)
processTreeUiState.selectableLazyListState.scrollToItem(0)
}
}
}