Toggle current todo item with Mod-Enter
This commit is contained in:
@@ -3,6 +3,13 @@ import { NodeType } from "prosemirror-model";
|
|||||||
import { Command } from "prosemirror-state";
|
import { Command } from "prosemirror-state";
|
||||||
import isNodeActive from "../queries/isNodeActive";
|
import isNodeActive from "../queries/isNodeActive";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggles the block type of the current selection between the given type and the toggle type.
|
||||||
|
*
|
||||||
|
* @param type The node type
|
||||||
|
* @param toggleType The toggle node type
|
||||||
|
* @returns A prosemirror command.
|
||||||
|
*/
|
||||||
export default function toggleBlockType(
|
export default function toggleBlockType(
|
||||||
type: NodeType,
|
type: NodeType,
|
||||||
toggleType: NodeType,
|
toggleType: NodeType,
|
||||||
|
|||||||
34
shared/editor/commands/toggleCheckboxItem.ts
Normal file
34
shared/editor/commands/toggleCheckboxItem.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import { Command } from "prosemirror-state";
|
||||||
|
import { findParentNode } from "@shared/editor/queries/findParentNode";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A prosemirror command to toggle the checkbox item at the current selection.
|
||||||
|
*
|
||||||
|
* @returns A prosemirror command.
|
||||||
|
*/
|
||||||
|
export default function toggleCheckboxItem(): Command {
|
||||||
|
return (state, dispatch) => {
|
||||||
|
const { empty } = state.selection;
|
||||||
|
|
||||||
|
// if the selection has anything in it then use standard behavior
|
||||||
|
if (!empty) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check we're in a matching node
|
||||||
|
const listItem = findParentNode(
|
||||||
|
(node) => node.type === state.schema.nodes.checkbox_item
|
||||||
|
)(state.selection);
|
||||||
|
|
||||||
|
if (!listItem) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch?.(
|
||||||
|
state.tr.setNodeMarkup(listItem.pos, undefined, {
|
||||||
|
checked: !listItem.node.attrs.checked,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
sinkListItem,
|
sinkListItem,
|
||||||
liftListItem,
|
liftListItem,
|
||||||
} from "prosemirror-schema-list";
|
} from "prosemirror-schema-list";
|
||||||
|
import toggleCheckboxItem from "../commands/toggleCheckboxItem";
|
||||||
import { MarkdownSerializerState } from "../lib/markdown/serializer";
|
import { MarkdownSerializerState } from "../lib/markdown/serializer";
|
||||||
import checkboxRule from "../rules/checkboxes";
|
import checkboxRule from "../rules/checkboxes";
|
||||||
import Node from "./Node";
|
import Node from "./Node";
|
||||||
@@ -93,6 +94,7 @@ export default class CheckboxItem extends Node {
|
|||||||
checked: false,
|
checked: false,
|
||||||
}),
|
}),
|
||||||
Tab: sinkListItem(type),
|
Tab: sinkListItem(type),
|
||||||
|
"Mod-Enter": toggleCheckboxItem(),
|
||||||
"Shift-Tab": liftListItem(type),
|
"Shift-Tab": liftListItem(type),
|
||||||
"Mod-]": sinkListItem(type),
|
"Mod-]": sinkListItem(type),
|
||||||
"Mod-[": liftListItem(type),
|
"Mod-[": liftListItem(type),
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ export const basicExtensions: Nodes = [
|
|||||||
* editors that need advanced formatting.
|
* editors that need advanced formatting.
|
||||||
*/
|
*/
|
||||||
export const richExtensions: Nodes = [
|
export const richExtensions: Nodes = [
|
||||||
...basicExtensions.filter((n) => n !== SimpleImage),
|
...basicExtensions.filter((n) => n !== SimpleImage && n !== Keys),
|
||||||
Image,
|
Image,
|
||||||
HardBreak,
|
HardBreak,
|
||||||
CodeBlock,
|
CodeBlock,
|
||||||
@@ -109,6 +109,7 @@ export const richExtensions: Nodes = [
|
|||||||
Math,
|
Math,
|
||||||
MathBlock,
|
MathBlock,
|
||||||
PreventTab,
|
PreventTab,
|
||||||
|
Keys,
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -211,7 +211,6 @@
|
|||||||
"Choose icon": "Choose icon",
|
"Choose icon": "Choose icon",
|
||||||
"Loading": "Loading",
|
"Loading": "Loading",
|
||||||
"Select a color": "Select a color",
|
"Select a color": "Select a color",
|
||||||
"Loading editor": "Loading editor",
|
|
||||||
"Search": "Search",
|
"Search": "Search",
|
||||||
"Default access": "Default access",
|
"Default access": "Default access",
|
||||||
"View and edit": "View and edit",
|
"View and edit": "View and edit",
|
||||||
|
|||||||
Reference in New Issue
Block a user