Skip to content

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

editor: add p tag above the 1st node list on `ArrowUp` (fixes #970)

Abdullah Atta0f9939120535
diff --git a/packages/editor/src/extensions/list-item/commands.ts b/packages/editor/src/extensions/list-item/commands.ts
index 7ea916ed2..e030c47e9 100644
--- a/packages/editor/src/extensions/list-item/commands.ts
+++ b/packages/editor/src/extensions/list-item/commands.ts
@@ -65,6 +65,17 @@ export function onBackspacePressed(
}
}
+export function onArrowUpPressed(editor: Editor, name: string, type: NodeType) {
+ const { selection } = editor.state;
+ const { empty } = selection;
+
+ if (!empty || !isFirstOfType(type, editor.state)) return false;
+ const parentList = getListFromListItem(type, editor.state);
+ if (editor.state.doc.firstChild === parentList)
+ return editor.commands.insertContentAt(0, "<p></p>");
+ return false;
+}
+
function isInside(name: string, type: NodeType, state: EditorState) {
const { $from } = state.selection;
diff --git a/packages/editor/src/extensions/list-item/list-item.ts b/packages/editor/src/extensions/list-item/list-item.ts
index abea0a426..213cc2ce0 100644
--- a/packages/editor/src/extensions/list-item/list-item.ts
+++ b/packages/editor/src/extensions/list-item/list-item.ts
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { ListItem as TiptapListItem } from "@tiptap/extension-list-item";
-import { onBackspacePressed } from "./commands";
+import { onArrowUpPressed, onBackspacePressed } from "./commands";
export const ListItem = TiptapListItem.extend({
addKeyboardShortcuts() {
@@ -35,7 +35,8 @@ export const ListItem = TiptapListItem.extend({
return this.parent?.()?.Tab(props) || false;
},
Backspace: ({ editor }) =>
- onBackspacePressed(editor, this.name, this.type)
+ onBackspacePressed(editor, this.name, this.type),
+ ArrowUp: ({ editor }) => onArrowUpPressed(editor, this.name, this.type)
};
}
});
diff --git a/packages/editor/src/extensions/outline-list-item/outline-list-item.ts b/packages/editor/src/extensions/outline-list-item/outline-list-item.ts
index 002a5ef5e..46451ebfb 100644
--- a/packages/editor/src/extensions/outline-list-item/outline-list-item.ts
+++ b/packages/editor/src/extensions/outline-list-item/outline-list-item.ts
@@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import { Node, mergeAttributes, findChildren, Editor } from "@tiptap/core";
import { NodeType } from "prosemirror-model";
import { findParentNodeOfTypeClosestToPos } from "prosemirror-utils";
-import { onBackspacePressed } from "../list-item/commands";
+import { onArrowUpPressed, onBackspacePressed } from "../list-item/commands";
import { OutlineList } from "../outline-list/outline-list";
import { createNodeView } from "../react";
import { OutlineListItemComponent } from "./component";
@@ -95,7 +95,8 @@ export const OutlineListItem = Node.create<ListItemOptions>({
Tab: () => this.editor.commands.sinkListItem(this.name),
"Shift-Tab": () => this.editor.commands.liftListItem(this.name),
Backspace: ({ editor }) =>
- onBackspacePressed(editor, this.name, this.type)
+ onBackspacePressed(editor, this.name, this.type),
+ ArrowUp: ({ editor }) => onArrowUpPressed(editor, this.name, this.type)
};
},
diff --git a/packages/editor/src/extensions/task-item/task-item.ts b/packages/editor/src/extensions/task-item/task-item.ts
index b8063b44c..b82712482 100644
--- a/packages/editor/src/extensions/task-item/task-item.ts
+++ b/packages/editor/src/extensions/task-item/task-item.ts
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { mergeAttributes } from "@tiptap/core";
-import { onBackspacePressed } from "../list-item/commands";
+import { onArrowUpPressed, onBackspacePressed } from "../list-item/commands";
import { TaskItem } from "@tiptap/extension-task-item";
import { TaskItemComponent } from "./component";
import { createNodeView } from "../react";
@@ -75,7 +75,8 @@ export const TaskItemNode = TaskItem.extend({
return {
...this.parent?.(),
Backspace: ({ editor }) =>
- onBackspacePressed(editor, this.name, this.type)
+ onBackspacePressed(editor, this.name, this.type),
+ ArrowUp: ({ editor }) => onArrowUpPressed(editor, this.name, this.type)
};
},