mirror of
https://github.com/outline/outline.git
synced 2026-11-21 13:34:02 +03:00
* feat: Add block movement with Cmd+Alt+Arrow keys - Add getCurrentBlock helper function to find current block node - Implement moveBlockUp and moveBlockDown commands in Keys extension - Support Cmd+Alt+ArrowUp to move current block up - Support Cmd+Alt+ArrowDown to move current block down - Follow ProseMirror best practices for node manipulation - Maintain cursor position after block movement Fixes #9486 * feat: Add block movement shortcuts to KeyboardShortcuts component - Add Cmd+Alt+↑ shortcut for moving blocks up - Add Cmd+Alt+↓ shortcut for moving blocks down - Added to Formatting section alongside other editing shortcuts --------- Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com>
27 lines
689 B
TypeScript
27 lines
689 B
TypeScript
import { Node } from "prosemirror-model";
|
|
import { EditorState } from "prosemirror-state";
|
|
|
|
/**
|
|
* Gets the current block node that contains the selection
|
|
* @param state The editor state
|
|
* @returns The current block node and its position, or undefined if not found
|
|
*/
|
|
export function getCurrentBlock(
|
|
state: EditorState
|
|
): [Node, number] | undefined {
|
|
const { $head } = state.selection;
|
|
|
|
// Walk up the tree to find the first block node
|
|
for (let d = $head.depth; d >= 0; d--) {
|
|
const node = $head.node(d);
|
|
const pos = $head.before(d);
|
|
|
|
if (node.isBlock && d > 0) {
|
|
// Don't return the document itself
|
|
return [node, pos];
|
|
}
|
|
}
|
|
|
|
return undefined;
|
|
}
|