Fixbug Indent, style status of button

pull/1372/head
Phạm Hoàng Sang 2 years ago
parent 5dca6008cd
commit 14b6f12f39
  1. 14
      lib/src/models/documents/document.dart
  2. 5
      lib/src/widgets/controller.dart
  3. 10
      lib/src/widgets/editor.dart

@ -156,7 +156,19 @@ class Document {
/// included in the result.
Style collectStyle(int index, int len) {
final res = queryChild(index);
return (res.node as Line).collectStyle(res.offset, len);
// -1 because the cursor is at the part of the line that is not visible
// Bug: When the caret is in the middle of the paragraph
// and at the end of the format string, it will display the wrong state
// of the format button
final isNotLinkStyle =
res.node?.style.attributes[Attribute.link.key]?.value == false;
// In this case, we have an exception, this is a link.
// When node is a link we will not -1
return (res.node as Line).collectStyle(
len == 0 && res.node != null && isNotLinkStyle
? res.offset - 1
: res.offset,
len);
}
/// Returns all styles and Embed for each node within selection

@ -122,11 +122,14 @@ class QuillController extends ChangeNotifier {
formatSelection(Attribute.clone(Attribute.indentL1, null));
return;
}
if (isIncrease) {
if (isIncrease && indent.value < 5) {
formatSelection(Attribute.getIndentLevel(indent.value + 1));
return;
}
if (indent.value > 0) {
formatSelection(Attribute.getIndentLevel(indent.value - 1));
return;
}
}
void _indentSelectionEachLine(bool isIncrease) {

@ -192,6 +192,7 @@ class QuillEditor extends StatefulWidget {
this.dialogTheme,
this.contentInsertionConfiguration,
this.contextMenuBuilder,
this.editorKey,
Key? key,
}) : super(key: key);
@ -205,6 +206,7 @@ class QuillEditor extends StatefulWidget {
bool expands = false,
FocusNode? focusNode,
String? placeholder,
GlobalKey<EditorState>? editorKey,
/// The locale to use for the editor toolbar, defaults to system locale
/// More at https://github.com/singerdmx/flutter-quill#translation
@ -223,6 +225,7 @@ class QuillEditor extends StatefulWidget {
locale: locale,
embedBuilders: embedBuilders,
placeholder: placeholder,
editorKey: editorKey,
);
}
@ -448,19 +451,24 @@ class QuillEditor extends StatefulWidget {
/// See [https://api.flutter.dev/flutter/widgets/EditableText/contentInsertionConfiguration.html]
final ContentInsertionConfiguration? contentInsertionConfiguration;
/// Using the editorKey for get getLocalRectForCaret
/// editorKey.currentState?.renderEditor.getLocalRectForCaret
final GlobalKey<EditorState>? editorKey;
@override
QuillEditorState createState() => QuillEditorState();
}
class QuillEditorState extends State<QuillEditor>
implements EditorTextSelectionGestureDetectorBuilderDelegate {
final GlobalKey<EditorState> _editorKey = GlobalKey<EditorState>();
late GlobalKey<EditorState> _editorKey;
late EditorTextSelectionGestureDetectorBuilder
_selectionGestureDetectorBuilder;
@override
void initState() {
super.initState();
_editorKey = widget.editorKey ?? GlobalKey<EditorState>();
_selectionGestureDetectorBuilder =
_QuillEditorSelectionGestureDetectorBuilder(
this, widget.detectWordBoundary);

Loading…
Cancel
Save