mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-04 19:10:47 -05:00
app: redraw terminal after resizing
The terminal emulator lives in the ViewModel and survives Activity recreation, but a recreated TerminalScreen draws its first frame before LaunchedEffect resizes the emulator to the new viewport. Nothing invalidated the drawing after the resize, so after rotating, the screen kept showing rows laid out for the old geometry instead of the end of the output, and the scrollbars used stale values. Refresh the snapshot state and redraw after every resize, through the same path used for new output, and keep a scrolled-up position within the transcript. Assisted-by: Claude Opus 5.5
This commit is contained in:
@@ -57,17 +57,17 @@ fun TerminalScreen(
|
||||
var transcriptRows by remember { mutableIntStateOf(0) }
|
||||
var maxUsedColumn by remember { mutableIntStateOf(0) }
|
||||
|
||||
// Re-read emulator state after new output or a resize, and redraw
|
||||
fun refresh() {
|
||||
transcriptRows = emulator.screen.activeTranscriptRows
|
||||
maxUsedColumn = emulator.maxUsedColumn
|
||||
topRow = if (scrolledToBottom) 0 else topRow.coerceAtLeast(-transcriptRows)
|
||||
drawTrigger++
|
||||
}
|
||||
|
||||
DisposableEffect(emulator) {
|
||||
fun syncState() {
|
||||
transcriptRows = emulator.screen.activeTranscriptRows
|
||||
maxUsedColumn = emulator.maxUsedColumn
|
||||
}
|
||||
syncState()
|
||||
emulator.onScreenUpdate = {
|
||||
if (scrolledToBottom) topRow = 0
|
||||
syncState()
|
||||
drawTrigger++
|
||||
}
|
||||
refresh()
|
||||
emulator.onScreenUpdate = { refresh() }
|
||||
onDispose {
|
||||
emulator.onScreenUpdate = null
|
||||
}
|
||||
@@ -88,6 +88,9 @@ fun TerminalScreen(
|
||||
|
||||
LaunchedEffect(cols, rows) {
|
||||
emulator.resize(cols, rows, renderer.fontWidth.toInt(), renderer.fontLineSpacing)
|
||||
// The emulator outlives this screen (e.g. across rotation), and the first frame was drawn
|
||||
// before this resize, so redraw with the new geometry.
|
||||
refresh()
|
||||
currentOnResized()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user