Skip to content

Commit

Permalink
Merge pull request #9139 from ckeditor/i/8877
Browse files Browse the repository at this point in the history
Feature (autoformat): Typing `[x]` will insert a checked todo list item. Closes #8877.
  • Loading branch information
mlewand authored Mar 12, 2021
2 parents 1cf180e + 228d21b commit 18be7da
Show file tree
Hide file tree
Showing 3 changed files with 219 additions and 159 deletions.
8 changes: 8 additions & 0 deletions packages/ckeditor5-autoformat/src/autoformat.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default class Autoformat extends Plugin {
* - `* ` or `- ` – A paragraph will be changed to a bulleted list.
* - `1. ` or `1) ` – A paragraph will be changed to a numbered list ("1" can be any digit or a list of digits).
* - `[] ` or `[ ] ` – A paragraph will be changed to a to-do list.
* - `[x] ` or `[ x ] ` – A paragraph will be changed to a checked to-do list.
*
* @private
*/
Expand All @@ -64,6 +65,13 @@ export default class Autoformat extends Plugin {
if ( commands.get( 'todoList' ) ) {
blockAutoformatEditing( this.editor, this, /^\[\s?\]\s$/, 'todoList' );
}

if ( commands.get( 'checkTodoList' ) ) {
blockAutoformatEditing( this.editor, this, /^\[\s?x\s?\]\s$/, () => {
this.editor.execute( 'todoList' );
this.editor.execute( 'checkTodoList' );
} );
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/ckeditor5-autoformat/src/blockautoformatediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ export default function blockAutoformatEditing( editor, plugin, pattern, callbac
return;
}

// Only lists should be formatted inside the lists.
// Only list commands and custom callbacks can be applied inside a list.
if ( blockToFormat.is( 'element', 'listItem' ) &&
typeof callbackOrCommand !== 'function' &&
![ 'numberedList', 'bulletedList', 'todoList' ].includes( callbackOrCommand )
) {
return;
Expand Down
Loading

0 comments on commit 18be7da

Please sign in to comment.