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 (0 <= selectedIndex && selectedIndex < widget.items.length) {
widget.items[selectedIndex].handler(widget.editorState);
return KeyEventResult.handled;
}
}
if (event.logicalKey == LogicalKeyboardKey.escape) {
clearPopupListOverlay();
return KeyEventResult.handled;
}
var newSelectedIndex = selectedIndex;
if (event.logicalKey == LogicalKeyboardKey.arrowLeft) {

View File

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

View File

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