diff --git a/doc/translation.md b/doc/translation.md index 76981a01..35d813e6 100644 --- a/doc/translation.md +++ b/doc/translation.md @@ -15,8 +15,8 @@ QuillToolbar.simple( ), Expanded( child: QuillEditor.basic( + controller: _controller, configurations: QuillEditorConfigurations( - controller: _controller, sharedConfigurations: const QuillSharedConfigurations( locale: Locale('de'), ), diff --git a/lib/src/editor/editor.dart b/lib/src/editor/editor.dart index 2f92393e..86e11cc8 100644 --- a/lib/src/editor/editor.dart +++ b/lib/src/editor/editor.dart @@ -286,8 +286,8 @@ class QuillEditorState extends State builder: configurations.builder, child: QuillRawEditor( key: _editorKey, + controller: controller, configurations: QuillRawEditorConfigurations( - controller: controller, focusNode: widget.focusNode, scrollController: widget.scrollController, scrollable: configurations.scrollable, @@ -489,15 +489,15 @@ class _QuillEditorSelectionGestureDetectorBuilder return false; } final pos = renderEditor!.getPositionForOffset(details.globalPosition); - final result = editor!.widget.configurations.controller.document - .querySegmentLeafNode(pos.offset); + final result = + editor!.widget.controller.document.querySegmentLeafNode(pos.offset); final line = result.line; if (line == null) { return false; } final segmentLeaf = result.leaf; if (segmentLeaf == null && line.length == 1) { - editor!.widget.configurations.controller.updateSelection( + editor!.widget.controller.updateSelection( TextSelection.collapsed(offset: pos.offset), ChangeSource.local, ); diff --git a/lib/src/editor/raw_editor/config/raw_editor_configurations.dart b/lib/src/editor/raw_editor/config/raw_editor_configurations.dart index dedd3fb3..81c9c298 100644 --- a/lib/src/editor/raw_editor/config/raw_editor_configurations.dart +++ b/lib/src/editor/raw_editor/config/raw_editor_configurations.dart @@ -40,7 +40,6 @@ import '../../../toolbar/theme/quill_dialog_theme.dart'; @immutable class QuillRawEditorConfigurations extends Equatable { const QuillRawEditorConfigurations({ - required this.controller, required this.focusNode, required this.scrollController, required this.scrollBottomInset, @@ -49,6 +48,9 @@ class QuillRawEditorConfigurations extends Equatable { required this.selectionCtrls, required this.embedBuilder, required this.autoFocus, + @Deprecated( + 'controller should be passed directly to the editor - this parameter will be removed in future versions.') + this.controller, this.showCursor = true, this.scrollable = true, this.padding = EdgeInsets.zero, @@ -93,7 +95,7 @@ class QuillRawEditorConfigurations extends Equatable { }); /// Controls the document being edited. - final QuillController controller; + final QuillController? controller; /// Controls whether this editor has keyboard focus. final FocusNode focusNode; diff --git a/lib/src/editor/raw_editor/raw_editor.dart b/lib/src/editor/raw_editor/raw_editor.dart index 5a6d04cf..8f162637 100644 --- a/lib/src/editor/raw_editor/raw_editor.dart +++ b/lib/src/editor/raw_editor/raw_editor.dart @@ -12,6 +12,7 @@ import 'package:flutter/widgets.dart' immutable; import '../../common/structs/offset_value.dart'; +import '../../controller/quill_controller.dart'; import '../editor.dart'; import '../widgets/text/text_selection.dart'; import 'config/raw_editor_configurations.dart'; @@ -20,8 +21,11 @@ import 'raw_editor_state.dart'; class QuillRawEditor extends StatefulWidget { QuillRawEditor({ required this.configurations, + controller, super.key, - }) : assert( + }) : assert((controller ?? configurations.controller) != null), + controller = controller ?? configurations.controller, + assert( configurations.maxHeight == null || configurations.maxHeight! > 0, 'maxHeight cannot be null'), assert( @@ -33,6 +37,7 @@ class QuillRawEditor extends StatefulWidget { configurations.maxHeight! >= configurations.minHeight!, 'maxHeight cannot be null'); + final QuillController controller; final QuillRawEditorConfigurations configurations; @override diff --git a/lib/src/editor/raw_editor/raw_editor_state.dart b/lib/src/editor/raw_editor/raw_editor_state.dart index 37f4bc2c..ea501b7a 100644 --- a/lib/src/editor/raw_editor/raw_editor_state.dart +++ b/lib/src/editor/raw_editor/raw_editor_state.dart @@ -77,7 +77,7 @@ class QuillRawEditorState extends EditorState // Cursors late CursorCont _cursorCont; - QuillController get controller => widget.configurations.controller; + QuillController get controller => widget.controller; // Focus bool _didAutoFocus = false; @@ -1275,8 +1275,7 @@ class QuillRawEditorState extends EditorState _cursorCont.style = widget.configurations.cursorStyle; if (controller != oldWidget.configurations.controller) { - oldWidget.configurations.controller - .removeListener(_didChangeTextEditingValue); + oldWidget.controller.removeListener(_didChangeTextEditingValue); controller.addListener(_didChangeTextEditingValue); updateRemoteValueIfNeeded(); } @@ -1293,7 +1292,7 @@ class QuillRawEditorState extends EditorState updateKeepAlive(); } - if (controller.selection != oldWidget.configurations.controller.selection) { + if (controller.selection != oldWidget.controller.selection) { _selectionOverlay?.update(textEditingValue); } @@ -1348,7 +1347,7 @@ class QuillRawEditorState extends EditorState /// operating on stale data. void _markNeedsBuild() { if (_dirty) { - // No need to rebuilt if it already darty + // No need to rebuilt if it already dirty return; } setState(() { @@ -1626,7 +1625,7 @@ class QuillRawEditorState extends EditorState final QuillEditorTextBoundary boundary; // final TextEditingValue textEditingValue = - // _textEditingValueforTextLayoutMetrics; + // _textEditingValueForTextLayoutMetrics; atomicTextBoundary = QuillEditorCharacterBoundary(textEditingValue); // This isn't enough. Newline characters. boundary = QuillEditorExpandedTextBoundary( diff --git a/lib/src/editor/raw_editor/raw_editor_state_selection_delegate_mixin.dart b/lib/src/editor/raw_editor/raw_editor_state_selection_delegate_mixin.dart index 55cda637..247e7728 100644 --- a/lib/src/editor/raw_editor/raw_editor_state_selection_delegate_mixin.dart +++ b/lib/src/editor/raw_editor/raw_editor_state_selection_delegate_mixin.dart @@ -11,22 +11,21 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState implements TextSelectionDelegate { @override TextEditingValue get textEditingValue { - return widget.configurations.controller.plainTextEditingValue; + return widget.controller.plainTextEditingValue; } set textEditingValue(TextEditingValue value) { final cursorPosition = value.selection.extentOffset; - final oldText = widget.configurations.controller.document.toPlainText(); + final oldText = widget.controller.document.toPlainText(); final newText = value.text; final diff = getDiff(oldText, newText, cursorPosition); if (diff.deleted == '' && diff.inserted == '') { // Only changing selection range - widget.configurations.controller - .updateSelection(value.selection, ChangeSource.local); + widget.controller.updateSelection(value.selection, ChangeSource.local); return; } - widget.configurations.controller.replaceTextWithEmbeds( + widget.controller.replaceTextWithEmbeds( diff.start, diff.deleted.length, diff.inserted, value.selection); } diff --git a/lib/src/editor/raw_editor/raw_editor_state_text_input_client_mixin.dart b/lib/src/editor/raw_editor/raw_editor_state_text_input_client_mixin.dart index 7aacc28f..d9f2fa14 100644 --- a/lib/src/editor/raw_editor/raw_editor_state_text_input_client_mixin.dart +++ b/lib/src/editor/raw_editor/raw_editor_state_text_input_client_mixin.dart @@ -198,10 +198,9 @@ mixin RawEditorStateTextInputClientMixin on EditorState final cursorPosition = value.selection.extentOffset; final diff = getDiff(oldText, text, cursorPosition); if (diff.deleted.isEmpty && diff.inserted.isEmpty) { - widget.configurations.controller - .updateSelection(value.selection, ChangeSource.local); + widget.controller.updateSelection(value.selection, ChangeSource.local); } else { - widget.configurations.controller.replaceText( + widget.controller.replaceText( diff.start, diff.deleted.length, diff.inserted,