CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/codemirror/extensions/util.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
export function cm_start_end(
7
selection
8
): { start_line: number; end_line: number } {
9
const { head, anchor } = selection;
10
let start = head;
11
let end = anchor;
12
if (
13
end.line <= start.line ||
14
(end.line === start.line && end.ch <= start.ch)
15
) {
16
[start, end] = [end, start];
17
}
18
const start_line = start.line;
19
let end_line = end.ch > 0 ? end.line : end.line - 1;
20
if (end_line < start_line) {
21
end_line = start_line;
22
}
23
return { start_line, end_line };
24
}
25
26