Skip to content

Commit

Permalink
fix: add onStatistics result length/lineBreak/readOnly/tabSize.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jul 2, 2022
1 parent 23dd9dc commit d2d2aa4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,14 @@ import { ViewUpdate } from '@codemirror/view';
export interface Statistics {
/** Get the number of lines in the editor. */
lineCount: number;
/** total length of the document */
length: number;
/** Get the proper [line-break](https://codemirror.net/docs/ref/#state.EditorState^lineSeparator) string for this state. */
lineBreak: string;
/** Returns true when the editor is [configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only. */
readOnly: boolean;
/** The size (in columns) of a tab in the document, determined by the [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) facet. */
tabSize: number;
/** Cursor Position */
selection: EditorSelection;
/** Retrieves a list of all current selections. */
Expand Down
12 changes: 12 additions & 0 deletions core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import { ViewUpdate } from '@codemirror/view';
export interface Statistics {
/** Get the number of lines in the editor. */
lineCount: number;
/** total length of the document */
length: number;
/** Get the proper [line-break](https://codemirror.net/docs/ref/#state.EditorState^lineSeparator) string for this state. */
lineBreak: string;
/** Returns true when the editor is [configured](https://codemirror.net/6/docs/ref/#state.EditorState^readOnly) to be read-only. */
readOnly: boolean;
/** The size (in columns) of a tab in the document, determined by the [`tabSize`](https://codemirror.net/6/docs/ref/#state.EditorState^tabSize) facet. */
tabSize: number;
/** Cursor Position */
selection: EditorSelection;
/** Retrieves a list of all current selections. */
Expand All @@ -21,6 +29,10 @@ export interface Statistics {

export const getStatistics = (view: ViewUpdate): Statistics => ({
lineCount: view.state.doc.lines,
length: view.state.doc.length,
lineBreak: view.state.lineBreak,
readOnly: view.state.readOnly,
tabSize: view.state.tabSize,
selection: view.state.selection,
ranges: view.state.selection.ranges,
selectionCode: view.state.sliceDoc(view.state.selection.main.from, view.state.selection.main.to),
Expand Down

0 comments on commit d2d2aa4

Please sign in to comment.