1 | // See docs https://codemirror.net/doc/manual.html#addon_foldcode
|
2 |
|
3 | import * as CodeMirror from "../../";
|
4 |
|
5 | export type FoldRangeFinder = (cm: CodeMirror.Editor, pos: CodeMirror.Position) => CodeMirror.FoldRange | undefined;
|
6 |
|
7 | export interface FoldHelpers {
|
8 | combine: (...finders: FoldRangeFinder[]) => FoldRangeFinder;
|
9 | auto: FoldRangeFinder;
|
10 | }
|
11 |
|
12 | declare module "../../" {
|
13 | interface Editor {
|
14 | /**
|
15 | * Helps with code folding. Adds a foldCode method to editor instances, which will try to do a code fold starting at the given line,
|
16 | * or unfold the fold that is already present.
|
17 | * The method takes as first argument the position that should be folded (may be a line number or a Pos), and as second optional argument either a
|
18 | * range-finder function, or an options object.
|
19 | */
|
20 | foldCode: (
|
21 | lineOrPos: number | Position,
|
22 | rangeFindeOrFoldOptions?: FoldRangeFinder | FoldOptions,
|
23 | force?: "fold" | "unfold",
|
24 | ) => void;
|
25 | isFolded(pos: Position): boolean | undefined;
|
26 | foldOption<K extends keyof FoldOptions>(option: K): FoldOptions[K];
|
27 | }
|
28 |
|
29 | interface EditorConfiguration {
|
30 | foldOptions?: FoldOptions | undefined;
|
31 | }
|
32 |
|
33 | interface FoldOptions {
|
34 | /**
|
35 | * The function that is used to find foldable ranges. If this is not directly passed, it will default to CodeMirror.fold.auto,
|
36 | * which uses getHelpers with a "fold" type to find folding functions appropriate for the local mode.
|
37 | * There are files in the addon/fold/ directory providing CodeMirror.fold.brace, which finds blocks in brace languages (JavaScript, C, Java, etc),
|
38 | * CodeMirror.fold.indent, for languages where indentation determines block structure (Python, Haskell), and CodeMirror.fold.xml, for XML-style languages,
|
39 | * and CodeMirror.fold.comment, for folding comment blocks.
|
40 | */
|
41 | rangeFinder?: FoldRangeFinder | undefined;
|
42 |
|
43 | /**
|
44 | * The widget to show for folded ranges. Can be either a string, in which case it'll become a span with class CodeMirror-foldmarker, or a DOM node.
|
45 | * To dynamically generate the widget, this can be a function that returns a string or DOM node, which will then render as described.
|
46 | * The function will be invoked with parameters identifying the range to be folded.
|
47 | */
|
48 | widget?: string | Element | ((from: Position, to: Position) => string | Element) | undefined;
|
49 |
|
50 | /**
|
51 | * When true (default is false), the addon will try to find foldable ranges on the lines above the current one if there isn't an eligible one on the given line.
|
52 | */
|
53 | scanUp?: boolean | undefined;
|
54 |
|
55 | /**
|
56 | * The minimum amount of lines that a fold should span to be accepted. Defaults to 0, which also allows single-line folds.
|
57 | */
|
58 | minFoldSize?: number | undefined;
|
59 |
|
60 | clearOnEnter?: boolean | undefined;
|
61 | }
|
62 |
|
63 | interface FoldRange {
|
64 | from: Position;
|
65 | to: Position;
|
66 | }
|
67 |
|
68 | interface CommandActions {
|
69 | toggleFold(cm: Editor): void;
|
70 | fold(cm: Editor): void;
|
71 | unfold(cm: Editor): void;
|
72 | foldAll(cm: Editor): void;
|
73 | unfoldAll(cm: Editor): void;
|
74 | }
|
75 |
|
76 | const fold: FoldHelpers;
|
77 | }
|
78 |
|
\ | No newline at end of file |