@@ -15,11 +15,13 @@ import androidx.compose.ui.graphics.Color
1515import androidx.compose.ui.graphics.TransformOrigin
1616import androidx.compose.ui.graphics.graphicsLayer
1717import androidx.compose.ui.layout.onGloballyPositioned
18+ import androidx.compose.ui.layout.onSizeChanged
1819import androidx.compose.ui.platform.LocalDensity
1920import androidx.compose.ui.text.SpanStyle
2021import androidx.compose.ui.text.TextStyle
2122import androidx.compose.ui.text.input.TextFieldValue
2223import androidx.compose.ui.tooling.preview.Preview
24+ import androidx.compose.ui.unit.IntSize
2325import androidx.compose.ui.unit.dp
2426import androidx.compose.ui.zIndex
2527import de.markusressel.kodehighlighter.core.LanguageRuleBook
@@ -92,13 +94,20 @@ fun KodeEditor(
9294 }
9395
9496 // Text Editor
97+ var totalSize by remember { mutableStateOf(IntSize .Zero ) }
98+ var maxXOffset by remember(totalSize) { mutableFloatStateOf(Float .MAX_VALUE ) }
99+ var maxYOffset by remember(totalSize) { mutableFloatStateOf(Float .MAX_VALUE ) }
100+
95101 ZoomLayout (
96102 modifier = Modifier
97103 .zIndex(0f )
98104 .padding(
99105 start = computedPadding,
100106 )
101- .matchParentSize(),
107+ .matchParentSize()
108+ .onSizeChanged { size ->
109+ totalSize = size
110+ },
102111 offset = offset,
103112 zoom = zoom,
104113 onOffsetChanged = {
@@ -109,8 +118,8 @@ fun KodeEditor(
109118
110119 val newOffset = offset + (it / zoom)
111120 offset = newOffset.copy(
112- x = newOffset.x.coerceAtLeast (0f ),
113- y = newOffset.y.coerceAtLeast (0f )
121+ x = newOffset.x.coerceIn (0f , maxXOffset ),
122+ y = newOffset.y.coerceIn (0f , maxYOffset )
114123 )
115124 },
116125 onZoomChanged = {
@@ -129,7 +138,11 @@ fun KodeEditor(
129138 .padding(
130139 start = 4 .dp,
131140 end = 4 .dp
132- ),
141+ )
142+ .onSizeChanged { unboundedSize ->
143+ maxXOffset = (unboundedSize.width - totalSize.width).toFloat()
144+ maxYOffset = (unboundedSize.height - totalSize.height).toFloat()
145+ },
133146 value = text,
134147 languageRuleBook = languageRuleBook,
135148 colorScheme = colorScheme,
0 commit comments