Files
outline/shared/editor/queries/getCurrentBlock.ts
codegen-sh[bot] c97e5fd181 feat: Add block movement with Cmd+Alt+Arrow keys (#9502)
* 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>
2025-06-29 04:56:48 -04:00

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;
}