Skip to content

Commit b24b826

Browse files
committed
Revert "Fix caret not auto scroll to visible when page has multiple editors (#2570)"
This reverts commit 3ac4027.
1 parent 3cd4132 commit b24b826

File tree

7 files changed

+123
-193
lines changed

7 files changed

+123
-193
lines changed

CHANGELOG.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
1111
## [Unreleased]
1212

13-
### Fixed
14-
- Fix caret not auto scroll to visible when page has multiple editors [#2570](https://github.com/singerdmx/flutter-quill/pull/2570).
15-
16-
### Changed
17-
- **BREAKING**: QuillEditorConfig is now accept `EdgeInsets padding` instead of `EdgeInsetsGeometry`.
18-
1913
## [11.4.1] - 2025-05-15
2014

2115
### Added

example/pubspec.lock

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ packages:
1313
dependency: transitive
1414
description:
1515
name: async
16-
sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb"
16+
sha256: d2872f9c19731c2e5f10444b14686eb7cc85c76274bd6c16e1816bff9a3bab63
1717
url: "https://pub.dev"
1818
source: hosted
19-
version: "2.13.0"
19+
version: "2.12.0"
2020
boolean_selector:
2121
dependency: transitive
2222
description:
@@ -93,10 +93,10 @@ packages:
9393
dependency: transitive
9494
description:
9595
name: fake_async
96-
sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44"
96+
sha256: "6a95e56b2449df2273fd8c45a662d6947ce1ebb7aafe80e550a3f68297f3cacc"
9797
url: "https://pub.dev"
9898
source: hosted
99-
version: "1.3.3"
99+
version: "1.3.2"
100100
ffi:
101101
dependency: transitive
102102
description:
@@ -365,18 +365,18 @@ packages:
365365
dependency: transitive
366366
description:
367367
name: intl
368-
sha256: "3df61194eb431efc39c4ceba583b95633a403f46c9fd341e550ce0bfa50e9aa5"
368+
sha256: d6f56758b7d3014a48af9701c085700aac781a92a87a62b1333b46d8879661cf
369369
url: "https://pub.dev"
370370
source: hosted
371-
version: "0.20.2"
371+
version: "0.19.0"
372372
leak_tracker:
373373
dependency: transitive
374374
description:
375375
name: leak_tracker
376-
sha256: "6bb818ecbdffe216e81182c2f0714a2e62b593f4a4f13098713ff1685dfb6ab0"
376+
sha256: c35baad643ba394b40aac41080300150a4f08fd0fd6a10378f8f7c6bc161acec
377377
url: "https://pub.dev"
378378
source: hosted
379-
version: "10.0.9"
379+
version: "10.0.8"
380380
leak_tracker_flutter_testing:
381381
dependency: transitive
382382
description:
@@ -738,10 +738,10 @@ packages:
738738
dependency: transitive
739739
description:
740740
name: vm_service
741-
sha256: ddfa8d30d89985b96407efce8acbdd124701f96741f2d981ca860662f1c0dc02
741+
sha256: "0968250880a6c5fe7edc067ed0a13d4bae1577fe2771dcf3010d52c4a9d3ca14"
742742
url: "https://pub.dev"
743743
source: hosted
744-
version: "15.0.0"
744+
version: "14.3.1"
745745
web:
746746
dependency: transitive
747747
description:
@@ -754,10 +754,10 @@ packages:
754754
dependency: transitive
755755
description:
756756
name: webdriver
757-
sha256: "2f3a14ca026957870cfd9c635b83507e0e51d8091568e90129fbf805aba7cade"
757+
sha256: "3d773670966f02a646319410766d3b5e1037efb7f07cc68f844d5e06cd4d61c8"
758758
url: "https://pub.dev"
759759
source: hosted
760-
version: "3.1.0"
760+
version: "3.0.4"
761761
win32:
762762
dependency: transitive
763763
description:

lib/src/editor/config/editor_config.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// @docImport '../../rules/insert.dart';
1+
/// @docImport '../../rules/insert.dart' show AutoFormatMultipleLinksRule;
22
library;
33

44
import 'dart:ui' as ui;
@@ -214,7 +214,7 @@ class QuillEditorConfig {
214214

215215
/// Additional space around the content of this editor.
216216
/// by default will be [EdgeInsets.zero]
217-
final EdgeInsets padding;
217+
final EdgeInsetsGeometry padding;
218218

219219
/// Whether this editor should focus itself if nothing else is already
220220
/// focused.
@@ -484,7 +484,7 @@ class QuillEditorConfig {
484484
bool? scrollable,
485485
double? scrollBottomInset,
486486
bool? enableAlwaysIndentOnTab,
487-
EdgeInsets? padding,
487+
EdgeInsetsGeometry? padding,
488488
bool? autoFocus,
489489
bool? onTapOutsideEnabled,
490490
Function(PointerDownEvent event, FocusNode focusNode)? onTapOutside,

lib/src/editor/editor.dart

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,71 @@ class RenderEditor extends RenderEditableContainerBox
12221222
);
12231223
}
12241224

1225+
/// Returns the y-offset of the editor at which [selection] is visible.
1226+
///
1227+
/// The offset is the distance from the top of the editor and is the minimum
1228+
/// from the current scroll position until [selection] becomes visible.
1229+
/// Returns null if [selection] is already visible.
1230+
///
1231+
/// Finds the closest scroll offset that fully reveals the editing cursor.
1232+
///
1233+
/// The `scrollOffset` parameter represents current scroll offset in the
1234+
/// parent viewport.
1235+
///
1236+
/// The `offsetInViewport` parameter represents the editor's vertical offset
1237+
/// in the parent viewport. This value should normally be 0.0 if this editor
1238+
/// is the only child of the viewport or if it's the topmost child. Otherwise
1239+
/// it should be a positive value equal to total height of all siblings of
1240+
/// this editor from above it.
1241+
///
1242+
/// Returns `null` if the cursor is currently visible.
1243+
double? getOffsetToRevealCursor(
1244+
double viewportHeight, double scrollOffset, double offsetInViewport) {
1245+
// Endpoints coordinates represents lower left or lower right corner of
1246+
// the selection. If we want to scroll up to reveal the caret we need to
1247+
// adjust the dy value by the height of the line. We also add a small margin
1248+
// so that the caret is not too close to the edge of the viewport.
1249+
final endpoints = getEndpointsForSelection(selection);
1250+
1251+
// when we drag the right handle, we should get the last point
1252+
TextSelectionPoint endpoint;
1253+
if (selection.isCollapsed) {
1254+
endpoint = endpoints.first;
1255+
} else {
1256+
if (selection is DragTextSelection) {
1257+
endpoint = (selection as DragTextSelection).first
1258+
? endpoints.first
1259+
: endpoints.last;
1260+
} else {
1261+
endpoint = endpoints.first;
1262+
}
1263+
}
1264+
1265+
// Collapsed selection => caret
1266+
final child = childAtPosition(selection.extent);
1267+
const kMargin = 8.0;
1268+
1269+
final caretTop = endpoint.point.dy -
1270+
child.preferredLineHeight(TextPosition(
1271+
offset: selection.extentOffset - child.container.documentOffset)) -
1272+
kMargin +
1273+
offsetInViewport +
1274+
scrollBottomInset;
1275+
final caretBottom =
1276+
endpoint.point.dy + kMargin + offsetInViewport + scrollBottomInset;
1277+
double? dy;
1278+
if (caretTop < scrollOffset) {
1279+
dy = caretTop;
1280+
} else if (caretBottom > scrollOffset + viewportHeight) {
1281+
dy = caretBottom - viewportHeight;
1282+
}
1283+
if (dy == null) {
1284+
return null;
1285+
}
1286+
// Clamping to 0.0 so that the content does not jump unnecessarily.
1287+
return math.max(dy, 0);
1288+
}
1289+
12251290
@override
12261291
Rect getLocalRectForCaret(TextPosition position) {
12271292
final targetChild = childAtPosition(position);
@@ -1233,10 +1298,6 @@ class RenderEditor extends RenderEditableContainerBox
12331298
return childLocalRect.shift(Offset(0, boxParentData.offset.dy));
12341299
}
12351300

1236-
TextPosition get caretTextPosition => _floatingCursorRect == null
1237-
? selection.extent
1238-
: _floatingCursorTextPosition;
1239-
12401301
// Start floating cursor
12411302

12421303
FloatingCursorPainter get _floatingCursorPainter => FloatingCursorPainter(

lib/src/editor/raw_editor/config/raw_editor_config.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class QuillRawEditorConfig {
159159
final KeyEventResult? Function(KeyEvent event, Node? node)? onKeyPressed;
160160

161161
/// Additional space around the editor contents.
162-
final EdgeInsets padding;
162+
final EdgeInsetsGeometry padding;
163163

164164
/// Enables always indenting when the TAB key is pressed.
165165
///

0 commit comments

Comments
 (0)