Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

editor: update snapshots

Abdullah Atta9b6a6de41576
diff --git a/packages/editor/src/extensions/task-list/task-list.ts b/packages/editor/src/extensions/task-list/task-list.ts
index 2441277ed..cbf3a2abb 100644
--- a/packages/editor/src/extensions/task-list/task-list.ts
+++ b/packages/editor/src/extensions/task-list/task-list.ts
@@ -31,11 +31,11 @@ import { inputRegex } from "@tiptap/extension-task-item";
import { dropPoint } from "prosemirror-transform";
import {
findChildrenByType,
- getChangedNodes,
getDeletedNodes,
getParentAttributes,
hasSameAttributes,
- findParentNodeClosestToPos
+ findParentNodeClosestToPos,
+ getExactChangedNodes
} from "../../utils/prosemirror";
import { countCheckedItems, findRootTaskList } from "./utils";
import { Node as ProsemirrorNode } from "@tiptap/pm/model";
@@ -249,9 +249,10 @@ export const TaskListNode = TaskList.extend({
appendTransaction(transactions, _oldState, newState) {
if (!transactions[0].docChanged) return;
- const changedNodes = getChangedNodes(transactions[0], {
- predicate: (node) => node.type.name === TaskItemNode.name
- });
+ const changedNodes = getExactChangedNodes(
+ transactions[0],
+ (node) => node.type.name === TaskItemNode.name
+ );
const deletedNodes = getDeletedNodes(
transactions[0],
(node) => node.type.name === TaskList.name
@@ -272,7 +273,6 @@ export const TaskListNode = TaskList.extend({
roots.add(root);
const stats = countCheckedItems(root.node);
- console.log(stats);
tr.setNodeMarkup(root.pos, undefined, { stats });
changeCount++;
}
diff --git a/packages/editor/src/extensions/task-list/tests/__snapshots__/task-list.test.ts.snap b/packages/editor/src/extensions/task-list/tests/__snapshots__/task-list.test.ts.snap
index a1e776e10..41bad3ff4 100644
--- a/packages/editor/src/extensions/task-list/tests/__snapshots__/task-list.test.ts.snap
+++ b/packages/editor/src/extensions/task-list/tests/__snapshots__/task-list.test.ts.snap
@@ -5,6 +5,10 @@ exports[`delete checked items in a nested task list 1`] = `
{
"attrs": {
"readonly": false,
+ "stats": {
+ "checked": 0,
+ "total": 6,
+ },
"title": null,
},
"content": [
@@ -42,6 +46,10 @@ exports[`delete checked items in a nested task list 1`] = `
{
"attrs": {
"readonly": false,
+ "stats": {
+ "checked": 0,
+ "total": 0,
+ },
"title": null,
},
"content": [
@@ -79,6 +87,10 @@ exports[`delete checked items in a nested task list 1`] = `
{
"attrs": {
"readonly": false,
+ "stats": {
+ "checked": 0,
+ "total": 0,
+ },
"title": null,
},
"content": [
@@ -99,6 +111,10 @@ exports[`delete checked items in a nested task list 1`] = `
{
"attrs": {
"readonly": false,
+ "stats": {
+ "checked": 0,
+ "total": 0,
+ },
"title": null,
},
"content": [
@@ -148,6 +164,10 @@ exports[`delete checked items in a task list 1`] = `
{
"attrs": {
"readonly": false,
+ "stats": {
+ "checked": 0,
+ "total": 1,
+ },
"title": null,
},
"content": [
@@ -179,6 +199,10 @@ exports[`sort checked items to the bottom of the task list 1`] = `
{
"attrs": {
"readonly": false,
+ "stats": {
+ "checked": 6,
+ "total": 12,
+ },
"title": null,
},
"content": [
@@ -216,6 +240,10 @@ exports[`sort checked items to the bottom of the task list 1`] = `
{
"attrs": {
"readonly": false,
+ "stats": {
+ "checked": 0,
+ "total": 0,
+ },
"title": null,
},
"content": [
@@ -253,6 +281,10 @@ exports[`sort checked items to the bottom of the task list 1`] = `
{
"attrs": {
"readonly": false,
+ "stats": {
+ "checked": 0,
+ "total": 0,
+ },
"title": null,
},
"content": [
@@ -273,6 +305,10 @@ exports[`sort checked items to the bottom of the task list 1`] = `
{
"attrs": {
"readonly": false,
+ "stats": {
+ "checked": 0,
+ "total": 0,
+ },
"title": null,
},
"content": [
diff --git a/packages/editor/src/utils/prosemirror.ts b/packages/editor/src/utils/prosemirror.ts
index 7b3590afb..a3edbab3d 100644
--- a/packages/editor/src/utils/prosemirror.ts
+++ b/packages/editor/src/utils/prosemirror.ts
@@ -309,6 +309,33 @@ export function getChangedNodes(
const { descend = false, predicate } = options;
const nodeRange = getChangedNodeRanges(tr);
+ // The container for the nodes which have been added..
+ const nodes: NodeWithPos[] = [];
+ for (const range of nodeRange) {
+ const { start, end } = range;
+
+ // Find all the nodes between the provided node range.
+ tr.doc.nodesBetween(start, end, (node, pos) => {
+ // Check wether this is a node that should be added.
+ const shouldAdd = !predicate || predicate(node, start, range);
+
+ if (shouldAdd && nodes.every((n) => n.pos !== pos)) {
+ nodes.push({ node, pos });
+ }
+
+ return descend;
+ });
+ }
+
+ return nodes;
+}
+
+export function getExactChangedNodes(
+ tr: Transaction,
+ predicate?: (node: ProsemirrorNode, pos: number, range: NodeRange) => boolean
+): NodeWithPos[] {
+ const nodeRange = getChangedNodeRanges(tr);
+
// The container for the nodes which have been added..
const nodes: NodeWithPos[] = [];
for (const range of nodeRange) {