-
-
Notifications
You must be signed in to change notification settings - Fork 670
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
editor: fix backspace deleting formatting in list item (#6712)
* fix hitting backspace inside the second (or next) p in list item deleted the formatting of the entire list item Signed-off-by: 01zulfi <[email protected]>
- Loading branch information
Showing
4 changed files
with
172 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
7 changes: 7 additions & 0 deletions
7
packages/editor/src/extensions/list-item/tests/__snapshots__/list-item.test.ts.snap
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`hitting backspace at the start of first list item 1`] = `"<div><div contenteditable="true" translate="no" class="tiptap ProseMirror" tabindex="0"><p>item1</p><ul><li><p>item2</p></li></ul></div></div>"`; | ||
|
||
exports[`hitting backspace at the start of the second (or next) list item 1`] = `"<div><div contenteditable="true" translate="no" class="tiptap ProseMirror" tabindex="0"><ul><li><p>item1item2</p></li></ul></div></div>"`; | ||
|
||
exports[`hitting backspace at the start of the second (or next) paragraph inside the list item 1`] = `"<div><div contenteditable="true" translate="no" class="tiptap ProseMirror" tabindex="0"><ul><li><p>item 1item 2</p></li></ul></div></div>"`; |
138 changes: 138 additions & 0 deletions
138
packages/editor/src/extensions/list-item/tests/list-item.test.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* | ||
This file is part of the Notesnook project (https://notesnook.com/) | ||
Copyright (C) 2023 Streetwriters (Private) Limited | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import ListKeymap from "@tiptap/extension-list-keymap"; | ||
import { expect, test } from "vitest"; | ||
import { createEditor, h, li, p, ul } from "../../../../test-utils/index.js"; | ||
import BulletList from "../../bullet-list/index.js"; | ||
import CheckListItem from "../../check-list-item/index.js"; | ||
import CheckList from "../../check-list/index.js"; | ||
import OrderedList from "../../ordered-list/index.js"; | ||
import { OutlineListItem } from "../../outline-list-item/index.js"; | ||
import { OutlineList } from "../../outline-list/index.js"; | ||
import { TaskItemNode } from "../../task-item/index.js"; | ||
import { TaskListNode } from "../../task-list/index.js"; | ||
import { ListItem } from "../index.js"; | ||
|
||
test("hitting backspace at the start of first list item", async () => { | ||
const el = ul([li([p(["item1"])]), li([p(["item2"])])]); | ||
const editorElement = h("div"); | ||
const editor = createEditor({ | ||
element: editorElement, | ||
initialContent: el.outerHTML, | ||
extensions: { | ||
listItem: ListItem, | ||
listKeymap: ListKeymap.configure({ | ||
listTypes: [ | ||
{ | ||
itemName: ListItem.name, | ||
wrapperNames: [BulletList.name, OrderedList.name] | ||
}, | ||
{ | ||
itemName: TaskItemNode.name, | ||
wrapperNames: [TaskListNode.name] | ||
}, | ||
{ | ||
itemName: OutlineListItem.name, | ||
wrapperNames: [OutlineList.name] | ||
}, | ||
{ | ||
itemName: CheckListItem.name, | ||
wrapperNames: [CheckList.name] | ||
} | ||
] | ||
}) | ||
} | ||
}); | ||
const event = new KeyboardEvent("keydown", { key: "Backspace" }); | ||
editor.editor.view.dom.dispatchEvent(event); | ||
expect(editorElement.outerHTML).toMatchSnapshot(); | ||
}); | ||
|
||
test("hitting backspace at the start of the second (or next) list item", async () => { | ||
const el = ul([li([p(["item1"])]), li([p(["item2"])])]); | ||
const editorElement = h("div"); | ||
const editor = createEditor({ | ||
element: editorElement, | ||
initialContent: el.outerHTML, | ||
extensions: { | ||
listItem: ListItem, | ||
listKeymap: ListKeymap.configure({ | ||
listTypes: [ | ||
{ | ||
itemName: ListItem.name, | ||
wrapperNames: [BulletList.name, OrderedList.name] | ||
}, | ||
{ | ||
itemName: TaskItemNode.name, | ||
wrapperNames: [TaskListNode.name] | ||
}, | ||
{ | ||
itemName: OutlineListItem.name, | ||
wrapperNames: [OutlineList.name] | ||
}, | ||
{ | ||
itemName: CheckListItem.name, | ||
wrapperNames: [CheckList.name] | ||
} | ||
] | ||
}) | ||
} | ||
}); | ||
editor.editor.commands.setTextSelection(12); | ||
const event = new KeyboardEvent("keydown", { key: "Backspace" }); | ||
editor.editor.view.dom.dispatchEvent(event); | ||
expect(editorElement.outerHTML).toMatchSnapshot(); | ||
}); | ||
|
||
test("hitting backspace at the start of the second (or next) paragraph inside the list item", async () => { | ||
const el = ul([li([p(["item 1"]), p(["item 2"])])]).outerHTML; | ||
const editorElement = h("div"); | ||
const editor = createEditor({ | ||
element: editorElement, | ||
initialContent: el, | ||
extensions: { | ||
listItem: ListItem, | ||
listKeymap: ListKeymap.configure({ | ||
listTypes: [ | ||
{ | ||
itemName: ListItem.name, | ||
wrapperNames: [BulletList.name, OrderedList.name] | ||
}, | ||
{ | ||
itemName: TaskItemNode.name, | ||
wrapperNames: [TaskListNode.name] | ||
}, | ||
{ | ||
itemName: OutlineListItem.name, | ||
wrapperNames: [OutlineList.name] | ||
}, | ||
{ | ||
itemName: CheckListItem.name, | ||
wrapperNames: [CheckList.name] | ||
} | ||
] | ||
}) | ||
} | ||
}); | ||
editor.editor.commands.setTextSelection(11); | ||
const event = new KeyboardEvent("keydown", { key: "Backspace" }); | ||
editor.editor.view.dom.dispatchEvent(event); | ||
expect(editorElement.outerHTML).toMatchSnapshot(); | ||
}); |
This file contains 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