mirror of
https://github.com/outline/outline.git
synced 2026-11-21 21:44:30 +03:00
23 lines
566 B
TypeScript
23 lines
566 B
TypeScript
import { Node, ResolvedPos } from "prosemirror-model";
|
|
|
|
/**
|
|
* Find the start of the line that the current position is on.
|
|
*
|
|
* @param $pos The current resolved position
|
|
* @param doc The current document
|
|
* @returns The position of the start of the line as an integer.
|
|
*/
|
|
export function findStartOfLine($pos: ResolvedPos, doc: Node) {
|
|
let lineStart = $pos.pos;
|
|
const parentStart = $pos.pos - $pos.parentOffset;
|
|
|
|
while (
|
|
lineStart > parentStart &&
|
|
doc.textBetween(lineStart - 1, lineStart) !== "\n"
|
|
) {
|
|
lineStart--;
|
|
}
|
|
|
|
return lineStart;
|
|
}
|