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
feat: show outdent/indent buttons in toolbar when list is selected
thecodrrce7e2ed536d4
diff --git a/packages/editor/src/toolbar/tools/lists.tsx b/packages/editor/src/toolbar/tools/lists.tsxindex fd479a7a9..0d39f6b58 100644--- a/packages/editor/src/toolbar/tools/lists.tsx+++ b/packages/editor/src/toolbar/tools/lists.tsx@@ -7,6 +7,8 @@ import { useToolbarLocation } from "../stores/toolbar-store";import { getToolbarElement } from "../utils/dom";import { PopupWrapper } from "../../components/popup-presenter";import React from "react";+import { ToolButton } from "../components/tool-button";+import { findListItemType, isListActive } from "../utils/prosemirror";type ListSubType<TListStyleTypes> = {items: string[];@@ -161,6 +163,42 @@ export function BulletList(props: ToolProps) {);}+export function Indent(props: ToolProps) {+ const { editor, ...toolProps } = props;+ const isBottom = useToolbarLocation() === "bottom";++ const listItemType = findListItemType(editor);+ if (!listItemType || !isBottom) return null;++ return (+ <ToolButton+ {...toolProps}+ toggled={false}+ onClick={() =>+ editor.current?.chain().focus().sinkListItem(listItemType).run()+ }+ />+ );+}++export function Outdent(props: ToolProps) {+ const { editor, ...toolProps } = props;+ const isBottom = useToolbarLocation() === "bottom";++ const listItemType = findListItemType(editor);+ if (!listItemType || !isBottom) return null;++ return (+ <ToolButton+ {...toolProps}+ toggled={false}+ onClick={() =>+ editor.current?.chain().focus().liftListItem(listItemType).run()+ }+ />+ );+}+type ListThumbnailProps = { listStyleType: string };function ListThumbnail(props: ListThumbnailProps) {const { listStyleType } = props;diff --git a/packages/editor/src/toolbar/utils/prosemirror.ts b/packages/editor/src/toolbar/utils/prosemirror.tsindex 4a53bb6b2..8d230dff5 100644--- a/packages/editor/src/toolbar/utils/prosemirror.ts+++ b/packages/editor/src/toolbar/utils/prosemirror.ts@@ -54,3 +54,27 @@ export function selectionToOffset(selection: Selection): NodeWithOffset {const { $from, from } = selection;return { node: $from.node(), from, to: from + $from.node().nodeSize };}++export function findListItemType(editor: Editor): string | null {+ const isTaskList = editor.isActive("taskList");+ const isOutlineList = editor.isActive("outlineList");+ const isList =+ editor.isActive("bulletList") || editor.isActive("orderedList");++ return isList+ ? "listItem"+ : isOutlineList+ ? "outlineListItem"+ : isTaskList+ ? "taskItem"+ : null;+}++export function isListActive(editor: Editor): boolean {+ const isTaskList = editor.isActive("taskList");+ const isOutlineList = editor.isActive("outlineList");+ const isList =+ editor.isActive("bulletList") || editor.isActive("orderedList");++ return isTaskList || isOutlineList || isList;+}