handle method
Dispatch msg through this surface.
Implementation
KeymapLayerResult handle(Msg msg) {
// Sequence timeouts are surface-scoped.
if (msg is _SequenceTimeoutMsg) {
if (msg.surfaceId != id) return const KeymapLayerPass();
if (_pendingSessionId != msg.sessionId) {
return const KeymapLayerDrop(); // stale
}
_clearPending();
return KeymapLayerClaim(
KeymapSequenceCancelledMsg(surfaceId: id, timedOut: true),
);
}
if (bindings.isNotEmpty && msg is KeyMsg) {
final seq = _handleKey(msg.key);
if (seq != null) return seq;
}
final custom = onMessage;
if (custom != null) {
final result = custom(msg);
if (result is! KeymapLayerPass) return result;
}
final nested = interceptor;
if (nested != null) {
final out = nested.onSend(msg);
if (out == null) return const KeymapLayerDrop();
// Nested interceptor always claims non-null results (Phase 0 contract).
// Use bindings for fallthrough-aware catalogs; nested is opaque.
return KeymapLayerClaim(out);
}
return const KeymapLayerPass();
}