Skip to content

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

fix: memoize outline list collapse action

thecodrr9724dfe6ded6
diff --git a/packages/editor/src/extensions/outline-list-item/component.tsx b/packages/editor/src/extensions/outline-list-item/component.tsx
index 0135d2877..8d496574e 100644
--- a/packages/editor/src/extensions/outline-list-item/component.tsx
+++ b/packages/editor/src/extensions/outline-list-item/component.tsx
@@ -8,7 +8,7 @@ import {
findChildren,
findParentNode,
getNodeType,
- NodeWithPos
+ NodeWithPos,
} from "@tiptap/core";
import { useCallback, useEffect } from "react";
import { OutlineList } from "../outline-list/outline-list";
@@ -21,7 +21,7 @@ export function OutlineListItemComponent(props: ReactNodeViewProps) {
const isNested = node.lastChild?.type.name === OutlineList.name;
const isCollapsed = isNested && node.lastChild?.attrs.collapsed;
- const onClick = () => {
+ const onClick = useCallback(() => {
const [subList] = findChildren(
node,
(node) => node.type.name === OutlineList.name
@@ -29,8 +29,11 @@ export function OutlineListItemComponent(props: ReactNodeViewProps) {
if (!subList) return;
const { pos } = subList;
- editor.commands.toggleOutlineCollapse(pos + getPos() + 1, !isCollapsed);
- };
+ editor.current?.commands.toggleOutlineCollapse(
+ pos + getPos() + 1,
+ !isCollapsed
+ );
+ }, []);
return (
<Flex>
@@ -39,7 +42,7 @@ export function OutlineListItemComponent(props: ReactNodeViewProps) {
sx={{
flexDirection: "column",
alignItems: "center",
- mt: isMobile ? "0px" : "3px"
+ mt: isMobile ? "0px" : "3px",
}}
>
{isNested ? (
@@ -54,14 +57,14 @@ export function OutlineListItemComponent(props: ReactNodeViewProps) {
cursor: "pointer",
transition: `all .2s ease-in-out`,
":hover": {
- transform: ["unset", "scale(1.3)"]
+ transform: ["unset", "scale(1.3)"],
},
":active": {
- transform: ["scale(1.3)", "unset"]
+ transform: ["scale(1.3)", "unset"],
},
".icon:hover path": {
- fill: "var(--checked) !important"
- }
+ fill: "var(--checked) !important",
+ },
}}
size={isMobile ? 24 : 18}
onMouseDown={(e) => e.preventDefault()}
@@ -92,8 +95,8 @@ export function OutlineListItemComponent(props: ReactNodeViewProps) {
transition: `all .2s ease-in-out`,
":hover": {
backgroundColor: "fontTertiary",
- width: 4
- }
+ width: 4,
+ },
}}
contentEditable={false}
/>
@@ -104,7 +107,7 @@ export function OutlineListItemComponent(props: ReactNodeViewProps) {
sx={{
pl: 1,
listStyleType: "none",
- flex: 1
+ flex: 1,
}}
/>
</Flex>