@@ -88,6 +88,120 @@ const code = 'const a = 0;';
88
88
- ` value ` value of the auto created model in the editor.
89
89
- ` options ` refer to [ codemirror options] ( https://codemirror.net/doc/manual.html#config ) .
90
90
91
+ ## Props Events
92
+
93
+ ``` tsx
94
+ import React from ' react' ;
95
+ import CodeMirror from ' codemirror' ;
96
+ export type DOMEvent = ' onMouseDown' | ' onDblClick' | ' onTouchStart' | ' onContextMenu' | ' onKeyDown' | ' onKeyPress'
97
+ | ' onKeyUp' | ' onCut' | ' onCopy' | ' onPaste' | ' onDragStart' | ' onDragEnter' | ' onDragOver' | ' onDragLeave' | ' onDrop' ;
98
+
99
+ export type IDOMEvent = {
100
+ [P in DOMEvent ]? : (instance : CodeMirror .Editor , event : Event ) => void ;
101
+ }
102
+
103
+ export type Editor = CodeMirror .Editor ;
104
+ export interface IReactCodemirror extends IDOMEvent {
105
+ /**
106
+ * Fired whenever a change occurs to the document.
107
+ * changeObj has a similar type as the object passed to the editor's "change" event,
108
+ * but it never has a next property, because document change events are not batched (whereas editor change events are).
109
+ */
110
+ onChange? : (instance : CodeMirror .Editor , change : CodeMirror .EditorChangeLinkedList []) => void ;
111
+ /**
112
+ * Like the "change" event, but batched per operation, passing an
113
+ * array containing all the changes that happened in the operation.
114
+ * This event is fired after the operation finished, and display
115
+ * changes it makes will trigger a new operation.
116
+ * */
117
+ onChanges? : (instance : CodeMirror .Editor , change : CodeMirror .EditorChangeLinkedList []) => void ;
118
+ /**
119
+ * This event is fired before a change is applied, and its handler may choose to modify or cancel the change.
120
+ * The changeObj never has a next property, since this is fired for each individual change, and not batched per operation.
121
+ * Note: you may not do anything from a "beforeChange" handler that would cause changes to the document or its visualization.
122
+ * Doing so will, since this handler is called directly from the bowels of the CodeMirror implementation,
123
+ * probably cause the editor to become corrupted.
124
+ */
125
+ onBeforeChange? : (instance : CodeMirror .Editor , change : CodeMirror .EditorChangeCancellable ) => void ;
126
+ /**
127
+ * Will be fired when the cursor or selection moves, or any change is made to the editor content.
128
+ */
129
+ onCursorActivity? : (instance : CodeMirror .Editor ) => void ;
130
+ /**
131
+ * This event is fired before the selection is moved. Its handler may modify the resulting selection head and anchor.
132
+ * Handlers for this event have the same restriction as "beforeChange" handlers they should not do anything to directly update the state of the editor.
133
+ */
134
+ onBeforeSelectionChange? : (instance : CodeMirror .Editor , selection : { head: Position ; anchor: Position ; }) => void ;
135
+ /**
136
+ * Fires whenever the view port of the editor changes (due to scrolling, editing, or any other factor).
137
+ * The from and to arguments give the new start and end of the viewport.
138
+ */
139
+ onViewportChange? : (instance : CodeMirror .Editor , from : number , to : number ) => void ;
140
+ /** Fires when the editor gutter (the line-number area) is clicked. Will pass the editor instance as first argument,
141
+ * the (zero-based) number of the line that was clicked as second argument, the CSS class of the gutter that was clicked as third argument,
142
+ * and the raw mousedown event object as fourth argument.
143
+ */
144
+ onGutterClick? : (instance : CodeMirror .Editor , line : number , gutter : string , clickEvent : Event ) => void ;
145
+
146
+ /** Fires whenever the editor is focused. */
147
+ onFocus? : (instance : CodeMirror .Editor ) => void ;
148
+
149
+ /** Fires whenever the editor is unfocused. */
150
+ onBlur? : (instance : CodeMirror .Editor ) => void ;
151
+
152
+ /** Fires when the editor is scrolled. */
153
+ onScroll? : (instance : CodeMirror .Editor ) => void ;
154
+
155
+ /** Will be fired whenever CodeMirror updates its DOM display. */
156
+ onUpdate? : (instance : CodeMirror .Editor ) => void ;
157
+
158
+ /** Fired whenever a line is (re-)rendered to the DOM. Fired right after the DOM element is built, before it is added to the document.
159
+ * The handler may mess with the style of the resulting element, or add event handlers, but should not try to change the state of the editor.
160
+ */
161
+ onRenderLine? : (instance : CodeMirror .Editor , line : CodeMirror .LineHandle , element : HTMLElement ) => void ;
162
+ /**
163
+ * Fires when the overwrite flag is flipped.
164
+ * */
165
+ onOverwriteToggle? : (instance : CodeMirror .Editor , overwrite : boolean ) => void ;
166
+ /**
167
+ * Fired whenever the cursor or selection in this document changes.
168
+ * */
169
+ onCursorActivity? (instance : CodeMirror .Editor ): void ;
170
+ /**
171
+ * Will be fired when the line object is deleted. A line object is associated with the start of the line.
172
+ * Mostly useful when you need to find out when your gutter markers on a given line are removed.
173
+ * */
174
+ onDelete? (): void ;
175
+ /**
176
+ * Fired when the cursor enters the marked range.
177
+ * From this event handler, the editor state may be inspected but not modified,
178
+ * with the exception that the range on which the event fires may be cleared.
179
+ * */
180
+ onBeforeCursorEnter? (): void ;
181
+ /**
182
+ * Fired when the cursor enters the marked range.
183
+ * From this event handler, the editor state may be inspected but not modified,
184
+ * with the exception that the range on which the event fires may be cleared.
185
+ * */
186
+ onClear? (): void ;
187
+ /**
188
+ * Fired when the last part of the marker is removed from the document by editing operations.
189
+ * */
190
+ onHide? (): void ;
191
+ /**
192
+ * Fired when, after the marker was removed by editing, a undo operation brought the marker back.
193
+ * */
194
+ onUnhide? (): void ;
195
+ /**
196
+ * Fired whenever the editor re-adds the widget to the DOM.
197
+ * This will happen once right after the widget is added (if it is scrolled into view),
198
+ * and then again whenever it is scrolled out of view and back in again, or when changes to the editor options
199
+ * or the line the widget is on require the widget to be redrawn.
200
+ * */
201
+ onRedraw? (): void ;
202
+ }
203
+ ```
204
+
91
205
## Options
92
206
93
207
[ codemirror options] ( https://codemirror.net/doc/manual.html#config )
0 commit comments