Files
outline/shared/editor/queries/findStartOfLine.ts
Tom Moor 41ccad7cce Adds natural behavior of Tab, Shift-Tab in code blocks (#7622)
* Adds proper handling of Tab, Shift-Tab in code blocks

* refactor
2024-09-19 17:00:05 -07:00

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