Skip to content

Commit d2d2aa4

Browse files
committed
fix: add onStatistics result length/lineBreak/readOnly/tabSize.
1 parent 23dd9dc commit d2d2aa4

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

core/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,14 @@ import { ViewUpdate } from '@codemirror/view';
367367
export interface Statistics {
368368
/** Get the number of lines in the editor. */
369369
lineCount: number;
370+
/** total length of the document */
371+
length: number;
372+
/** Get the proper [line-break](https://codemirror.net/docs/ref/#state.EditorState^lineSeparator) string for this state. */
373+
lineBreak: string;
374+
/** Returns true when the editor is [configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only. */
375+
readOnly: boolean;
376+
/** The size (in columns) of a tab in the document, determined by the [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) facet. */
377+
tabSize: number;
370378
/** Cursor Position */
371379
selection: EditorSelection;
372380
/** Retrieves a list of all current selections. */

core/src/utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ import { ViewUpdate } from '@codemirror/view';
44
export interface Statistics {
55
/** Get the number of lines in the editor. */
66
lineCount: number;
7+
/** total length of the document */
8+
length: number;
9+
/** Get the proper [line-break](https://codemirror.net/docs/ref/#state.EditorState^lineSeparator) string for this state. */
10+
lineBreak: string;
11+
/** Returns true when the editor is [configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only. */
12+
readOnly: boolean;
13+
/** The size (in columns) of a tab in the document, determined by the [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) facet. */
14+
tabSize: number;
715
/** Cursor Position */
816
selection: EditorSelection;
917
/** Retrieves a list of all current selections. */
@@ -21,6 +29,10 @@ export interface Statistics {
2129

2230
export const getStatistics = (view: ViewUpdate): Statistics => ({
2331
lineCount: view.state.doc.lines,
32+
length: view.state.doc.length,
33+
lineBreak: view.state.lineBreak,
34+
readOnly: view.state.readOnly,
35+
tabSize: view.state.tabSize,
2436
selection: view.state.selection,
2537
ranges: view.state.selection.ranges,
2638
selectionCode: view.state.sliceDoc(view.state.selection.main.from, view.state.selection.main.to),

0 commit comments

Comments
 (0)