Skip to content

Undo operation breaks editor #2621

@PeterParker4339

Description

@PeterParker4339

Have you checked for an existing issue?

Flutter Quill Version

11.4.2

Steps to Reproduce

I just open this page:

import 'package:flutter/material.dart';
import 'package:flutter_quill/flutter_quill.dart' as quill;

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

  @override
  State<QuillTestPage> createState() => _QuillTestPageState();
}

class _QuillTestPageState extends State<QuillTestPage> {
  final _controller = quill.QuillController.basic();

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final toolbarConfig = quill.QuillSimpleToolbarConfig();
    final editorConfig = quill.QuillEditorConfig(
      placeholder: 'Type something...',
    );

    return Scaffold(
      appBar: AppBar(title: Text('Quill Test')),
      body: Column(
        children: [
          quill.QuillSimpleToolbar(
            controller: _controller,
            config: toolbarConfig,
          ),
          Expanded(
            child: quill.QuillEditor.basic(
              controller: _controller,
              config: editorConfig,
            ),
          ),
        ],
      ),
    );
  }
}

then write something in the editor, press undo and then try to continue writing.

Expected results

Undo should not cause error or bring editor to inconsistent state.

Actual results

Getting error while trying to continue editing with keyboard:
════════ Exception caught by services library ══════════════════════════════════ RangeError (end): Invalid value: Not in inclusive range 0..5: 19 ════════════════════════════════════════════════════════════════════════════════

Trying to paste something in the editor after this error works. It also resolves the RangeError but brings editor into inconsistent state, where it does not reflect cursors actual position: cursor gets updated visually but upon entering text it moves back to the last place before the error (see video attached).

Loading editor with some data before hand does not cause error after undo operation, but it brings the same cursor issue.

Additional Context

I am pretty new to flutter and dart in general, so maybe I am doing something wrong or not initializing the editor or page properly

Screenshots / Video demonstration
2025-07-29.15-38-08.mp4
Logs
════════ Exception caught by services library ══════════════════════════════════
RangeError (end): Invalid value: Not in inclusive range 0..15: 17
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by services library ══════════════════════════════════
RangeError (end): Invalid value: Not in inclusive range 0..15: 18
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by services library ══════════════════════════════════
RangeError (end): Invalid value: Not in inclusive range 0..15: 19
════════════════════════════════════════════════════════════════════════════════

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions