From 0afc3236c2d773791de05d457367c73faf113ca0 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 15 Feb 2022 08:02:07 +0100 Subject: fix: indicator of the task list. See #2018. Use tiptap TaskList and TaskItem. Markdown-it happily mixes tasks and bullet points in the same list. Tiptap lists are strictly separated. Split bullet and tasks into BulletList and TaskList in markdown-io. Just like this will turn into three different lists: * one - two + three This will now also turn into three different lists with the middle one being a task list: * first list * [ ] todo * [x] done * third list Signed-off-by: Max --- cypress/fixtures/ListItem.md | 97 ++++++++++++++++++++++++++++------- cypress/integration/ListItem.spec.js | 27 +++++++--- cypress/integration/workspace.spec.js | 19 +++++++ 3 files changed, 117 insertions(+), 26 deletions(-) (limited to 'cypress') diff --git a/cypress/fixtures/ListItem.md b/cypress/fixtures/ListItem.md index 97ff201f8..7e59ca711 100644 --- a/cypress/fixtures/ListItem.md +++ b/cypress/fixtures/ListItem.md @@ -1,62 +1,121 @@ -## creates todo lists +## Keeps homogeneous lists together -* todo\_item +* foo +* bar + +1. one +2. two + +* [ ] todo +* [x] done + +--- + +* foo +* bar + +1. one +2. two + +* [ ] todo +* [x] done + +## Splits mixed lists with empty lines + +* foo +* bar +* [ ] todo +* [x] done +1. one +2. two + +--- + +* foo +* bar + +* [ ] todo +* [x] done + +1. one +2. two + +## bullet list to task list + +* toggleTaskList +* keep --- -* [ ] todo\_item +* [ ] did toggleTaskList + +* keep -## removes the list when toggling todo off +## bullet list to ordered list -* [ ] todo\_item +* toggleOrderedList +* keep --- -todo\_item +1. did toggleOrderedList +2. keep + + +## removes the list when toggling task off + +* [ ] toggleTaskList + +--- + +did toggleTaskList ## creates a bullet list -bulletListItem +toggleBulletList --- -* bulletListItem +* did toggleBulletList -## only toggles one list item +## Splits bullet list when turning one item into task -* todo\_item +* toggleTaskList * not todo --- -* [ ] todo\_item +* [ ] did toggleTaskList + * not todo ## toggles two list items separately -* todo\_item +* toggleTaskList * not todo -* todo\_item +* toggleTaskList --- -* [ ] todo\_item +* [ ] did toggleTaskList + * not todo -* [ ] todo\_item -## toggle off todo list item should turn it into normal list item +* [ ] did toggleTaskList + +## toggle off task list item should turn it into normal list item * not todo -* [ ] todo\_item +* [ ] toggleTaskList --- * not todo -todo\_item +did toggleTaskList --- * not todo -* todo\_item +* toggleTaskList diff --git a/cypress/integration/ListItem.spec.js b/cypress/integration/ListItem.spec.js index dd0c95a87..c45a8b2cc 100644 --- a/cypress/integration/ListItem.spec.js +++ b/cypress/integration/ListItem.spec.js @@ -1,5 +1,8 @@ +import OrderedList from '@tiptap/extension-ordered-list' +import ListItem from '@tiptap/extension-list-item' +import TaskList from './../../src/nodes/TaskList' +import TaskItem from './../../src/nodes/TaskItem' import BulletList from './../../src/nodes/BulletList' -import ListItem from './../../src/nodes/ListItem' import Markdown from './../../src/extensions/Markdown' import markdownit from './../../src/markdownit' import { createMarkdownSerializer } from './../../src/extensions/Markdown'; @@ -11,7 +14,14 @@ describe('ListItem extension integrated in the editor', () => { const editor = createEditor({ content: '', - extensions: [Markdown, BulletList, ListItem], + extensions: [ + Markdown, + BulletList, + OrderedList, + ListItem, + TaskList, + TaskItem, + ], }) for (const spec of testData.split(/#+\s+/)){ @@ -36,18 +46,21 @@ describe('ListItem extension integrated in the editor', () => { } function runCommands() { - for (const { node, pos } of findCommands()) { - const command = node.text + let found + while (found = findCommand()) { + const { node, pos } = found + const name = node.text editor.commands.setTextSelection(pos) - editor.commands[command]() + editor.commands[name]() + editor.commands.insertContent('did ') } } - function findCommands() { + function findCommand() { const doc = editor.state.doc return findChildren(doc, child => { return child.isText && editor.commands.hasOwnProperty(child.text) - }) + })[0] } function expectMarkdown(markdown) { diff --git a/cypress/integration/workspace.spec.js b/cypress/integration/workspace.spec.js index efa3e5953..01829cd7c 100644 --- a/cypress/integration/workspace.spec.js +++ b/cypress/integration/workspace.spec.js @@ -104,6 +104,25 @@ describe('Workspace', function() { }) }) + it('creates lists', function() { + openWorkspace() + .type('List me') + .type('{selectall}') + ;[ + ['ul', 'ul'], + ['ol', 'ol'], + ['checkmark', 'ul[data-type="taskList"]'], + ].forEach(([button, tag]) => { + menuButton(button) + .click() + .should('have.class', 'is-active') + cy.get(`.ProseMirror ${tag}`).should('contain', 'List me') + menuButton(button) + .click() + .should('not.have.class', 'is-active') + }) + }) + it('takes README.md into account', function() { cy.uploadFile('test.md', 'text/markdown', `${Cypress.currentTest.title}/README.md`) cy.reload() -- cgit v1.2.3