super_editor icon indicating copy to clipboard operation
super_editor copied to clipboard

Android interactor assumes an offset will map to a document position

Open jellynoone opened this issue 1 year ago • 0 comments

Package Version stable

To Reproduce Steps to reproduce the behavior:

  1. Run the code below on Android
  2. Click on text
  3. Attempt to scroll by dragging the horizontal white space
  4. See error

Minimal Reproduction Code

Minimal, Runnable Code Sample
import 'package:flutter/material.dart';
import 'package:super_editor/super_editor.dart';

void main() {
runApp(const MainApp());
}

class MainApp extends StatefulWidget {
const MainApp({super.key});

@override
State<MainApp> createState() => _MainAppState();
}

class _MainAppState extends State<MainApp> {
final _document = MutableDocument(nodes: [
  for (var i = 0; i < 2; i++)
    ParagraphNode(
      id: Editor.createNodeId(),
      text: AttributedText('Some random text.'),
    ),
]);
final _composer = MutableDocumentComposer();
late final _editor = createDefaultDocumentEditor(
  composer: _composer,
  document: _document,
);

@override
void dispose() {
  _editor.dispose();
  _document.dispose();
  _composer.dispose();
  super.dispose();
}

@override
Widget build(BuildContext context) {
  return MaterialApp(
    home: Scaffold(
      body: SafeArea(
        child: SuperEditor(
          stylesheet: Stylesheet(
            rules: defaultStylesheet.rules,
            documentPadding: EdgeInsets.symmetric(horizontal: 100),
            selectedTextColorStrategy:
                defaultStylesheet.selectedTextColorStrategy,
            inlineTextStyler: defaultStylesheet.inlineTextStyler,
          ),
          editor: _editor,
          document: _document,
          composer: _composer,
        ),
      ),
    ),
  );
}
}

Actual behavior An error occurs due to the pointer offset not mapping to any document position and the interactor assuming it does. The error happens at: https://github.com/superlistapp/super_editor/blob/ced4413f515525cc422c2072172e2bc332069152/super_editor/lib/src/default_editor/document_gestures_touch_android.dart#L981

Expected behavior There should be no error.

Platform Android

Flutter version Flutter 3.22.0 • channel stable • https://github.com/flutter/flutter.git Framework • revision 5dcb86f68f (5 days ago) • 2024-05-09 07:39:20 -0500 Engine • revision f6344b75dc Tools • Dart 3.4.0 • DevTools 2.34.3

jellynoone avatar May 14 '24 10:05 jellynoone