disable floating cursor (#526)

pull/531/head
Andy Trand 3 years ago committed by GitHub
parent 69f64047b5
commit 6961542216
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      lib/src/widgets/editor.dart
  2. 10
      lib/src/widgets/raw_editor.dart
  3. 6
      lib/src/widgets/simple_viewer.dart

@ -242,6 +242,7 @@ class QuillEditor extends StatefulWidget {
this.onSingleLongTapEnd, this.onSingleLongTapEnd,
this.embedBuilder = defaultEmbedBuilder, this.embedBuilder = defaultEmbedBuilder,
this.customStyleBuilder, this.customStyleBuilder,
this.floatingCursorDisabled = false,
Key? key}); Key? key});
factory QuillEditor.basic({ factory QuillEditor.basic({
@ -306,6 +307,8 @@ class QuillEditor extends StatefulWidget {
final EmbedBuilder embedBuilder; final EmbedBuilder embedBuilder;
final CustomStyleBuilder? customStyleBuilder; final CustomStyleBuilder? customStyleBuilder;
final bool floatingCursorDisabled;
@override @override
_QuillEditorState createState() => _QuillEditorState(); _QuillEditorState createState() => _QuillEditorState();
} }
@ -408,6 +411,7 @@ class _QuillEditorState extends State<QuillEditor>
scrollPhysics: widget.scrollPhysics, scrollPhysics: widget.scrollPhysics,
embedBuilder: widget.embedBuilder, embedBuilder: widget.embedBuilder,
customStyleBuilder: widget.customStyleBuilder, customStyleBuilder: widget.customStyleBuilder,
floatingCursorDisabled: widget.floatingCursorDisabled,
); );
return _selectionGestureDetectorBuilder.build( return _selectionGestureDetectorBuilder.build(
@ -692,7 +696,8 @@ class RenderEditor extends RenderEditableContainerBox
this._startHandleLayerLink, this._startHandleLayerLink,
this._endHandleLayerLink, this._endHandleLayerLink,
EdgeInsets floatingCursorAddedMargin, EdgeInsets floatingCursorAddedMargin,
this._cursorController) this._cursorController,
this.floatingCursorDisabled)
: super( : super(
children, children,
document.root, document.root,
@ -702,6 +707,7 @@ class RenderEditor extends RenderEditableContainerBox
); );
final CursorCont _cursorController; final CursorCont _cursorController;
final bool floatingCursorDisabled;
Document document; Document document;
TextSelection selection; TextSelection selection;
@ -1214,6 +1220,8 @@ class RenderEditor extends RenderEditableContainerBox
void setFloatingCursor(FloatingCursorDragState dragState, void setFloatingCursor(FloatingCursorDragState dragState,
Offset boundedOffset, TextPosition textPosition, Offset boundedOffset, TextPosition textPosition,
{double? resetLerpValue}) { {double? resetLerpValue}) {
if (floatingCursorDisabled) return;
if (dragState == FloatingCursorDragState.Start) { if (dragState == FloatingCursorDragState.Start) {
_relativeOrigin = Offset.zero; _relativeOrigin = Offset.zero;
_previousOffset = null; _previousOffset = null;

@ -63,6 +63,7 @@ class RawEditor extends StatefulWidget {
this.scrollPhysics, this.scrollPhysics,
this.embedBuilder = defaultEmbedBuilder, this.embedBuilder = defaultEmbedBuilder,
this.customStyleBuilder, this.customStyleBuilder,
this.floatingCursorDisabled = false
}) : assert(maxHeight == null || maxHeight > 0, 'maxHeight cannot be null'), }) : assert(maxHeight == null || maxHeight > 0, 'maxHeight cannot be null'),
assert(minHeight == null || minHeight >= 0, 'minHeight cannot be null'), assert(minHeight == null || minHeight >= 0, 'minHeight cannot be null'),
assert(maxHeight == null || minHeight == null || maxHeight >= minHeight, assert(maxHeight == null || minHeight == null || maxHeight >= minHeight,
@ -95,6 +96,8 @@ class RawEditor extends StatefulWidget {
final ScrollPhysics? scrollPhysics; final ScrollPhysics? scrollPhysics;
final EmbedBuilder embedBuilder; final EmbedBuilder embedBuilder;
final CustomStyleBuilder? customStyleBuilder; final CustomStyleBuilder? customStyleBuilder;
final bool floatingCursorDisabled;
@override @override
State<StatefulWidget> createState() => RawEditorState(); State<StatefulWidget> createState() => RawEditorState();
} }
@ -167,6 +170,7 @@ class RawEditorState extends EditorState
onSelectionChanged: _handleSelectionChanged, onSelectionChanged: _handleSelectionChanged,
scrollBottomInset: widget.scrollBottomInset, scrollBottomInset: widget.scrollBottomInset,
padding: widget.padding, padding: widget.padding,
floatingCursorDisabled: widget.floatingCursorDisabled,
children: _buildChildren(_doc, context), children: _buildChildren(_doc, context),
), ),
), ),
@ -196,6 +200,7 @@ class RawEditorState extends EditorState
scrollBottomInset: widget.scrollBottomInset, scrollBottomInset: widget.scrollBottomInset,
padding: widget.padding, padding: widget.padding,
cursorController: _cursorCont, cursorController: _cursorCont,
floatingCursorDisabled: widget.floatingCursorDisabled,
children: _buildChildren(_doc, context), children: _buildChildren(_doc, context),
), ),
), ),
@ -812,6 +817,7 @@ class _Editor extends MultiChildRenderObjectWidget {
required this.onSelectionChanged, required this.onSelectionChanged,
required this.scrollBottomInset, required this.scrollBottomInset,
required this.cursorController, required this.cursorController,
required this.floatingCursorDisabled,
this.padding = EdgeInsets.zero, this.padding = EdgeInsets.zero,
this.offset, this.offset,
}) : super(key: key, children: children); }) : super(key: key, children: children);
@ -827,6 +833,7 @@ class _Editor extends MultiChildRenderObjectWidget {
final double scrollBottomInset; final double scrollBottomInset;
final EdgeInsetsGeometry padding; final EdgeInsetsGeometry padding;
final CursorCont cursorController; final CursorCont cursorController;
final bool floatingCursorDisabled;
@override @override
RenderEditor createRenderObject(BuildContext context) { RenderEditor createRenderObject(BuildContext context) {
@ -843,7 +850,8 @@ class _Editor extends MultiChildRenderObjectWidget {
startHandleLayerLink, startHandleLayerLink,
endHandleLayerLink, endHandleLayerLink,
const EdgeInsets.fromLTRB(4, 4, 4, 5), const EdgeInsets.fromLTRB(4, 4, 4, 5),
cursorController); cursorController,
floatingCursorDisabled);
} }
@override @override

@ -158,6 +158,7 @@ class _QuillSimpleViewerState extends State<QuillSimpleViewer>
scrollBottomInset: widget.scrollBottomInset, scrollBottomInset: widget.scrollBottomInset,
padding: widget.padding, padding: widget.padding,
cursorController: _cursorCont, cursorController: _cursorCont,
floatingCursorDisabled: true,
children: _buildChildren(_doc, context)), children: _buildChildren(_doc, context)),
), ),
); );
@ -316,6 +317,7 @@ class _SimpleViewer extends MultiChildRenderObjectWidget {
required this.onSelectionChanged, required this.onSelectionChanged,
required this.scrollBottomInset, required this.scrollBottomInset,
required this.cursorController, required this.cursorController,
required this.floatingCursorDisabled,
this.offset, this.offset,
this.padding = EdgeInsets.zero, this.padding = EdgeInsets.zero,
Key? key, Key? key,
@ -330,6 +332,7 @@ class _SimpleViewer extends MultiChildRenderObjectWidget {
final double scrollBottomInset; final double scrollBottomInset;
final EdgeInsetsGeometry padding; final EdgeInsetsGeometry padding;
final CursorCont cursorController; final CursorCont cursorController;
final bool floatingCursorDisabled;
@override @override
RenderEditor createRenderObject(BuildContext context) { RenderEditor createRenderObject(BuildContext context) {
@ -347,7 +350,8 @@ class _SimpleViewer extends MultiChildRenderObjectWidget {
startHandleLayerLink, startHandleLayerLink,
endHandleLayerLink, endHandleLayerLink,
const EdgeInsets.fromLTRB(4, 4, 4, 5), const EdgeInsets.fromLTRB(4, 4, 4, 5),
cursorController); cursorController,
floatingCursorDisabled);
} }
@override @override

Loading…
Cancel
Save