Skip to content

Commit

Permalink
fix: update onStatistics result line.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jul 2, 2022
1 parent d8ec2b2 commit d0d2f0e
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions core/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { EditorSelection, SelectionRange } from '@codemirror/state';
import { EditorSelection, SelectionRange, Line } from '@codemirror/state';
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 number of lines in the editor. */
lineCount: number;
/** Get the currently line description around the given position. */
line: Line;
/** 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. */
Expand All @@ -29,16 +31,19 @@ export interface Statistics {
selectedText: boolean;
}

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,
selectionAsSingle: view.state.selection.asSingle().main,
ranges: view.state.selection.ranges,
selectionCode: view.state.sliceDoc(view.state.selection.main.from, view.state.selection.main.to),
selections: view.state.selection.ranges.map((r) => view.state.sliceDoc(r.from, r.to)),
selectedText: view.state.selection.ranges.some((r) => !r.empty),
});
export const getStatistics = (view: ViewUpdate): Statistics => {
return {
line: view.state.doc.lineAt(view.state.selection.main.from),
lineCount: view.state.doc.lines,
lineBreak: view.state.lineBreak,
length: view.state.doc.length,
readOnly: view.state.readOnly,
tabSize: view.state.tabSize,
selection: view.state.selection,
selectionAsSingle: view.state.selection.asSingle().main,
ranges: view.state.selection.ranges,
selectionCode: view.state.sliceDoc(view.state.selection.main.from, view.state.selection.main.to),
selections: view.state.selection.ranges.map((r) => view.state.sliceDoc(r.from, r.to)),
selectedText: view.state.selection.ranges.some((r) => !r.empty),
};
};

0 comments on commit d0d2f0e

Please sign in to comment.