From cab454f1a981a40399995b79105366bf27bc07e6 Mon Sep 17 00:00:00 2001 From: DatDang Date: Thu, 11 Jul 2024 16:00:49 +0700 Subject: [PATCH] Resolve focus jumping --- lib/src/widgets/html_editor_widget_web.dart | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/src/widgets/html_editor_widget_web.dart b/lib/src/widgets/html_editor_widget_web.dart index 2989ec9f..9190c1c6 100644 --- a/lib/src/widgets/html_editor_widget_web.dart +++ b/lib/src/widgets/html_editor_widget_web.dart @@ -67,6 +67,7 @@ class _HtmlEditorWidgetWebState extends State { StreamSubscription? _editorJSListener; StreamSubscription? _summernoteOnLoadListener; static const String _summernoteLoadedMessage = '_HtmlEditorWidgetWebState::summernoteLoaded'; + final _focusNode = FocusNode(); @override void initState() { @@ -634,7 +635,7 @@ class _HtmlEditorWidgetWebState extends State { @override Widget build(BuildContext context) { - return SizedBox( + final child = SizedBox( height: widget.htmlEditorOptions.autoAdjustHeight ? actualHeight : widget.otherOptions.height, @@ -674,6 +675,10 @@ class _HtmlEditorWidgetWebState extends State { ], ), ); + + return Focus( + focusNode: _focusNode, + child: child); } /// Adds the callbacks the user set into JavaScript @@ -811,6 +816,7 @@ class _HtmlEditorWidgetWebState extends State { c.onEnter!.call(); } if (data['type'].contains('onFocus')) { + _focusNode.requestFocus(); c.onFocus!.call(); } if (data['type'].contains('onBlur')) { @@ -988,6 +994,7 @@ class _HtmlEditorWidgetWebState extends State { void dispose() { _editorJSListener?.cancel(); _summernoteOnLoadListener?.cancel(); + _focusNode.dispose(); super.dispose(); } }