UNPKG

3.96 kBTypeScriptView Raw
1import * as CodeMirror from "../../";
2
3/**
4 * Tracks changes in chunks from original to new.
5 */
6export interface MergeViewDiffChunk {
7 editFrom: number;
8 editTo: number;
9 origFrom: number;
10 origTo: number;
11}
12
13export interface DiffView {
14 /**
15 * Forces the view to reload.
16 */
17 forceUpdate(): (mode: string) => void;
18
19 /**
20 * Sets whether or not the merge view should show the differences between the editor views.
21 */
22 setShowDifferences(showDifferences: boolean): void;
23}
24
25export interface MergeView {
26 /**
27 * Returns the editor instance.
28 */
29 editor(): CodeMirror.Editor;
30
31 /**
32 * Left side of the merge view.
33 */
34 left?: DiffView | undefined;
35 leftChunks(): MergeViewDiffChunk[] | undefined;
36 leftOriginal(): CodeMirror.Editor | undefined;
37
38 /**
39 * Right side of the merge view.
40 */
41 right?: DiffView | undefined;
42 rightChunks(): MergeViewDiffChunk[] | undefined;
43 rightOriginal(): CodeMirror.Editor | undefined;
44
45 /**
46 * Sets whether or not the merge view should show the differences between the editor views.
47 */
48 setShowDifferences(showDifferences: boolean): void;
49}
50
51export interface MergeViewConstructor {
52 new(element: HTMLElement, options?: MergeViewConfiguration): MergeView;
53 (element: HTMLElement, options?: MergeViewConfiguration): MergeView;
54}
55
56/**
57 * Options available to MergeView.
58 */
59export interface MergeViewConfiguration extends CodeMirror.EditorConfiguration {
60 /**
61 * Determines whether the original editor allows editing. Defaults to false.
62 */
63 allowEditingOriginals?: boolean | undefined;
64
65 /**
66 * When true stretches of unchanged text will be collapsed. When a number is given, this indicates the amount
67 * of lines to leave visible around such stretches (which defaults to 2). Defaults to false.
68 */
69 collapseIdentical?: boolean | number | undefined;
70
71 /**
72 * Sets the style used to connect changed chunks of code. By default, connectors are drawn. When this is set to "align",
73 * the smaller chunk is padded to align with the bigger chunk instead.
74 */
75 connect?: string | undefined;
76
77 /**
78 * Callback for when stretches of unchanged text are collapsed.
79 */
80 onCollapse?(
81 mergeView: MergeView,
82 line: number,
83 size: number,
84 mark: CodeMirror.TextMarker<CodeMirror.MarkerRange>,
85 ): void;
86
87 /**
88 * Provides original version of the document to be shown on the right of the editor.
89 */
90 orig?: string | undefined;
91
92 /**
93 * Provides original version of the document to be shown on the left of the editor.
94 * To create a 2-way (as opposed to 3-way) merge view, provide only one of origLeft and origRight.
95 */
96 origLeft?: string | undefined;
97
98 /**
99 * Provides original version of document to be shown on the right of the editor.
100 * To create a 2-way (as opposed to 3-way) merge view, provide only one of origLeft and origRight.
101 */
102 origRight?: string | undefined;
103
104 /**
105 * Determines whether buttons that allow the user to revert changes are shown. Defaults to true.
106 */
107 revertButtons?: boolean | undefined;
108
109 revertChunk?:
110 | ((
111 mv: MergeView,
112 from: CodeMirror.Editor,
113 fromStart: CodeMirror.Position,
114 fromEnd: CodeMirror.Position,
115 to: CodeMirror.Editor,
116 toStart: CodeMirror.Position,
117 toEnd: CodeMirror.Position,
118 ) => void)
119 | undefined;
120
121 /**
122 * When true, changed pieces of text are highlighted. Defaults to true.
123 */
124 showDifferences?: boolean | undefined;
125}
126
127declare module "../../" {
128 const MergeView: MergeViewConstructor;
129
130 interface CommandActions {
131 /** Move cursor to the next diff */
132 goNextDiff(cm: Editor): void;
133
134 /** Move cursor to the previous diff */
135 goPrevDiff(cm: Editor): void;
136 }
137}