Skip to content

Document.getPlainText(index, len) has a weird bug where it may repeat the document content to satisfy the specified length in parameter. #2704

@HP1324

Description

@HP1324

Have you checked for an existing issue?

Flutter Quill Version

11.5.0

Steps to Reproduce

Use Document.getPlainText(0, <any_length>) in any setting and print the returned result to the console.

Expected results

Document.getPlainText(index, len) should return the available content only, if the content is less than len then it should not repeat the same content.

Actual results

Document.getPlainText(index, len) has a weird bug where it may
repeat the document content to satisfy the specified length in parameter.
So if the document's length is less than the specified len parameter, we see this behavior.

Example:
If the actual document text is: "This is string 1"
and we request a length of 50, the method may return:

"This is string 1\nThis is string 1\n..."

Currenty I did the following to avoid this issue, split until the first newline and return the first string in the returned list.

String _getInitialContentFromController(QuillController controller) {
    final content = controller.document.getPlainText(0, 50).trim();
    return content.split('\n').first;
  }

Additional Context

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