import 'package:flutter/widgets.dart'; /// Marks a widget that takes raw typing without being an [EditableText], such /// as a terminal emulator. While focus is inside it, app-wide shortcuts that /// would otherwise act on plain keys (`/` to the composer, Escape, Ctrl+/, /// Ctrl+1…9, Ctrl+Shift+arrows) leave the keys to it. class TypingSurface extends StatelessWidget { const TypingSurface({super.key, required this.child}); final Widget child; @override Widget build(BuildContext context) => child; } /// Whether keyboard focus is inside a [TypingSurface]. bool primaryFocusIsTypingSurface() { final context = FocusManager.instance.primaryFocus?.context; if (context == null) return false; if (context.widget is TypingSurface) return true; return context.findAncestorWidgetOfExactType() != null; } /// Whether keyboard focus is in something that takes typing: an editable /// text field or a [TypingSurface]. bool primaryFocusTakesTyping() { final context = FocusManager.instance.primaryFocus?.context; if (context == null) return false; if (primaryFocusIsTypingSurface()) return true; if (context.widget case final EditableText field) return !field.readOnly; final editable = context.findAncestorWidgetOfExactType(); return editable != null && !editable.readOnly; }