Skip to content

Commit 6746614

Browse files
committed
Keep reading caret comments within the repository guideline
1 parent 51fe941 commit 6746614

5 files changed

Lines changed: 24 additions & 38 deletions

File tree

‎lib/shortcuts/configured_shortcut_scope.dart‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ class ConfiguredShortcutScope extends InheritedWidget {
1818
required super.child,
1919
});
2020

21-
/// Handles a matching configured command once and returns its ownership.
22-
/// A known but unavailable command also claims the key without performing it.
23-
/// Fixed navigation keys are outside this scope.
21+
/// Dispatches matching configured commands once and returns key ownership.
22+
/// Unavailable commands still claim; fixed navigation keys stay outside.
2423
final ConfiguredShortcutClaim? Function(KeyDownEvent event) onKeyDown;
2524

2625
static ConfiguredShortcutClaim? claim(

‎lib/text_book/view/combined_view/combined_book_screen.dart‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -832,9 +832,8 @@ class _CombinedViewState extends State<CombinedView> {
832832
_selectionLineStart = null;
833833
_selectionLineEnd = null;
834834
_selectionStartColumn = null;
835-
// Native clears also invalidate the parent reader's selection actions.
836-
// Book resets own their lifecycle, and correction selections were already
837-
// reported as null. Repeated empty callbacks must not notify again.
835+
// Notify native clears once; resets own their lifecycle, and correction
836+
// selections have already cleared the parent.
838837
if (notifyParent &&
839838
hadText &&
840839
!_hasLocalCorrections &&

‎lib/text_book/view/reading_caret/reading_caret.dart‎

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ class ReadingCaretController extends ChangeNotifier {
7070
region!._selectionChanged();
7171
return;
7272
}
73-
// Native readers distinguish an empty selection from a cleared selection,
74-
// notably while preserving a selection for a secondary click. Keep that
75-
// callback and its focus/copy guards exactly as they are.
73+
// Preserve native empty-versus-null semantics and existing focus/copy guards;
74+
// a secondary click may intentionally retain an empty selection.
7675
_lastSelection = null;
7776
_unreportedSelection = null;
7877
_region?._ownsSelectionEndpoints = false;
@@ -103,9 +102,8 @@ class ReadingCaretController extends ChangeNotifier {
103102
if (previous == null || region == null) return;
104103
final content = region._delegate?.getSelectedContent();
105104
if (content?.plainText == previous.plainText) return;
106-
// Public dispatch does not update SelectableRegion's native callback cache.
107-
// A subsequent native clear may therefore emit no callback. Fill only that
108-
// gap after the transaction, retaining its raw empty-versus-null meaning.
105+
// Public dispatch leaves Flutter's callback cache unchanged. Report a silent
106+
// native clear after the transaction, preserving empty versus null.
109107
_unreportedSelection = null;
110108
_lastSelection = null;
111109
region._ownsSelectionEndpoints = false;
@@ -369,9 +367,8 @@ class _ReadingCaretRegionState extends State<ReadingCaretRegion>
369367
final owner = widget.owner;
370368
final delegate = _delegate;
371369
final region = _selectionRegion;
372-
// A reused SelectionArea can still hold the previous tab's collapsed range.
373-
// Clear it outside build before adopting geometry for the new owner. The
374-
// token is a separate generation: focus changes must not cancel this reset.
370+
// Clear a reused SelectionArea outside build before adopting the new owner.
371+
// A separate reset token prevents focus changes from cancelling the clear.
375372
WidgetsBinding.instance.addPostFrameCallback((_) {
376373
if (!mounted ||
377374
!_connected ||
@@ -618,10 +615,8 @@ class _ReadingCaretRegionState extends State<ReadingCaretRegion>
618615
_adoptSelection();
619616
return;
620617
}
621-
// A selection ending at offset zero in the next paragraph has no selected
622-
// glyph there. Flutter may report the previous paragraph's trailing edge
623-
// for that same range. Retain the explicit caret position and affinity;
624-
// only native interaction may replace it with the delegate's endpoint.
618+
// At offset zero Flutter may report the previous paragraph's trailing edge.
619+
// Retain explicit endpoints until native interaction replaces them.
625620
final paragraphs = _paragraphs();
626621
_base = _restore(_base, paragraphs) ?? _base;
627622
_extent = _restore(_extent, paragraphs) ?? _extent;
@@ -653,9 +648,8 @@ class _ReadingCaretRegionState extends State<ReadingCaretRegion>
653648
extent.position.selectionPoint == null) {
654649
return;
655650
}
656-
// A font/style layout replaces RenderParagraph's selectable fragments.
657-
// Restore the actual range in their completed registration transaction,
658-
// using the same source/item identities and the same public delegate.
651+
// Layout replaces selectable fragments. Restore the real range only after
652+
// registration completes, preserving source/item identities.
659653
_place(extent, extend: true, replayBase: base);
660654
}
661655

@@ -677,9 +671,8 @@ class _ReadingCaretRegionState extends State<ReadingCaretRegion>
677671
final owner = widget.owner;
678672
final generation = _generation;
679673
final version = ++_selectionSyncVersion;
680-
// A scrollable updates its child registry in a post-frame callback. Its
681-
// geometry notification can precede completion of the child's range.
682-
// Observe the completed transaction, and never republish a native event.
674+
// Registry notifications may precede the completed post-frame range.
675+
// Observe the finished transaction without republishing native events.
683676
scheduleMicrotask(() {
684677
if (!mounted ||
685678
!_connected ||

‎lib/text_book/view/reading_caret/reading_caret_geometry.dart‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import 'package:characters/characters.dart';
22
import 'package:flutter/rendering.dart';
33

4-
/// A position in the paragraph that actually paints the reader's text.
5-
/// Keeping the text snapshot prevents a recycled list child from adopting an
6-
/// old caret. Affinity distinguishes the two visual sides of a wrapped line.
4+
/// A position in the rendered paragraph, with a text snapshot to reject reuse.
5+
/// Affinity distinguishes the visual sides of a wrapped line.
76
class ReadingCaretPosition {
87
ReadingCaretPosition(this.paragraph, this.position, {String? text})
98
: text = text ?? paragraph.text.toPlainText(),
@@ -44,10 +43,8 @@ class ReadingCaretPosition {
4443
: MatrixUtils.transformRect(paragraph.getTransformTo(null), rect);
4544
}
4645

47-
/// Selection dispatch uses a hit point, whereas a caret may sit exactly on
48-
/// the outside edge of an RTL paragraph. Only use an inset if the real
49-
/// paragraph still maps it to the same text offset and visual line. A blind
50-
/// clamp can select an adjacent paragraph or the other side of a wrap.
46+
/// Inset an edge hit point only if the paragraph maps it to the same offset
47+
/// and visual line; a blind clamp may choose another paragraph or wrap side.
5148
Offset? get selectionPoint {
5249
final rect = localRect;
5350
if (rect == null) return null;

‎test/text_book/view/text_book_screen_actions_test.dart‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,8 @@ void main() {
277277
expect(harness.selectedText, 'ש');
278278
expect((harness.bloc.state as TextBookLoaded).selectedTextForNote, 'ש');
279279
await harness.key(LogicalKeyboardKey.arrowDown);
280-
// Refresh is unavailable for this official book. Its configured arrow
281-
// remains claimed. There is no CustomFoldersBloc in this fixture, so
282-
// entering the rescan path would also fail its required provider lookup.
280+
// An unavailable refresh still owns its configured arrow; entering rescan
281+
// would also fail because this fixture has no CustomFoldersBloc.
283282
expect(tester.takeException(), isNull);
284283
expect(harness.selectedText, 'ש');
285284
expect((harness.bloc.state as TextBookLoaded).fontSize, font + 3);
@@ -477,9 +476,8 @@ void main() {
477476
);
478477
await _caretUntil(tester, () => harness.caret != null);
479478
expect(harness.caret!.top, closeTo(before.top, 0.5));
480-
// The same native clear is deferred while the real reader has a
481-
// primary pointer down. Cancellation releases that transaction
482-
// without scheduling an unrelated delayed single-tap action.
479+
// Cancellation releases a deferred native clear during a primary
480+
// pointer transaction without scheduling a delayed single tap.
483481
await harness.key(LogicalKeyboardKey.home);
484482
await harness.key(LogicalKeyboardKey.end, shift: true);
485483
expect(harness.selectedText, 'שורה א');

0 commit comments

Comments
 (0)