A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
editor: add button to clear completed tasks (#1336)
Muhammad Alif5a7beef1735
diff --git a/packages/editor/src/extensions/list-item/commands.ts b/packages/editor/src/extensions/list-item/commands.tsindex e030c47e9..87b8ba690 100644--- a/packages/editor/src/extensions/list-item/commands.ts+++ b/packages/editor/src/extensions/list-item/commands.ts@@ -42,7 +42,6 @@ export function onBackspacePressed(return false;const isEmpty = isListItemEmpty(type, editor.state);-if (isEmpty) {if (isFirstOfType(type, editor.state)) {const parentList = getListFromListItem(type, editor.state);@@ -100,7 +99,6 @@ const isFirstOfType = (type: NodeType, state: EditorState) => {if (!block) return false;const { pos } = block;const resolved = state.doc.resolve(pos);- console.log("isFirstOfType", resolved);return !resolved.nodeBefore;};diff --git a/packages/editor/src/extensions/task-list/component.tsx b/packages/editor/src/extensions/task-list/component.tsxindex 70e9007c7..8d46cd03a 100644--- a/packages/editor/src/extensions/task-list/component.tsx+++ b/packages/editor/src/extensions/task-list/component.tsx@@ -29,6 +29,8 @@ import { TaskItemNode } from "../task-item";import { TaskListAttributes } from "./task-list";import { findParentNodeOfTypeClosestToPos } from "prosemirror-utils";import { useIsMobile } from "../../toolbar/stores/toolbar-store";+import { ToolButton } from "../../toolbar/components/tool-button";+import TaskItem from "@tiptap/extension-task-item";export function TaskListComponent(props: ReactNodeViewProps<TaskListAttributes>@@ -170,7 +172,42 @@ export function TaskListComponent(}}/><Flex sx={{ flexShrink: 0, pr: 2 }}>- <Icon path={Icons.checkbox} size={15} color="fontTertiary" />+ <ToolButton+ toggled={false}+ title="Clear completed tasks"+ icon="clear"+ variant="small"+ onClick={() => {+ if (!editor.current) return;+ const pos = getPos();+ // we need to get a fresh instance of the task list instead+ // of using the one we got via props.+ const node = editor.current.state.doc.nodeAt(pos);+ if (!node) return;++ editor.current?.commands.command(({ tr }) => {+ const taskItems = findChildren(+ node,+ (n) => n.type.name === TaskItem.name && n.attrs.checked+ );+ const mapping = tr.mapping;+ for (const item of taskItems) {+ const childPos = pos + item.pos + 1;+ tr.deleteRange(+ mapping.map(childPos),+ mapping.map(childPos + item.node.nodeSize)+ );+ }+ return true;+ });+ }}+ />+ <Icon+ path={Icons.checkbox}+ size={15}+ color="fontTertiary"+ sx={{ ml: 1 }}+ /><Text variant={"body"} sx={{ ml: 1, color: "fontTertiary" }}>{stats.checked}/{stats.total}</Text>@@ -192,7 +229,7 @@ export function TaskListComponent(li: {listStyleType: "none",position: "relative",- marginBottom: isNested ? [1, "3px"] : [2, "7px"]+ marginBottom: isNested ? 1 : [2, 1]}}}/>diff --git a/packages/editor/src/toolbar/icons.ts b/packages/editor/src/toolbar/icons.tsindex 42418067e..e804b06b5 100644--- a/packages/editor/src/toolbar/icons.ts+++ b/packages/editor/src/toolbar/icons.ts@@ -107,7 +107,8 @@ import {mdiProgressDownload,mdiProgressAlert,mdiContentSaveOutline,- mdiClipboardOutline+ mdiClipboardOutline,+ mdiNotificationClearAll} from "@mdi/js";export const Icons = {@@ -152,6 +153,7 @@ export const Icons = {copy: mdiClipboardOutline,check: mdiCheck,checkbox: mdiCheckboxMarkedOutline,+ clear: mdiNotificationClearAll,loading: mdiLoading,more: mdiDotsVertical,upload: mdiUploadOutline,