750071abe1
Terminals are marked as typing surfaces. While one has focus, the chat's "/ jumps to the composer", the Search tab's Escape, Ctrl+/, Ctrl+1…9 and Ctrl+Shift+arrow pane moves leave the key to the terminal, like they do for text fields.
36 lines
1.4 KiB
Dart
36 lines
1.4 KiB
Dart
import 'package:flutter/widgets.dart';
|
|
import '../../../ui/input/keyboard_owner.dart';
|
|
|
|
/// Flutter shares a single web editing element across fields. DOM identity
|
|
/// alone cannot tell a chat composer from search, rename or another editor.
|
|
abstract final class ChatComposerPasteFocus {
|
|
static final Set<FocusNode> _composers = {};
|
|
|
|
static final Set<FocusNode> _inputs = {};
|
|
|
|
static void register(FocusNode focus) => _composers.add(focus);
|
|
static void unregister(FocusNode focus) => _composers.remove(focus);
|
|
|
|
/// An input that is not an [EditableText] (a shell command's terminal)
|
|
/// registers its focus here: a paste while it has focus is its own.
|
|
static void registerInput(FocusNode focus) => _inputs.add(focus);
|
|
static void unregisterInput(FocusNode focus) => _inputs.remove(focus);
|
|
|
|
static bool get anotherEditableHasFocus {
|
|
final primary = FocusManager.instance.primaryFocus;
|
|
if (primary == null || _composers.any((focus) => focus.hasFocus)) {
|
|
return false;
|
|
}
|
|
if (_inputs.any((focus) => focus.hasFocus)) return true;
|
|
if (primaryFocusIsTypingSurface()) return true;
|
|
final context = primary.context;
|
|
if (context == null) return false;
|
|
var editable = context.widget is EditableText;
|
|
context.visitAncestorElements((element) {
|
|
if (element.widget is EditableText) editable = true;
|
|
return !editable;
|
|
});
|
|
return editable;
|
|
}
|
|
}
|