Add API for propagating cursor locations (#61)
This commit is contained in:
parent
f97193e287
commit
e8b9bf40c5
1 changed files with 1929 additions and 2228 deletions
|
|
@ -0,0 +1,17 @@
|
|||
import type { Editor } from "obsidian";
|
||||
import { lineAndColumnToPosition } from "../../utils/line-and-column-to-position";
|
||||
|
||||
export interface Cursor {
|
||||
id: number;
|
||||
start: number;
|
||||
end: number;
|
||||
}
|
||||
|
||||
export function getCursorsFromEditor(editor: Editor): Cursor[] {
|
||||
const text = editor.getValue();
|
||||
return editor.listSelections().map(({ anchor, head }, i) => ({
|
||||
id: i,
|
||||
start: lineAndColumnToPosition(text, anchor.line, anchor.ch),
|
||||
end: lineAndColumnToPosition(text, head.line, head.ch)
|
||||
}));
|
||||
}
|
||||
Loading…
Reference in a new issue