Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When copying a list, the last item does not retain the list formatting #360

Open
simonbengtsson opened this issue May 29, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@simonbengtsson
Copy link
Contributor

Steps to Reproduce

  1. Write a couple of bullet points in editor
  2. Copy all bullet points
  3. Log the delta obtained in a clipboard manager and observe that all bullet points except for the last one has a new line with the "ul" attribute defined which means this will not be treated as a bullet item when pasted somewhere later.

Environment

  • OS: macos
  • Flutter version: 3.22.1
  • Fleather version: master

Logs

Document delta:

  • insert⟨ hello ⟩
  • insert⟨ ⏎ ⟩ + {block: ul}
  • insert⟨ world ⟩
  • insert⟨ ⏎ ⟩ + {block: ul}

FleatherClipboardData delta:

  • insert⟨ hello ⟩
  • insert⟨ ⏎ ⟩ + {block: ul}
  • insert⟨ world ⟩
@simonbengtsson simonbengtsson changed the title When copying a list (ordered or unordered) the last item does not get formatting in the clipboard manager delta When copying a list the last item does ont retain the list formatting May 29, 2024
@simonbengtsson simonbengtsson changed the title When copying a list the last item does ont retain the list formatting When copying a list, the last item does ont retain the list formatting May 29, 2024
@simonbengtsson simonbengtsson changed the title When copying a list, the last item does ont retain the list formatting When copying a list, the last item does not retain the list formatting May 29, 2024
@simonbengtsson
Copy link
Contributor Author

simonbengtsson commented May 29, 2024

In addition to the above issue there is also a minor issue that pasting adds an extra new line when the last item is a list item. Except for these issues the following class works for copy pasting all types of text formatting (lists, bold etc) both inside fleather editor and from/to other editors such as Notion.

class SimpleMarkdownClipboardManager extends ClipboardManager {
  const SimpleMarkdownClipboardManager();

  @override
  Future<void> setData(FleatherClipboardData data) async {
    final plainText = data.plainText;
    final clipboardDelta = data.delta;
    if (clipboardDelta != null && clipboardDelta.length > 0) {
      // Add new line since required by ParchmentDocument.fromDelta
      final delta = clipboardDelta.concat(Delta()..insert('\n'));
      final doc = ParchmentDocument.fromDelta(delta);
      final markdown = parchmentMarkdown.encode(doc);
      await Clipboard.setData(ClipboardData(text: markdown));
    } else if (plainText != null) {
      await Clipboard.setData(ClipboardData(text: plainText));
    }
  }

  @override
  Future<FleatherClipboardData?> getData() async {
    final data = await Clipboard.getData(Clipboard.kTextPlain);
    final markdown = data?.text ?? '';
    
    // Many editors such as Notion use "- " as plaint text format for unordered lists
    markdown = markdown.replaceAll('\n- ', '\n* ');
    
    final doc = parchmentMarkdown.decode(markdown);
    return FleatherClipboardData(delta: doc.toDelta());
  }
}

@simonbengtsson
Copy link
Contributor Author

simonbengtsson commented May 30, 2024

After diving into the "extra new line when pasting bullet list" issue mentioned above I realized it is actually reproducible in the quilljs playground as well. And they have an issue describing it here: slab/quill#1483.

@amantoux amantoux added the bug Something isn't working label Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants