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
fix: outline list doesn't expand/collapse predictably (fixes streetwriters/notesnook#801)
thecodrr09219a88a9a9
diff --git a/packages/editor/src/extensions/outline-list-item/component.tsx b/packages/editor/src/extensions/outline-list-item/component.tsxindex 8d496574e..db847375d 100644--- a/packages/editor/src/extensions/outline-list-item/component.tsx+++ b/packages/editor/src/extensions/outline-list-item/component.tsx@@ -2,39 +2,19 @@ import { Box, Flex, Text } from "rebass";import { ReactNodeViewProps } from "../react";import { Icon } from "../../toolbar/components/icon";import { Icons } from "../../toolbar/icons";-import { Node } from "prosemirror-model";-import { Transaction } from "prosemirror-state";-import {- findChildren,- findParentNode,- getNodeType,- NodeWithPos,-} from "@tiptap/core";-import { useCallback, useEffect } from "react";+import { Node as ProsemirrorNode } from "prosemirror-model";+import { findChildren } from "@tiptap/core";import { OutlineList } from "../outline-list/outline-list";import { useIsMobile } from "../../toolbar/stores/toolbar-store";+import { Editor } from "../../types";export function OutlineListItemComponent(props: ReactNodeViewProps) {- const { editor, updateAttributes, node, getPos, forwardRef } = props;+ const { editor, node, getPos, forwardRef } = props;const isMobile = useIsMobile();const isNested = node.lastChild?.type.name === OutlineList.name;const isCollapsed = isNested && node.lastChild?.attrs.collapsed;- const onClick = useCallback(() => {- const [subList] = findChildren(- node,- (node) => node.type.name === OutlineList.name- );- if (!subList) return;- const { pos } = subList;-- editor.current?.commands.toggleOutlineCollapse(- pos + getPos() + 1,- !isCollapsed- );- }, []);-return (<Flex><Flex@@ -70,9 +50,11 @@ export function OutlineListItemComponent(props: ReactNodeViewProps) {onMouseDown={(e) => e.preventDefault()}onTouchEnd={(e) => {e.preventDefault();- onClick();+ toggleOutlineList(editor, node, isCollapsed, getPos());+ }}+ onClick={() => {+ toggleOutlineList(editor, node, isCollapsed, getPos());}}- onClick={onClick}/>) : (<Icon@@ -113,3 +95,22 @@ export function OutlineListItemComponent(props: ReactNodeViewProps) {</Flex>);}++function toggleOutlineList(+ editor: Editor,+ node: ProsemirrorNode,+ isCollapsed: boolean,+ nodePos: number+) {+ const [subList] = findChildren(+ node,+ (node) => node.type.name === OutlineList.name+ );+ if (!subList) return;+ const { pos } = subList;++ editor.current?.commands.toggleOutlineCollapse(+ pos + nodePos + 1,+ !isCollapsed+ );+}