@@ -138,8 +138,8 @@ internal class InputTarget constructor(
138
138
private var mayDragSelectByLine: Boolean by mutableStateOf(false )
139
139
private var mayDragSelectByLineNumber: Boolean by mutableStateOf(false )
140
140
private var selectionDragStart: Selection ? by mutableStateOf(null )
141
- private var textAreaRect : Rect by mutableStateOf(Rect .Zero )
142
- private val lineNumberBorder: Float get() = textAreaRect .left - horPadding.value
141
+ private var textAreaBounds : Rect by mutableStateOf(Rect .Zero )
142
+ private val lineNumberBorder: Float get() = textAreaBounds .left - horPadding.value
143
143
private val lineCount: Int get() = content.size
144
144
private val end: Cursor get() = Cursor (content.size - 1 , content.last().length)
145
145
private val coroutineScope = CoroutineScope (EmptyCoroutineContext )
@@ -153,18 +153,19 @@ internal class InputTarget constructor(
153
153
textWidth = 0 .dp
154
154
}
155
155
156
- internal fun updateTextArea (rawRectangle : Rect ) {
157
- textAreaRect = Rect (
156
+ internal fun updateBounds (rawRectangle : Rect ) {
157
+ textAreaBounds = Rect (
158
158
left = toDP(rawRectangle.left, density).value + horPadding.value,
159
159
top = toDP(rawRectangle.top, density).value,
160
160
right = toDP(rawRectangle.right, density).value - horPadding.value,
161
161
bottom = toDP(rawRectangle.bottom, density).value
162
162
)
163
+ println (" InputTarget.textAreaRect: $textAreaBounds " )
163
164
}
164
165
165
166
private fun createCursor (x : Int , y : Int ): Cursor {
166
- val relX = x - textAreaRect .left + toDP(horScroller.value, density).value
167
- val relY = y - textAreaRect .top + verScroller.offset.value
167
+ val relX = x - textAreaBounds .left + toDP(horScroller.value, density).value
168
+ val relY = y - textAreaBounds .top + verScroller.offset.value
168
169
val row = floor(relY / lineHeight.value).toInt().coerceIn(0 , lineCount - 1 )
169
170
val offsetInLine = Offset (relX * density, (relY - (row * lineHeight.value)) * density)
170
171
val col = rendering.get(row)?.getOffsetForPosition(offsetInLine) ? : 0
@@ -217,7 +218,7 @@ internal class InputTarget constructor(
217
218
}
218
219
219
220
internal fun mayUpdateCursor (x : Int , y : Int , isSelecting : Boolean ) {
220
- if (x <= textAreaRect .right) {
221
+ if (x <= textAreaBounds .right) {
221
222
updateCursor(createCursor(x, y), isSelecting, false )
222
223
if (x > lineNumberBorder) mayDragSelectByChar = true
223
224
else mayDragSelectByLineNumber = true
@@ -244,10 +245,10 @@ internal class InputTarget constructor(
244
245
245
246
private fun mayScrollToCursor () {
246
247
fun mayScrollToCoordinate (x : Int , y : Int , padding : Int = 0) {
247
- val left = textAreaRect .left.toInt() + padding
248
- val right = textAreaRect .right.toInt() - padding
249
- val top = textAreaRect .top.toInt() + padding
250
- val bottom = textAreaRect .bottom.toInt() - padding
248
+ val left = textAreaBounds .left.toInt() + padding
249
+ val right = textAreaBounds .right.toInt() - padding
250
+ val top = textAreaBounds .top.toInt() + padding
251
+ val bottom = textAreaBounds .bottom.toInt() - padding
251
252
if (x < left) coroutineScope.launch {
252
253
horScroller.scrollTo(horScroller.value + ((x - left) * density).toInt())
253
254
} else if (x > right) coroutineScope.launch {
@@ -260,8 +261,8 @@ internal class InputTarget constructor(
260
261
val cursorRect = rendering.get(cursor.row)?.let {
261
262
it.getCursorRect(cursor.col.coerceAtMost(it.getLineEnd(0 )))
262
263
} ? : Rect (0f , 0f , 0f , 0f )
263
- val x = textAreaRect .left + toDP(cursorRect.left - horScroller.value, density).value
264
- val y = textAreaRect .top + (lineHeight.value * (cursor.row + 0.5f )) - verScroller.offset.value
264
+ val x = textAreaBounds .left + toDP(cursorRect.left - horScroller.value, density).value
265
+ val y = textAreaBounds .top + (lineHeight.value * (cursor.row + 0.5f )) - verScroller.offset.value
265
266
mayScrollToCoordinate(x.toInt(), y.toInt(), lineHeight.value.toInt() * 2 )
266
267
}
267
268
@@ -388,14 +389,14 @@ internal class InputTarget constructor(
388
389
}
389
390
390
391
internal fun moveCursorUpByPage (isSelecting : Boolean = false) {
391
- val fullyVisibleLines = floor(textAreaRect .height / lineHeight.value).toInt()
392
+ val fullyVisibleLines = floor(textAreaBounds .height / lineHeight.value).toInt()
392
393
val newRow = (cursor.row - fullyVisibleLines).coerceAtLeast(0 )
393
394
val newCol = cursor.col.coerceAtMost(content[newRow].length)
394
395
updateCursor(Cursor (newRow, newCol), isSelecting)
395
396
}
396
397
397
398
internal fun moveCursorDownByPage (isSelecting : Boolean = false) {
398
- val fullyVisibleLines = floor(textAreaRect .height / lineHeight.value).toInt()
399
+ val fullyVisibleLines = floor(textAreaBounds .height / lineHeight.value).toInt()
399
400
val newRow = (cursor.row + fullyVisibleLines).coerceAtMost(content.size - 1 )
400
401
val newCol = cursor.col.coerceAtMost(content[newRow].length)
401
402
updateCursor(Cursor (newRow, newCol), isSelecting)
0 commit comments