Skip to content

Commit 6961542

Browse files
authored
disable floating cursor (singerdmx#526)
1 parent 69f6404 commit 6961542

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

lib/src/widgets/editor.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ class QuillEditor extends StatefulWidget {
242242
this.onSingleLongTapEnd,
243243
this.embedBuilder = defaultEmbedBuilder,
244244
this.customStyleBuilder,
245+
this.floatingCursorDisabled = false,
245246
Key? key});
246247

247248
factory QuillEditor.basic({
@@ -306,6 +307,8 @@ class QuillEditor extends StatefulWidget {
306307
final EmbedBuilder embedBuilder;
307308
final CustomStyleBuilder? customStyleBuilder;
308309

310+
final bool floatingCursorDisabled;
311+
309312
@override
310313
_QuillEditorState createState() => _QuillEditorState();
311314
}
@@ -408,6 +411,7 @@ class _QuillEditorState extends State<QuillEditor>
408411
scrollPhysics: widget.scrollPhysics,
409412
embedBuilder: widget.embedBuilder,
410413
customStyleBuilder: widget.customStyleBuilder,
414+
floatingCursorDisabled: widget.floatingCursorDisabled,
411415
);
412416

413417
return _selectionGestureDetectorBuilder.build(
@@ -692,7 +696,8 @@ class RenderEditor extends RenderEditableContainerBox
692696
this._startHandleLayerLink,
693697
this._endHandleLayerLink,
694698
EdgeInsets floatingCursorAddedMargin,
695-
this._cursorController)
699+
this._cursorController,
700+
this.floatingCursorDisabled)
696701
: super(
697702
children,
698703
document.root,
@@ -702,6 +707,7 @@ class RenderEditor extends RenderEditableContainerBox
702707
);
703708

704709
final CursorCont _cursorController;
710+
final bool floatingCursorDisabled;
705711

706712
Document document;
707713
TextSelection selection;
@@ -1214,6 +1220,8 @@ class RenderEditor extends RenderEditableContainerBox
12141220
void setFloatingCursor(FloatingCursorDragState dragState,
12151221
Offset boundedOffset, TextPosition textPosition,
12161222
{double? resetLerpValue}) {
1223+
if (floatingCursorDisabled) return;
1224+
12171225
if (dragState == FloatingCursorDragState.Start) {
12181226
_relativeOrigin = Offset.zero;
12191227
_previousOffset = null;

lib/src/widgets/raw_editor.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class RawEditor extends StatefulWidget {
6363
this.scrollPhysics,
6464
this.embedBuilder = defaultEmbedBuilder,
6565
this.customStyleBuilder,
66+
this.floatingCursorDisabled = false
6667
}) : assert(maxHeight == null || maxHeight > 0, 'maxHeight cannot be null'),
6768
assert(minHeight == null || minHeight >= 0, 'minHeight cannot be null'),
6869
assert(maxHeight == null || minHeight == null || maxHeight >= minHeight,
@@ -95,6 +96,8 @@ class RawEditor extends StatefulWidget {
9596
final ScrollPhysics? scrollPhysics;
9697
final EmbedBuilder embedBuilder;
9798
final CustomStyleBuilder? customStyleBuilder;
99+
final bool floatingCursorDisabled;
100+
98101
@override
99102
State<StatefulWidget> createState() => RawEditorState();
100103
}
@@ -167,6 +170,7 @@ class RawEditorState extends EditorState
167170
onSelectionChanged: _handleSelectionChanged,
168171
scrollBottomInset: widget.scrollBottomInset,
169172
padding: widget.padding,
173+
floatingCursorDisabled: widget.floatingCursorDisabled,
170174
children: _buildChildren(_doc, context),
171175
),
172176
),
@@ -196,6 +200,7 @@ class RawEditorState extends EditorState
196200
scrollBottomInset: widget.scrollBottomInset,
197201
padding: widget.padding,
198202
cursorController: _cursorCont,
203+
floatingCursorDisabled: widget.floatingCursorDisabled,
199204
children: _buildChildren(_doc, context),
200205
),
201206
),
@@ -812,6 +817,7 @@ class _Editor extends MultiChildRenderObjectWidget {
812817
required this.onSelectionChanged,
813818
required this.scrollBottomInset,
814819
required this.cursorController,
820+
required this.floatingCursorDisabled,
815821
this.padding = EdgeInsets.zero,
816822
this.offset,
817823
}) : super(key: key, children: children);
@@ -827,6 +833,7 @@ class _Editor extends MultiChildRenderObjectWidget {
827833
final double scrollBottomInset;
828834
final EdgeInsetsGeometry padding;
829835
final CursorCont cursorController;
836+
final bool floatingCursorDisabled;
830837

831838
@override
832839
RenderEditor createRenderObject(BuildContext context) {
@@ -843,7 +850,8 @@ class _Editor extends MultiChildRenderObjectWidget {
843850
startHandleLayerLink,
844851
endHandleLayerLink,
845852
const EdgeInsets.fromLTRB(4, 4, 4, 5),
846-
cursorController);
853+
cursorController,
854+
floatingCursorDisabled);
847855
}
848856

849857
@override

lib/src/widgets/simple_viewer.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ class _QuillSimpleViewerState extends State<QuillSimpleViewer>
158158
scrollBottomInset: widget.scrollBottomInset,
159159
padding: widget.padding,
160160
cursorController: _cursorCont,
161+
floatingCursorDisabled: true,
161162
children: _buildChildren(_doc, context)),
162163
),
163164
);
@@ -316,6 +317,7 @@ class _SimpleViewer extends MultiChildRenderObjectWidget {
316317
required this.onSelectionChanged,
317318
required this.scrollBottomInset,
318319
required this.cursorController,
320+
required this.floatingCursorDisabled,
319321
this.offset,
320322
this.padding = EdgeInsets.zero,
321323
Key? key,
@@ -330,6 +332,7 @@ class _SimpleViewer extends MultiChildRenderObjectWidget {
330332
final double scrollBottomInset;
331333
final EdgeInsetsGeometry padding;
332334
final CursorCont cursorController;
335+
final bool floatingCursorDisabled;
333336

334337
@override
335338
RenderEditor createRenderObject(BuildContext context) {
@@ -347,7 +350,8 @@ class _SimpleViewer extends MultiChildRenderObjectWidget {
347350
startHandleLayerLink,
348351
endHandleLayerLink,
349352
const EdgeInsets.fromLTRB(4, 4, 4, 5),
350-
cursorController);
353+
cursorController,
354+
floatingCursorDisabled);
351355
}
352356

353357
@override

0 commit comments

Comments
 (0)