Organize raw editor configurations

pull/2078/head
AtlasAutocode 9 months ago
parent f853a4e9d7
commit d354ab21f9
  1. 2
      doc/translation.md
  2. 8
      lib/src/editor/editor.dart
  3. 6
      lib/src/editor/raw_editor/config/raw_editor_configurations.dart
  4. 7
      lib/src/editor/raw_editor/raw_editor.dart
  5. 11
      lib/src/editor/raw_editor/raw_editor_state.dart
  6. 9
      lib/src/editor/raw_editor/raw_editor_state_selection_delegate_mixin.dart
  7. 5
      lib/src/editor/raw_editor/raw_editor_state_text_input_client_mixin.dart

@ -15,8 +15,8 @@ QuillToolbar.simple(
),
Expanded(
child: QuillEditor.basic(
controller: _controller,
configurations: QuillEditorConfigurations(
controller: _controller,
sharedConfigurations: const QuillSharedConfigurations(
locale: Locale('de'),
),

@ -286,8 +286,8 @@ class QuillEditorState extends State<QuillEditor>
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,
);

@ -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;

@ -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

@ -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(

@ -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);
}

@ -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,

Loading…
Cancel
Save