[FEAT] Add TaskConversionReaction for live checkbox creation#15
Open
rutvik-at-pieces wants to merge 2 commits into
Open
[FEAT] Add TaskConversionReaction for live checkbox creation#15rutvik-at-pieces wants to merge 2 commits into
rutvik-at-pieces wants to merge 2 commits into
Conversation
…pe to create a checkbox in the document
There was a problem hiding this comment.
Pull request overview
Adds a new paragraph prefix conversion reaction intended to convert a ParagraphNode into a TaskNode when the user types a task checkbox prefix at the start of a paragraph.
Changes:
- Introduces
TaskConversionReactionto detect a task prefix and replace aParagraphNodewith aTaskNode. - Adds configurability via
allowConversionOfNonEmptyParagraphsto control whether conversion triggers for non-empty paragraphs.
Comments suppressed due to low confidence (3)
super_editor/lib/src/default_editor/default_document_editor_reactions.dart:177
- The task prefix regex only matches
[]or[x], but the rest of the codebase serializes tasks using GitHub-style- [ ]/- [x](seelib/src/infrastructure/serialization/markdown/document_to_markdown_serializer.dart:351-378). Consider also matching[ ](and allowing uppercaseX) so users can type the common task syntax.
static final _taskInEmptyParagraphPattern = RegExp(r'^\s*\[x?\]\s+$');
static final _taskInNonEmptyParagraphPattern = RegExp(r'^\s*\[x?\]\s+');
super_editor/lib/src/default_editor/default_document_editor_reactions.dart:197
match.contains('x')is case-sensitive, so[X]won't be treated as complete (especially if the regex is made case-insensitive). Prefer an explicit, case-insensitive check for the[x]token.
final isComplete = match.contains('x');
super_editor/lib/src/default_editor/default_document_editor_reactions.dart:194
- This new conversion behavior should have widget test coverage alongside the other paragraph conversions in
test/super_editor/text_entry/paragraph_conversions_test.dart(e.g., for[]/[x]/[ ]in empty and non-empty paragraphs, and forallowConversionOfNonEmptyParagraphs: false).
void onPrefixMatched(
EditContext editContext,
RequestDispatcher requestDispatcher,
List<EditEvent> changeList,
ParagraphNode paragraph,
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
TaskConversionReactionthat converts aParagraphNodeinto aTaskNodewhen the user types[]or[x]at the start of a paragraph — matching the existing pattern used for unordered (-) and ordered (1.) list item conversions.Changes
TaskConversionReactionclass indefault_document_editor_reactions.dartParagraphPrefixConversionReaction(same base asUnorderedListItemConversionReaction)[](incomplete task) and[x](complete task) prefixesParagraphNodewith aTaskNode, preserving remaining text contentisCompletebased on whetherxis present in the prefixallowConversionOfNonEmptyParagraphsflag (defaults totrue)Motivation
Previously, there was no way to create a
TaskNodeby typing in the editor — users could only get checkboxes from deserialized markdown. This brings task creation UX in line with how list items already work (type a prefix, get a converted node).Related PRs