diff --git a/lib/src/editor/editor.dart b/lib/src/editor/editor.dart index a46fba7e..57a6cfa8 100644 --- a/lib/src/editor/editor.dart +++ b/lib/src/editor/editor.dart @@ -174,16 +174,28 @@ class QuillEditorState extends State @override void initState() { super.initState(); - widget.configurations.controller.editorFocusNode ??= widget.focusNode; - if (configurations.autoFocus) { - widget.configurations.controller.editorFocusNode?.requestFocus(); - } + _editorKey = configurations.editorKey ?? GlobalKey(); _selectionGestureDetectorBuilder = _QuillEditorSelectionGestureDetectorBuilder( this, configurations.detectWordBoundary, ); + + final focusNode = + widget.configurations.controller.editorFocusNode ?? widget.focusNode; + widget.configurations.controller.editorFocusNode = focusNode; + + if (configurations.autoFocus) { + focusNode.requestFocus(); + } + + // Hide toolbar when the editor loses focus. + focusNode.addListener(() { + if (!focusNode.hasFocus) { + _editorKey.currentState?.hideToolbar(); + } + }); } @override