Skip to content

Undo/redo should coalesce changes correctly by platform #99186

@justinmc

Description

@justinmc

Support for text undo/redo was added in #96968, but the coalescing isn't exactly correct on each platform. In that PR, we used a simple time-based throttle on all platforms (code), but the actual behavior is much more nuanced and slightly different on each platform (some analysis). Ideally, Flutter should perfectly match the behavior of each platform.

By coalescing, I mean where the editor separates one undoable chunk of text from the next.

To reproduce

  1. Run any app with a text input, such as the one given below.
  2. Type one or two lines of text. Enough that it takes you a few seconds to finish.
  3. Press ctrl/cmd + Z to undo a few times and notice how the text is grouped.

Expected behavior: The amount of text that is undone at each step exactly matches the native platform.
Actual behavior: It's likely to be off on all platforms.

Code
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Flutter Demo'),
        ),
        body: const Center(
          child: TextField(),
        ),
      ),
    );
  }
}

TODO

  • Figure out what the exact algorithms are for coalescing text input on Windows, Mac, and Linux.

If your app is negatively affected by this, please give a 👍 and maybe leave a comment to help us gauge how this is affecting people.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: desktopRunning on desktopa: text inputEntering text in a text field or keyboard related problemsf: material designflutter/packages/flutter/material repository.found in release: 2.11Found to occur in 2.11frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-text-inputOwned by Text Input teamtriaged-text-inputTriaged by Text Input team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions