fix: focusNode lost focus

This commit is contained in:
Lucas.Xu
2022-08-07 11:24:41 +08:00
parent 2b113aae7f
commit 274b3d1d25
3 changed files with 20 additions and 7 deletions

View File

@ -208,9 +208,16 @@ class _PopupListWidgetState extends State<PopupListWidget> {
} }
if (event.logicalKey == LogicalKeyboardKey.enter) { if (event.logicalKey == LogicalKeyboardKey.enter) {
if (0 <= selectedIndex && selectedIndex < widget.items.length) {
widget.items[selectedIndex].handler(widget.editorState); widget.items[selectedIndex].handler(widget.editorState);
return KeyEventResult.handled; return KeyEventResult.handled;
} }
}
if (event.logicalKey == LogicalKeyboardKey.escape) {
clearPopupListOverlay();
return KeyEventResult.handled;
}
var newSelectedIndex = selectedIndex; var newSelectedIndex = selectedIndex;
if (event.logicalKey == LogicalKeyboardKey.arrowLeft) { if (event.logicalKey == LogicalKeyboardKey.arrowLeft) {

View File

@ -32,23 +32,23 @@ class FlowyKeyboard extends StatefulWidget {
class _FlowyKeyboardState extends State<FlowyKeyboard> class _FlowyKeyboardState extends State<FlowyKeyboard>
with FlowyKeyboardService { with FlowyKeyboardService {
final FocusNode focusNode = FocusNode(debugLabel: 'flowy_keyboard_service'); final FocusNode _focusNode = FocusNode(debugLabel: 'flowy_keyboard_service');
bool isFocus = true; bool isFocus = true;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Focus( return Focus(
focusNode: focusNode, focusNode: _focusNode,
autofocus: true,
onKey: _onKey, onKey: _onKey,
onFocusChange: _onFocusChange,
child: widget.child, child: widget.child,
); );
} }
@override @override
void dispose() { void dispose() {
focusNode.dispose(); _focusNode.dispose();
super.dispose(); super.dispose();
} }
@ -56,13 +56,17 @@ class _FlowyKeyboardState extends State<FlowyKeyboard>
@override @override
void enable() { void enable() {
isFocus = true; isFocus = true;
focusNode.requestFocus(); _focusNode.requestFocus();
} }
@override @override
void disable() { void disable() {
isFocus = false; isFocus = false;
focusNode.unfocus(); _focusNode.unfocus();
}
void _onFocusChange(bool value) {
debugPrint('[KeyBoard Service] focus change $value');
} }
KeyEventResult _onKey(FocusNode node, RawKeyEvent event) { KeyEventResult _onKey(FocusNode node, RawKeyEvent event) {

View File

@ -265,6 +265,8 @@ class _FlowySelectionState extends State<FlowySelection>
} }
final selection = Selection.collapsed(position); final selection = Selection.collapsed(position);
editorState.updateCursorSelection(selection); editorState.updateCursorSelection(selection);
editorState.service.keyboardService?.enable();
} }
@override @override