outline/shared/editor/commands/collapseSelection.ts
2024-07-02 03:55:16 -07:00

16 lines
413 B
TypeScript

import { Command, TextSelection } from "prosemirror-state";
/**
* A prosemirror command to collapse the current selection to a cursor at the start of the selection.
*
* @returns A prosemirror command.
*/
export const collapseSelection = (): Command => (state, dispatch) => {
dispatch?.(
state.tr.setSelection(
TextSelection.create(state.doc, state.tr.selection.from)
)
);
return true;
};