[iOS] Scribble: handwriting started in the empty area below the text of a multiline TextField is inserted mid-text
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 35/100
Rechercherichtung
Start in onScribbleFocus in packages/flutter/lib/src/widgets/editable_text.dart, which calls renderEditable.selectPositionAt with the handwriting start point; compare with TextPainter.getPositionForOffset, which returns the nearest x on the last line for points below the text. The reproduction is the widget test in test/scribble_focus_test.dart, which sends requestElementsInRect and focusElement and expects the caret at offset 18 rather than 1. Done when that test passes and the caret lands at the end of the text for points below the last line.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Steps to reproduce
Device: iPad Pro (12.9-inch) (4th generation), iPad OS 27.2.1, Apple Pencil, with Scribble turned on (Settings > Apple Pencil > Scribble).
- Run
main.dartfrom the code sample on the iPad. It is one multilineTextFieldthat fills the page. - With the Pencil, write
I went tonear the top of the field. It is converted and appears at the top left. - Continue the sentence the way one does on paper: write
the parkon the next handwritten line, that is, below the converted text and starting near the left edge of the field.
Without a device: run the widget test from the code sample. It sends the two messages the iOS embedder sends for step 3 (TextInputClient.requestElementsInRect, then TextInputClient.focusElement with a point below the text) and checks where the caret is.
What was actually run: steps 2 and 3 were observed on a physical iPad with an Apple Pencil in a production app whose answer field has this shape (a page-filling TextField with maxLines: null). main.dart below is that field reduced to a sample and has not itself been run on a device. The widget test was run on Flutter 3.50.1 and fails as shown under "Actual results".
Expected results
the park is appended: I went to the park.
The empty area below the last line has no text under it, so the end of the text is the only reasonable insertion point there. The iOS embedder already encodes this rule: in FlutterTextInputPlugin.mm, closestPositionToPoint: resolves a point below the bottom line to the far end of that line ("when the point is below the bottom line of text, we want to select the whole line of text, so we mark the farthest rect as closest").
Actual results
the park is inserted inside I went to, at the horizontal position of the pen on the last line. Writing immediately to the right of the converted text works. So every handwritten line after the first one lands in the middle of the sentence, and the user has to rewrite it.
Cause, as far as the source shows (the same on 3.50.1 and on master at 43150a886d):
_ScribbleFocusableState.onScribbleFocusinpackages/flutter/lib/src/widgets/editable_text.dartcallsrenderEditable.selectPositionAt(from: offset, cause: SelectionChangedCause.stylusHandwriting)with the point where the handwriting started. For a point below the last line,TextPainter.getPositionForOffsetreturns the position on the last line with the nearest x, not the end of the text.- The embedder's
insertText:inserts at that selection. It also sets_scribbleFocusStatusback to unfocused after every insertion, sofocusElementruns again and moves the caret for every handwritten chunk, not only the first.
A possible fix: onScribbleFocus places the caret at the end of the text when the point is below the last line, matching the embedder's closestPositionToPoint: rule.
The widget test fails with:
Expected: TextSelection:<TextSelection.collapsed(offset: 18, affinity: TextAffinity.downstream, isDirectional: false)>
Actual: TextSelection:<TextSelection.collapsed(offset: 1, affinity: TextAffinity.upstream, isDirectional: false)>
Code sample
Code sample
lib/main.dart
import 'package:flutter/material.dart';
void main() => runApp(const MaterialApp(home: ScribbleRepro()));
class ScribbleRepro extends StatelessWidget {
const ScribbleRepro({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Scribble caret repro')),
body: const TextField(
expands: true,
maxLines: null,
textAlignVertical: TextAlignVertical.top,
),
);
}
}
test/scribble_focus_test.dart
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
/// Delivers a message on the text input channel as if it came from the iOS
/// embedder, and returns the decoded reply.
Future<dynamic> fromEmbedder(WidgetTester tester, String method, List<dynamic> args) async {
dynamic reply;
await tester.binding.defaultBinaryMessenger.handlePlatformMessage(
SystemChannels.textInput.name,
SystemChannels.textInput.codec.encodeMethodCall(MethodCall(method, args)),
(ByteData? data) {
if (data != null) {
reply = SystemChannels.textInput.codec.decodeEnvelope(data);
}
},
);
await tester.pump();
return reply;
}
void main() {
testWidgets('Scribble focus below the text keeps the caret at the end', (WidgetTester tester) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
const String text = 'I went to the park';
final TextEditingController controller = TextEditingController(text: text);
addTearDown(controller.dispose);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: TextField(
controller: controller,
expands: true,
maxLines: null,
textAlignVertical: TextAlignVertical.top,
),
),
),
);
final Rect field = tester.getRect(find.byType(EditableText));
// What UIIndirectScribbleInteraction asks first: which elements are here?
final List<dynamic> elements =
await fromEmbedder(tester, 'TextInputClient.requestElementsInRect', <dynamic>[
field.left,
field.top,
field.width,
field.height,
])
as List<dynamic>;
final String elementId = (elements.single as List<dynamic>).first as String;
// The pencil starts the next handwritten line below the existing text, at
// the left margin: 200 px under the first line, 10 px from the left edge.
await fromEmbedder(tester, 'TextInputClient.focusElement', <dynamic>[
elementId,
field.left + 10,
field.top + 200,
]);
debugDefaultTargetPlatformOverride = null;
// Fails: the caret is at offset 1 ("I| went to the park"), so the embedder's
// insertText puts the next handwritten words in the middle of the sentence.
expect(controller.selection, const TextSelection.collapsed(offset: text.length));
});
}
Screenshots or Video
No response
Logs
No response
Flutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.50.1, on macOS 27.2.1 26B131 darwin-arm64, locale en-US) [823ms]
• Flutter version 3.50.1 on channel stable at /Users/runner/fvm/versions/3.50.1
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision ae9b586f34 (9 days ago), 2026-11-18 17:01:07 -0800
• Engine revision 4d35714800
• Dart version 3.14.0
• DevTools version 2.61.0
• Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, enable-record-use, enable-swift-package-manager, omit-legacy-version-file, no-enable-lldb-debugging, enable-uiscene-migration
[✗] Android toolchain - develop for Android devices [775ms]
✗ Unable to locate Android SDK.
[✓] Xcode - develop for iOS and macOS (Xcode 27.1) [2.2s]
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 27A9275
• CocoaPods version 1.16.2
[✓] Chrome - develop for the web [7ms]
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Connected device (2 available) [9.3s]
• macOS (desktop) • macos • darwin-arm64 • macOS 27.2.1 26B131 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 158.0.8127.88
[✓] Network resources [474ms]
• All expected network resources are available.
! Doctor found issues in 1 category.
- Vorherrschende Sprache
- Dart
- Sterne
- 182k
- Forks
- 32k
- Ø Merge
- 1 T. 23 Std.
- Gemergte PRs (30 T.)
- 352
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus flutter/flutter
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
RenderListWheelViewport creates a new OpacityLayer on every paint and keeps it after it stops using itEvtl. vergeben @leoafarias hat das vor 2 Tagen übernommen. Offena: tests f: scrolling found in release: 3.50 framework has reproducible steps team-framework
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
a: text input engine found in release: 3.50 fyi-text-input platform-ios team-ios workaround available
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
flutter/flutter#197531 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
in triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
flutter/flutter#197514 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in flutter/flutter
Ähnliche Issues
-
Study Button croppedOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
lichess-org/mobile#4119 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 76/100
Nicolas11Leon/Tunner#278 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
ImranR98/apps.obtainium.imranr.dev#2058 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 6 Tagen