Measure the explorer, and cap edit mode at what it can carry
Three numbers, taken on the emulator through the app's own render report and written into EXPLORER.md; the fixture tree the sandbox now builds is what they were taken against. The viewer's scan was on the main thread. Decision 8 said off it, and the first version did it in a `remember` inside the composition, which is not that -- 460ms of frozen screen on a 1 MiB file, long enough that the accessibility tree cannot be read, which is exactly what "the app has stopped" looks like from outside. It runs on Dispatchers.Default now, with a spinner where the file will be. Reading a megabyte is otherwise fine: the viewer is a row per line, and it opens and scrolls 28,660 of them. Edit mode needed a cap, and not the one the plan expected. The cost that matters is not the highlighting -- 40ms a keystroke at 128 kB, which is survivable -- it is Compose laying out one enormous text in the field: 2,027ms per frame at 128 kB, with typed characters dropped, and no response at all at 1 MiB. Switching highlighting off would have saved nothing, since every arrangement of a single text field pays it. So EDIT_LIMIT is 32 kB, the largest size actually measured as usable, and above it the pencil is disabled with the reason in words beside it: a disabled control teaches what the thing can do but cannot say why it is off, and a reader who cannot edit a file they can plainly read would otherwise conclude the app is broken. `FileLines.of` is timed like everything else here, so the figure lands in the render report rather than needing a harness to ask for it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9c4d33273b
commit
2c12274285
6 files changed
+147
-24
No files matched your search
@@ -375,6 +375,10 @@ private fun ColumnScope.DocPane(
|
||||
val editScroll = rememberScrollState()
|
||||
val language = remember(name) { fileLanguage(name) }
|
||||
val loaded = (state as? LoadState.Loaded)?.value as? FileContent.Text
|
||||
// Readable but not editable: see [EDIT_LIMIT]. The size is the one the machine reported, so
|
||||
// this is decided before anything is typed rather than discovered by a keyboard that stops
|
||||
// answering.
|
||||
val editable = loaded != null && loaded.size <= EDIT_LIMIT
|
||||
|
||||
suspend fun fetch() {
|
||||
state = LoadState.Loading
|
||||
@@ -450,7 +454,7 @@ private fun ColumnScope.DocPane(
|
||||
{ scope.launch { fetch() } },
|
||||
enabled = state !is LoadState.Loading,
|
||||
)
|
||||
GlyphButton(EDIT_GLYPH, "Edit", { onEditing(true) }, enabled = loaded != null)
|
||||
GlyphButton(EDIT_GLYPH, "Edit", { onEditing(true) }, enabled = editable)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -463,6 +467,20 @@ private fun ColumnScope.DocPane(
|
||||
)
|
||||
}
|
||||
|
||||
// Why the pencil is off. A disabled control teaches what the thing can do, but it cannot say
|
||||
// why it is disabled -- and a reader who cannot edit a file they can plainly read will
|
||||
// otherwise conclude the app is broken. Said once, here, rather than waiting for a tap that a
|
||||
// disabled button never receives.
|
||||
if (loaded != null && !editable) {
|
||||
Text(
|
||||
"Too big to edit here (${humanSize(loaded.size)}; the limit is " +
|
||||
"${humanSize(EDIT_LIMIT)}). A text field this large stops answering the keyboard.",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 4.dp),
|
||||
)
|
||||
}
|
||||
|
||||
Box(Modifier.weight(1f).fillMaxWidth().background(rawSurface).padding(horizontal = 8.dp)) {
|
||||
when (val current = state) {
|
||||
is LoadState.Loading -> CircularProgressIndicator(Modifier.padding(8.dp))
|
||||
@@ -484,11 +502,7 @@ private fun ColumnScope.DocPane(
|
||||
Modifier.verticalScroll(editScroll),
|
||||
)
|
||||
} else {
|
||||
val lines =
|
||||
remember(file.content, language) {
|
||||
FileLines.of(file.content, language)
|
||||
}
|
||||
FileViewer(lines)
|
||||
ScannedFile(file.content, language)
|
||||
}
|
||||
// Said in words, with the measurement that makes it make sense. Neither of
|
||||
// these is an empty file and neither is an error, so neither may look like one.
|
||||
|
||||
Reference in new issue
Block a user