Refactor large Kotlin source files
- Split core game models from sandbox engine, native level setup, and repo state saving. - Move app overlays and completion helpers out of GitHugApp. - Extract the terminal special key bar into its own component.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package solutions.tretter.githugandroid
|
||||
|
||||
internal fun fileCompletionCandidates(repo: RepoState): List<String> {
|
||||
val prefix = repo.currentDirPrefix()
|
||||
return repo.files
|
||||
.filterNot { it.deleted }
|
||||
.map { it.name }
|
||||
.filter { it.startsWith(prefix) }
|
||||
.map { it.removePrefix(prefix) }
|
||||
.filter { it.isNotBlank() }
|
||||
}
|
||||
|
||||
internal fun directoryCompletionCandidates(repo: RepoState): List<String> {
|
||||
val prefix = repo.currentDirPrefix()
|
||||
return repo.files
|
||||
.filterNot { it.deleted }
|
||||
.map { it.name }
|
||||
.filter { it.startsWith(prefix) }
|
||||
.map { it.removePrefix(prefix) }
|
||||
.flatMap { file ->
|
||||
val parts = file.split('/').dropLast(1)
|
||||
parts.indices.map { index -> parts.take(index + 1).joinToString("/") + "/" }
|
||||
}
|
||||
.distinct()
|
||||
}
|
||||
|
||||
private fun RepoState.currentDirPrefix(): String {
|
||||
return if (currentDir == ".") "" else currentDir.trimEnd('/') + "/"
|
||||
}
|
||||
Reference in New Issue
Block a user