mirror of
https://github.com/jlengrand/compose-multiplatform.git
synced 2026-03-10 08:11:20 +00:00
Multiplatform template in IDEA / Android Studio. Refactoring
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* This file is example (we can open it in android application)
|
||||
* This file is an example (we can open it in android application)
|
||||
*/
|
||||
|
||||
package org.jetbrains.codeviewer.ui.editor
|
||||
@@ -73,7 +73,7 @@ fun EditorView(model: Editor, settings: Settings) = key(model) {
|
||||
|
||||
@Composable
|
||||
private fun Lines(lines: Editor.Lines, settings: Settings) = with(DensityAmbient.current) {
|
||||
val maxNum = remember(lines.lineNumberDigitCount) {
|
||||
val maxNumber = remember(lines.lineNumberDigitCount) {
|
||||
(1..lines.lineNumberDigitCount).joinToString(separator = "") { "9" }
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ private fun Lines(lines: Editor.Lines, settings: Settings) = with(DensityAmbient
|
||||
val line: Editor.Line? by loadable { lines.get(index) }
|
||||
Box(Modifier.height(lineHeight)) {
|
||||
if (line != null) {
|
||||
Line(Modifier.align(Alignment.CenterStart), maxNum, line!!, settings)
|
||||
Line(Modifier.align(Alignment.CenterStart), maxNumber, line!!, settings)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -108,11 +108,11 @@ private fun Lines(lines: Editor.Lines, settings: Settings) = with(DensityAmbient
|
||||
// دعم اللغة العربية
|
||||
// 中文支持
|
||||
@Composable
|
||||
private fun Line(modifier: Modifier, maxNum: String, line: Editor.Line, settings: Settings) {
|
||||
private fun Line(modifier: Modifier, maxNumber: String, line: Editor.Line, settings: Settings) {
|
||||
Row(modifier = modifier) {
|
||||
WithoutSelection {
|
||||
Box {
|
||||
LineNumber(maxNum, Modifier.drawOpacity(0f), settings)
|
||||
LineNumber(maxNumber, Modifier.drawOpacity(0f), settings)
|
||||
LineNumber(line.number.toString(), Modifier.align(Alignment.CenterEnd), settings)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import org.jetbrains.codeviewer.ui.MainView
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
@@ -25,6 +25,7 @@ fun java.io.File.toProjectFile(): File = object : File {
|
||||
get() = isDirectory && listFiles()?.size ?: 0 > 0
|
||||
|
||||
override suspend fun readLines(backgroundScope: CoroutineScope): TextLines {
|
||||
// linePositions can be very big, so we are using IntList instead of List<Long>
|
||||
val linePositions = IntList()
|
||||
var size by mutableStateOf(0)
|
||||
|
||||
@@ -52,6 +53,7 @@ fun java.io.File.toProjectFile(): File = object : File {
|
||||
try {
|
||||
RandomAccessFile(this@toProjectFile, "rws").use {
|
||||
it.seek(position.toLong())
|
||||
// NOTE: it isn't efficient, but simple
|
||||
String(
|
||||
it.readLine()
|
||||
.toCharArray()
|
||||
@@ -77,7 +79,6 @@ private suspend fun java.io.File.readLinePositions(list: IntList) = withContext(
|
||||
}
|
||||
|
||||
val averageLineLength = 200
|
||||
// linePositions can be very big, so we are using IntArray instead of List<Long>
|
||||
list.clear(length().toInt() / averageLineLength)
|
||||
|
||||
var isBeginOfLine = true
|
||||
@@ -107,6 +108,9 @@ private suspend fun java.io.File.readLinePositions(list: IntList) = withContext(
|
||||
list.compact()
|
||||
}
|
||||
|
||||
/**
|
||||
* Compact version of List<Int> (without unboxing Int and using IntArray under the hood)
|
||||
*/
|
||||
private class IntList(initialCapacity: Int = 16) {
|
||||
@Volatile
|
||||
private var array = IntArray(initialCapacity)
|
||||
|
||||
Reference in New Issue
Block a user