feat(phase-1/m5.1): desktop Esc back stack + Ctrl+N/Ctrl+comma shortcuts

JVM PlatformBackHandler made real (PlatformBackStack + LocalPlatformBackStack);
window drains it on Esc via Window(onPreviewKeyEvent) — the editor rides the
shared seam unchanged (draft flush + discard prompt). Shell registers
drawer/settings Esc; preview-phase shortcuts. New --keys-smoke leg drives the
exact dispatch headlessly. Keypress capture pending-manual (KWin/Wayland drops
xdotool XTEST events to the XWayland window).

Verify: ./gradlew assembleDebug :composeApp:compileKotlinJvm :desktopApp:build
(SUCCESSFUL); :desktopApp:run --args="--data-dir /tmp/incido-keys --keys-smoke
--exit-after 12" (KEYS ALL-OK); --self-test/--settings-smoke/--editor-smoke
green; :core:data-jvm:smoke M1a PASS.
This commit is contained in:
Incido Developer committed 2026-10-06 22:37:37 +13:00
1 parent faab0cde98
commit 639f39d187
5 files changed
+300 -56

No files matched your search

@@ -7,9 +7,9 @@ import androidx.compose.runtime.Composable
* wrapper around `activity-compose` inside the editor file).
*
* Android actual = `androidx.activity.compose.BackHandler`, verbatim
* behaviour. The JVM actual is a no-op: a desktop window has no system
* back gesture, the editor's close button owns that path, and physical
* Esc/back-key routing is keyboard-shortcut polish on the M5 list.
* behaviour. The JVM actual (M5.1) registers into the desktop window's
* [PlatformBackStack], which the window drains on Esc — so the editor's
* discard-prompt chain works on both platforms through this one seam.
*/
@Composable
expect fun PlatformBackHandler(enabled: Boolean, onBack: () -> Unit)
@@ -1,8 +1,66 @@
package org.incido.compose.util
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.runtime.remember
/** M4.4c JVM actual — no system back gesture on a desktop window; the
* editor's close button owns that path (Esc handling is M5 polish). */
/**
* M5.1 — the M4.4c no-op made real: a desktop back stack.
*
* A desktop window has no system back gesture, so the desktop window
* translates Esc (`Window(onPreviewKeyEvent)`) into [dispatchBack] on the
* [PlatformBackStack] provided through [LocalPlatformBackStack]. Every live
* `PlatformBackHandler` becomes an entry here, so the editor's existing
* tryClose/discard-prompt chain behaves exactly like Android's BackHandler
* stack: the topmost enabled entry wins.
*
* Entries keep their stack position across recompositions: the registration
* object is remembered and its callback slot refreshed per composition.
* Re-registering on every `onBack` lambda change would let a lower handler's
* recomposition jump above an editor or dialog stacked on top of it.
*/
class PlatformBackStack {
internal class Entry(var enabled: Boolean = false, var onBack: () -> Unit = {})
private val entries = ArrayDeque<Entry>()
internal fun push(entry: Entry) {
entries.addLast(entry)
}
internal fun remove(entry: Entry) {
entries.remove(entry)
}
/**
* Runs the topmost enabled handler. Returns true when consumed — the
* window uses that to decide whether Esc falls through to content.
*/
fun dispatchBack(): Boolean {
val top = entries.lastOrNull { it.enabled } ?: return false
top.onBack()
return true
}
}
/** Provided by the desktop host window (see `:desktopApp` Main.kt, M5.1). */
val LocalPlatformBackStack = compositionLocalOf<PlatformBackStack?> { null }
/**
* M4.4c/M5.1 JVM actual — registers into [LocalPlatformBackStack]. No-op
* when the host provides no stack (headless tests, embeds).
*/
@Composable
actual fun PlatformBackHandler(enabled: Boolean, onBack: () -> Unit) = Unit
actual fun PlatformBackHandler(enabled: Boolean, onBack: () -> Unit) {
val stack = LocalPlatformBackStack.current
val entry = remember { PlatformBackStack.Entry() }
entry.enabled = enabled
entry.onBack = onBack
if (stack != null) {
DisposableEffect(stack) {
stack.push(entry)
onDispose { stack.remove(entry) }
}
}
}