1 | import * as _codemirror_state from '@codemirror/state';
|
2 | import { RangeSet, RangeValue, Range, EditorState, Extension, Transaction, ChangeSet, EditorSelection, EditorStateConfig, TransactionSpec, SelectionRange, Line, StateEffect, Facet } from '@codemirror/state';
|
3 | import { StyleModule, StyleSpec } from 'style-mod';
|
4 |
|
5 | declare type Attrs = {
|
6 | [name: string]: string;
|
7 | };
|
8 |
|
9 | interface MarkDecorationSpec {
|
10 | /**
|
11 | Whether the mark covers its start and end position or not. This
|
12 | influences whether content inserted at those positions becomes
|
13 | part of the mark. Defaults to false.
|
14 | */
|
15 | inclusive?: boolean;
|
16 | /**
|
17 | Specify whether the start position of the marked range should be
|
18 | inclusive. Overrides `inclusive`, when both are present.
|
19 | */
|
20 | inclusiveStart?: boolean;
|
21 | /**
|
22 | Whether the end should be inclusive.
|
23 | */
|
24 | inclusiveEnd?: boolean;
|
25 | /**
|
26 | Add attributes to the DOM elements that hold the text in the
|
27 | marked range.
|
28 | */
|
29 | attributes?: {
|
30 | [key: string]: string;
|
31 | };
|
32 | /**
|
33 | Shorthand for `{attributes: {class: value}}`.
|
34 | */
|
35 | class?: string;
|
36 | /**
|
37 | Add a wrapping element around the text in the marked range. Note
|
38 | that there will not necessarily be a single element covering the
|
39 | entire range—other decorations with lower precedence might split
|
40 | this one if they partially overlap it, and line breaks always
|
41 | end decoration elements.
|
42 | */
|
43 | tagName?: string;
|
44 | /**
|
45 | Decoration specs allow extra properties, which can be retrieved
|
46 | through the decoration's [`spec`](https://codemirror.net/6/docs/ref/#view.Decoration.spec)
|
47 | property.
|
48 | */
|
49 | [other: string]: any;
|
50 | }
|
51 | interface WidgetDecorationSpec {
|
52 | /**
|
53 | The type of widget to draw here.
|
54 | */
|
55 | widget: WidgetType;
|
56 | /**
|
57 | Which side of the given position the widget is on. When this is
|
58 | positive, the widget will be drawn after the cursor if the
|
59 | cursor is on the same position. Otherwise, it'll be drawn before
|
60 | it. When multiple widgets sit at the same position, their `side`
|
61 | values will determine their ordering—those with a lower value
|
62 | come first. Defaults to 0.
|
63 | */
|
64 | side?: number;
|
65 | /**
|
66 | Determines whether this is a block widgets, which will be drawn
|
67 | between lines, or an inline widget (the default) which is drawn
|
68 | between the surrounding text.
|
69 |
|
70 | Note that block-level decorations should not have vertical
|
71 | margins, and if you dynamically change their height, you should
|
72 | make sure to call
|
73 | [`requestMeasure`](https://codemirror.net/6/docs/ref/#view.EditorView.requestMeasure), so that the
|
74 | editor can update its information about its vertical layout.
|
75 | */
|
76 | block?: boolean;
|
77 | /**
|
78 | Other properties are allowed.
|
79 | */
|
80 | [other: string]: any;
|
81 | }
|
82 | interface ReplaceDecorationSpec {
|
83 | /**
|
84 | An optional widget to drawn in the place of the replaced
|
85 | content.
|
86 | */
|
87 | widget?: WidgetType;
|
88 | /**
|
89 | Whether this range covers the positions on its sides. This
|
90 | influences whether new content becomes part of the range and
|
91 | whether the cursor can be drawn on its sides. Defaults to false
|
92 | for inline replacements, and true for block replacements.
|
93 | */
|
94 | inclusive?: boolean;
|
95 | /**
|
96 | Set inclusivity at the start.
|
97 | */
|
98 | inclusiveStart?: boolean;
|
99 | /**
|
100 | Set inclusivity at the end.
|
101 | */
|
102 | inclusiveEnd?: boolean;
|
103 | /**
|
104 | Whether this is a block-level decoration. Defaults to false.
|
105 | */
|
106 | block?: boolean;
|
107 | /**
|
108 | Other properties are allowed.
|
109 | */
|
110 | [other: string]: any;
|
111 | }
|
112 | interface LineDecorationSpec {
|
113 | /**
|
114 | DOM attributes to add to the element wrapping the line.
|
115 | */
|
116 | attributes?: {
|
117 | [key: string]: string;
|
118 | };
|
119 | /**
|
120 | Shorthand for `{attributes: {class: value}}`.
|
121 | */
|
122 | class?: string;
|
123 | /**
|
124 | Other properties are allowed.
|
125 | */
|
126 | [other: string]: any;
|
127 | }
|
128 | /**
|
129 | Widgets added to the content are described by subclasses of this
|
130 | class. Using a description object like that makes it possible to
|
131 | delay creating of the DOM structure for a widget until it is
|
132 | needed, and to avoid redrawing widgets even if the decorations
|
133 | that define them are recreated.
|
134 | */
|
135 | declare abstract class WidgetType {
|
136 | /**
|
137 | Build the DOM structure for this widget instance.
|
138 | */
|
139 | abstract toDOM(view: EditorView): HTMLElement;
|
140 | /**
|
141 | Compare this instance to another instance of the same type.
|
142 | (TypeScript can't express this, but only instances of the same
|
143 | specific class will be passed to this method.) This is used to
|
144 | avoid redrawing widgets when they are replaced by a new
|
145 | decoration of the same type. The default implementation just
|
146 | returns `false`, which will cause new instances of the widget to
|
147 | always be redrawn.
|
148 | */
|
149 | eq(widget: WidgetType): boolean;
|
150 | /**
|
151 | Update a DOM element created by a widget of the same type (but
|
152 | different, non-`eq` content) to reflect this widget. May return
|
153 | true to indicate that it could update, false to indicate it
|
154 | couldn't (in which case the widget will be redrawn). The default
|
155 | implementation just returns false.
|
156 | */
|
157 | updateDOM(dom: HTMLElement): boolean;
|
158 | /**
|
159 | The estimated height this widget will have, to be used when
|
160 | estimating the height of content that hasn't been drawn. May
|
161 | return -1 to indicate you don't know. The default implementation
|
162 | returns -1.
|
163 | */
|
164 | get estimatedHeight(): number;
|
165 | /**
|
166 | Can be used to configure which kinds of events inside the widget
|
167 | should be ignored by the editor. The default is to ignore all
|
168 | events.
|
169 | */
|
170 | ignoreEvent(event: Event): boolean;
|
171 | /**
|
172 | This is called when the an instance of the widget is removed
|
173 | from the editor view.
|
174 | */
|
175 | destroy(dom: HTMLElement): void;
|
176 | }
|
177 | /**
|
178 | A decoration set represents a collection of decorated ranges,
|
179 | organized for efficient access and mapping. See
|
180 | [`RangeSet`](https://codemirror.net/6/docs/ref/#state.RangeSet) for its methods.
|
181 | */
|
182 | declare type DecorationSet = RangeSet<Decoration>;
|
183 | /**
|
184 | The different types of blocks that can occur in an editor view.
|
185 | */
|
186 | declare enum BlockType {
|
187 | /**
|
188 | A line of text.
|
189 | */
|
190 | Text = 0,
|
191 | /**
|
192 | A block widget associated with the position after it.
|
193 | */
|
194 | WidgetBefore = 1,
|
195 | /**
|
196 | A block widget associated with the position before it.
|
197 | */
|
198 | WidgetAfter = 2,
|
199 | /**
|
200 | A block widget [replacing](https://codemirror.net/6/docs/ref/#view.Decoration^replace) a range of content.
|
201 | */
|
202 | WidgetRange = 3
|
203 | }
|
204 | /**
|
205 | A decoration provides information on how to draw or style a piece
|
206 | of content. You'll usually use it wrapped in a
|
207 | [`Range`](https://codemirror.net/6/docs/ref/#state.Range), which adds a start and end position.
|
208 | @nonabstract
|
209 | */
|
210 | declare abstract class Decoration extends RangeValue {
|
211 | /**
|
212 | The config object used to create this decoration. You can
|
213 | include additional properties in there to store metadata about
|
214 | your decoration.
|
215 | */
|
216 | readonly spec: any;
|
217 | protected constructor(
|
218 | /**
|
219 | @internal
|
220 | */
|
221 | startSide: number,
|
222 | /**
|
223 | @internal
|
224 | */
|
225 | endSide: number,
|
226 | /**
|
227 | @internal
|
228 | */
|
229 | widget: WidgetType | null,
|
230 | /**
|
231 | The config object used to create this decoration. You can
|
232 | include additional properties in there to store metadata about
|
233 | your decoration.
|
234 | */
|
235 | spec: any);
|
236 | abstract eq(other: Decoration): boolean;
|
237 | /**
|
238 | Create a mark decoration, which influences the styling of the
|
239 | content in its range. Nested mark decorations will cause nested
|
240 | DOM elements to be created. Nesting order is determined by
|
241 | precedence of the [facet](https://codemirror.net/6/docs/ref/#view.EditorView^decorations), with
|
242 | the higher-precedence decorations creating the inner DOM nodes.
|
243 | Such elements are split on line boundaries and on the boundaries
|
244 | of lower-precedence decorations.
|
245 | */
|
246 | static mark(spec: MarkDecorationSpec): Decoration;
|
247 | /**
|
248 | Create a widget decoration, which displays a DOM element at the
|
249 | given position.
|
250 | */
|
251 | static widget(spec: WidgetDecorationSpec): Decoration;
|
252 | /**
|
253 | Create a replace decoration which replaces the given range with
|
254 | a widget, or simply hides it.
|
255 | */
|
256 | static replace(spec: ReplaceDecorationSpec): Decoration;
|
257 | /**
|
258 | Create a line decoration, which can add DOM attributes to the
|
259 | line starting at the given position.
|
260 | */
|
261 | static line(spec: LineDecorationSpec): Decoration;
|
262 | /**
|
263 | Build a [`DecorationSet`](https://codemirror.net/6/docs/ref/#view.DecorationSet) from the given
|
264 | decorated range or ranges. If the ranges aren't already sorted,
|
265 | pass `true` for `sort` to make the library sort them for you.
|
266 | */
|
267 | static set(of: Range<Decoration> | readonly Range<Decoration>[], sort?: boolean): DecorationSet;
|
268 | /**
|
269 | The empty set of decorations.
|
270 | */
|
271 | static none: DecorationSet;
|
272 | }
|
273 |
|
274 | /**
|
275 | Basic rectangle type.
|
276 | */
|
277 | interface Rect {
|
278 | readonly left: number;
|
279 | readonly right: number;
|
280 | readonly top: number;
|
281 | readonly bottom: number;
|
282 | }
|
283 | declare type ScrollStrategy = "nearest" | "start" | "end" | "center";
|
284 |
|
285 | /**
|
286 | Command functions are used in key bindings and other types of user
|
287 | actions. Given an editor view, they check whether their effect can
|
288 | apply to the editor, and if it can, perform it as a side effect
|
289 | (which usually means [dispatching](https://codemirror.net/6/docs/ref/#view.EditorView.dispatch) a
|
290 | transaction) and return `true`.
|
291 | */
|
292 | declare type Command = (target: EditorView) => boolean;
|
293 | /**
|
294 | Log or report an unhandled exception in client code. Should
|
295 | probably only be used by extension code that allows client code to
|
296 | provide functions, and calls those functions in a context where an
|
297 | exception can't be propagated to calling code in a reasonable way
|
298 | (for example when in an event handler).
|
299 |
|
300 | Either calls a handler registered with
|
301 | [`EditorView.exceptionSink`](https://codemirror.net/6/docs/ref/#view.EditorView^exceptionSink),
|
302 | `window.onerror`, if defined, or `console.error` (in which case
|
303 | it'll pass `context`, when given, as first argument).
|
304 | */
|
305 | declare function logException(state: EditorState, exception: any, context?: string): void;
|
306 | /**
|
307 | This is the interface plugin objects conform to.
|
308 | */
|
309 | interface PluginValue extends Object {
|
310 | /**
|
311 | Notifies the plugin of an update that happened in the view. This
|
312 | is called _before_ the view updates its own DOM. It is
|
313 | responsible for updating the plugin's internal state (including
|
314 | any state that may be read by plugin fields) and _writing_ to
|
315 | the DOM for the changes in the update. To avoid unnecessary
|
316 | layout recomputations, it should _not_ read the DOM layout—use
|
317 | [`requestMeasure`](https://codemirror.net/6/docs/ref/#view.EditorView.requestMeasure) to schedule
|
318 | your code in a DOM reading phase if you need to.
|
319 | */
|
320 | update?(update: ViewUpdate): void;
|
321 | /**
|
322 | Called when the plugin is no longer going to be used. Should
|
323 | revert any changes the plugin made to the DOM.
|
324 | */
|
325 | destroy?(): void;
|
326 | }
|
327 | /**
|
328 | Provides additional information when defining a [view
|
329 | plugin](https://codemirror.net/6/docs/ref/#view.ViewPlugin).
|
330 | */
|
331 | interface PluginSpec<V extends PluginValue> {
|
332 | /**
|
333 | Register the given [event
|
334 | handlers](https://codemirror.net/6/docs/ref/#view.EditorView^domEventHandlers) for the plugin.
|
335 | When called, these will have their `this` bound to the plugin
|
336 | value.
|
337 | */
|
338 | eventHandlers?: DOMEventHandlers<V>;
|
339 | /**
|
340 | Specify that the plugin provides additional extensions when
|
341 | added to an editor configuration.
|
342 | */
|
343 | provide?: (plugin: ViewPlugin<V>) => Extension;
|
344 | /**
|
345 | Allow the plugin to provide decorations. When given, this should
|
346 | be a function that take the plugin value and return a
|
347 | [decoration set](https://codemirror.net/6/docs/ref/#view.DecorationSet). See also the caveat about
|
348 | [layout-changing decorations](https://codemirror.net/6/docs/ref/#view.EditorView^decorations) that
|
349 | depend on the view.
|
350 | */
|
351 | decorations?: (value: V) => DecorationSet;
|
352 | }
|
353 | /**
|
354 | View plugins associate stateful values with a view. They can
|
355 | influence the way the content is drawn, and are notified of things
|
356 | that happen in the view.
|
357 | */
|
358 | declare class ViewPlugin<V extends PluginValue> {
|
359 | /**
|
360 | Instances of this class act as extensions.
|
361 | */
|
362 | extension: Extension;
|
363 | private constructor();
|
364 | /**
|
365 | Define a plugin from a constructor function that creates the
|
366 | plugin's value, given an editor view.
|
367 | */
|
368 | static define<V extends PluginValue>(create: (view: EditorView) => V, spec?: PluginSpec<V>): ViewPlugin<V>;
|
369 | /**
|
370 | Create a plugin for a class whose constructor takes a single
|
371 | editor view as argument.
|
372 | */
|
373 | static fromClass<V extends PluginValue>(cls: {
|
374 | new (view: EditorView): V;
|
375 | }, spec?: PluginSpec<V>): ViewPlugin<V>;
|
376 | }
|
377 | interface MeasureRequest<T> {
|
378 | /**
|
379 | Called in a DOM read phase to gather information that requires
|
380 | DOM layout. Should _not_ mutate the document.
|
381 | */
|
382 | read(view: EditorView): T;
|
383 | /**
|
384 | Called in a DOM write phase to update the document. Should _not_
|
385 | do anything that triggers DOM layout.
|
386 | */
|
387 | write?(measure: T, view: EditorView): void;
|
388 | /**
|
389 | When multiple requests with the same key are scheduled, only the
|
390 | last one will actually be ran.
|
391 | */
|
392 | key?: any;
|
393 | }
|
394 | declare type AttrSource = Attrs | ((view: EditorView) => Attrs | null);
|
395 | /**
|
396 | View [plugins](https://codemirror.net/6/docs/ref/#view.ViewPlugin) are given instances of this
|
397 | class, which describe what happened, whenever the view is updated.
|
398 | */
|
399 | declare class ViewUpdate {
|
400 | /**
|
401 | The editor view that the update is associated with.
|
402 | */
|
403 | readonly view: EditorView;
|
404 | /**
|
405 | The new editor state.
|
406 | */
|
407 | readonly state: EditorState;
|
408 | /**
|
409 | The transactions involved in the update. May be empty.
|
410 | */
|
411 | readonly transactions: readonly Transaction[];
|
412 | /**
|
413 | The changes made to the document by this update.
|
414 | */
|
415 | readonly changes: ChangeSet;
|
416 | /**
|
417 | The previous editor state.
|
418 | */
|
419 | readonly startState: EditorState;
|
420 | private constructor();
|
421 | /**
|
422 | Tells you whether the [viewport](https://codemirror.net/6/docs/ref/#view.EditorView.viewport) or
|
423 | [visible ranges](https://codemirror.net/6/docs/ref/#view.EditorView.visibleRanges) changed in this
|
424 | update.
|
425 | */
|
426 | get viewportChanged(): boolean;
|
427 | /**
|
428 | Indicates whether the height of a block element in the editor
|
429 | changed in this update.
|
430 | */
|
431 | get heightChanged(): boolean;
|
432 | /**
|
433 | Returns true when the document was modified or the size of the
|
434 | editor, or elements within the editor, changed.
|
435 | */
|
436 | get geometryChanged(): boolean;
|
437 | /**
|
438 | True when this update indicates a focus change.
|
439 | */
|
440 | get focusChanged(): boolean;
|
441 | /**
|
442 | Whether the document changed in this update.
|
443 | */
|
444 | get docChanged(): boolean;
|
445 | /**
|
446 | Whether the selection was explicitly set in this update.
|
447 | */
|
448 | get selectionSet(): boolean;
|
449 | }
|
450 |
|
451 | /**
|
452 | Interface that objects registered with
|
453 | [`EditorView.mouseSelectionStyle`](https://codemirror.net/6/docs/ref/#view.EditorView^mouseSelectionStyle)
|
454 | must conform to.
|
455 | */
|
456 | interface MouseSelectionStyle {
|
457 | /**
|
458 | Return a new selection for the mouse gesture that starts with
|
459 | the event that was originally given to the constructor, and ends
|
460 | with the event passed here. In case of a plain click, those may
|
461 | both be the `mousedown` event, in case of a drag gesture, the
|
462 | latest `mousemove` event will be passed.
|
463 |
|
464 | When `extend` is true, that means the new selection should, if
|
465 | possible, extend the start selection. If `multiple` is true, the
|
466 | new selection should be added to the original selection.
|
467 | */
|
468 | get: (curEvent: MouseEvent, extend: boolean, multiple: boolean) => EditorSelection;
|
469 | /**
|
470 | Called when the view is updated while the gesture is in
|
471 | progress. When the document changes, it may be necessary to map
|
472 | some data (like the original selection or start position)
|
473 | through the changes.
|
474 |
|
475 | This may return `true` to indicate that the `get` method should
|
476 | get queried again after the update, because something in the
|
477 | update could change its result. Be wary of infinite loops when
|
478 | using this (where `get` returns a new selection, which will
|
479 | trigger `update`, which schedules another `get` in response).
|
480 | */
|
481 | update: (update: ViewUpdate) => boolean | void;
|
482 | }
|
483 | declare type MakeSelectionStyle = (view: EditorView, event: MouseEvent) => MouseSelectionStyle | null;
|
484 |
|
485 | /**
|
486 | Record used to represent information about a block-level element
|
487 | in the editor view.
|
488 | */
|
489 | declare class BlockInfo {
|
490 | /**
|
491 | The start of the element in the document.
|
492 | */
|
493 | readonly from: number;
|
494 | /**
|
495 | The length of the element.
|
496 | */
|
497 | readonly length: number;
|
498 | /**
|
499 | The top position of the element (relative to the top of the
|
500 | document).
|
501 | */
|
502 | readonly top: number;
|
503 | /**
|
504 | Its height.
|
505 | */
|
506 | readonly height: number;
|
507 | /**
|
508 | The type of element this is. When querying lines, this may be
|
509 | an array of all the blocks that make up the line.
|
510 | */
|
511 | readonly type: BlockType | readonly BlockInfo[];
|
512 | /**
|
513 | The end of the element as a document position.
|
514 | */
|
515 | get to(): number;
|
516 | /**
|
517 | The bottom position of the element.
|
518 | */
|
519 | get bottom(): number;
|
520 | }
|
521 |
|
522 | /**
|
523 | Used to indicate [text direction](https://codemirror.net/6/docs/ref/#view.EditorView.textDirection).
|
524 | */
|
525 | declare enum Direction {
|
526 | /**
|
527 | Left-to-right.
|
528 | */
|
529 | LTR = 0,
|
530 | /**
|
531 | Right-to-left.
|
532 | */
|
533 | RTL = 1
|
534 | }
|
535 | /**
|
536 | Represents a contiguous range of text that has a single direction
|
537 | (as in left-to-right or right-to-left).
|
538 | */
|
539 | declare class BidiSpan {
|
540 | /**
|
541 | The start of the span (relative to the start of the line).
|
542 | */
|
543 | readonly from: number;
|
544 | /**
|
545 | The end of the span.
|
546 | */
|
547 | readonly to: number;
|
548 | /**
|
549 | The ["bidi
|
550 | level"](https://unicode.org/reports/tr9/#Basic_Display_Algorithm)
|
551 | of the span (in this context, 0 means
|
552 | left-to-right, 1 means right-to-left, 2 means left-to-right
|
553 | number inside right-to-left text).
|
554 | */
|
555 | readonly level: number;
|
556 | /**
|
557 | The direction of this span.
|
558 | */
|
559 | get dir(): Direction;
|
560 | }
|
561 |
|
562 | /**
|
563 | The type of object given to the [`EditorView`](https://codemirror.net/6/docs/ref/#view.EditorView)
|
564 | constructor.
|
565 | */
|
566 | interface EditorViewConfig extends EditorStateConfig {
|
567 | /**
|
568 | The view's initial state. If not given, a new state is created
|
569 | by passing this configuration object to
|
570 | [`EditorState.create`](https://codemirror.net/6/docs/ref/#state.EditorState^create), using its
|
571 | `doc`, `selection`, and `extensions` field (if provided).
|
572 | */
|
573 | state?: EditorState;
|
574 | /**
|
575 | When given, the editor is immediately appended to the given
|
576 | element on creation. (Otherwise, you'll have to place the view's
|
577 | [`dom`](https://codemirror.net/6/docs/ref/#view.EditorView.dom) element in the document yourself.)
|
578 | */
|
579 | parent?: Element | DocumentFragment;
|
580 | /**
|
581 | If the view is going to be mounted in a shadow root or document
|
582 | other than the one held by the global variable `document` (the
|
583 | default), you should pass it here. If you provide `parent`, but
|
584 | not this option, the editor will automatically look up a root
|
585 | from the parent.
|
586 | */
|
587 | root?: Document | ShadowRoot;
|
588 | /**
|
589 | Override the transaction [dispatch
|
590 | function](https://codemirror.net/6/docs/ref/#view.EditorView.dispatch) for this editor view, which
|
591 | is the way updates get routed to the view. Your implementation,
|
592 | if provided, should probably call the view's [`update`
|
593 | method](https://codemirror.net/6/docs/ref/#view.EditorView.update).
|
594 | */
|
595 | dispatch?: (tr: Transaction) => void;
|
596 | }
|
597 | /**
|
598 | An editor view represents the editor's user interface. It holds
|
599 | the editable DOM surface, and possibly other elements such as the
|
600 | line number gutter. It handles events and dispatches state
|
601 | transactions for editing actions.
|
602 | */
|
603 | declare class EditorView {
|
604 | /**
|
605 | The current editor state.
|
606 | */
|
607 | get state(): EditorState;
|
608 | /**
|
609 | To be able to display large documents without consuming too much
|
610 | memory or overloading the browser, CodeMirror only draws the
|
611 | code that is visible (plus a margin around it) to the DOM. This
|
612 | property tells you the extent of the current drawn viewport, in
|
613 | document positions.
|
614 | */
|
615 | get viewport(): {
|
616 | from: number;
|
617 | to: number;
|
618 | };
|
619 | /**
|
620 | When there are, for example, large collapsed ranges in the
|
621 | viewport, its size can be a lot bigger than the actual visible
|
622 | content. Thus, if you are doing something like styling the
|
623 | content in the viewport, it is preferable to only do so for
|
624 | these ranges, which are the subset of the viewport that is
|
625 | actually drawn.
|
626 | */
|
627 | get visibleRanges(): readonly {
|
628 | from: number;
|
629 | to: number;
|
630 | }[];
|
631 | /**
|
632 | Returns false when the editor is entirely scrolled out of view
|
633 | or otherwise hidden.
|
634 | */
|
635 | get inView(): boolean;
|
636 | /**
|
637 | Indicates whether the user is currently composing text via
|
638 | [IME](https://en.wikipedia.org/wiki/Input_method), and at least
|
639 | one change has been made in the current composition.
|
640 | */
|
641 | get composing(): boolean;
|
642 | /**
|
643 | Indicates whether the user is currently in composing state. Note
|
644 | that on some platforms, like Android, this will be the case a
|
645 | lot, since just putting the cursor on a word starts a
|
646 | composition there.
|
647 | */
|
648 | get compositionStarted(): boolean;
|
649 | private _dispatch;
|
650 | /**
|
651 | The document or shadow root that the view lives in.
|
652 | */
|
653 | readonly root: DocumentOrShadowRoot;
|
654 | /**
|
655 | The DOM element that wraps the entire editor view.
|
656 | */
|
657 | readonly dom: HTMLElement;
|
658 | /**
|
659 | The DOM element that can be styled to scroll. (Note that it may
|
660 | not have been, so you can't assume this is scrollable.)
|
661 | */
|
662 | readonly scrollDOM: HTMLElement;
|
663 | /**
|
664 | The editable DOM element holding the editor content. You should
|
665 | not, usually, interact with this content directly though the
|
666 | DOM, since the editor will immediately undo most of the changes
|
667 | you make. Instead, [dispatch](https://codemirror.net/6/docs/ref/#view.EditorView.dispatch)
|
668 | [transactions](https://codemirror.net/6/docs/ref/#state.Transaction) to modify content, and
|
669 | [decorations](https://codemirror.net/6/docs/ref/#view.Decoration) to style it.
|
670 | */
|
671 | readonly contentDOM: HTMLElement;
|
672 | private announceDOM;
|
673 | private plugins;
|
674 | private pluginMap;
|
675 | private editorAttrs;
|
676 | private contentAttrs;
|
677 | private styleModules;
|
678 | private bidiCache;
|
679 | private destroyed;
|
680 | /**
|
681 | Construct a new view. You'll want to either provide a `parent`
|
682 | option, or put `view.dom` into your document after creating a
|
683 | view, so that the user can see the editor.
|
684 | */
|
685 | constructor(config?: EditorViewConfig);
|
686 | /**
|
687 | All regular editor state updates should go through this. It
|
688 | takes a transaction or transaction spec and updates the view to
|
689 | show the new state produced by that transaction. Its
|
690 | implementation can be overridden with an
|
691 | [option](https://codemirror.net/6/docs/ref/#view.EditorView.constructor^config.dispatch). This
|
692 | function is bound to the view instance, so it does not have to
|
693 | be called as a method.
|
694 | */
|
695 | dispatch(tr: Transaction): void;
|
696 | dispatch(...specs: TransactionSpec[]): void;
|
697 | /**
|
698 | Update the view for the given array of transactions. This will
|
699 | update the visible document and selection to match the state
|
700 | produced by the transactions, and notify view plugins of the
|
701 | change. You should usually call
|
702 | [`dispatch`](https://codemirror.net/6/docs/ref/#view.EditorView.dispatch) instead, which uses this
|
703 | as a primitive.
|
704 | */
|
705 | update(transactions: readonly Transaction[]): void;
|
706 | /**
|
707 | Reset the view to the given state. (This will cause the entire
|
708 | document to be redrawn and all view plugins to be reinitialized,
|
709 | so you should probably only use it when the new state isn't
|
710 | derived from the old state. Otherwise, use
|
711 | [`dispatch`](https://codemirror.net/6/docs/ref/#view.EditorView.dispatch) instead.)
|
712 | */
|
713 | setState(newState: EditorState): void;
|
714 | private updatePlugins;
|
715 | /**
|
716 | Get the CSS classes for the currently active editor themes.
|
717 | */
|
718 | get themeClasses(): string;
|
719 | private updateAttrs;
|
720 | private showAnnouncements;
|
721 | private mountStyles;
|
722 | private readMeasured;
|
723 | /**
|
724 | Schedule a layout measurement, optionally providing callbacks to
|
725 | do custom DOM measuring followed by a DOM write phase. Using
|
726 | this is preferable reading DOM layout directly from, for
|
727 | example, an event handler, because it'll make sure measuring and
|
728 | drawing done by other components is synchronized, avoiding
|
729 | unnecessary DOM layout computations.
|
730 | */
|
731 | requestMeasure<T>(request?: MeasureRequest<T>): void;
|
732 | /**
|
733 | Get the value of a specific plugin, if present. Note that
|
734 | plugins that crash can be dropped from a view, so even when you
|
735 | know you registered a given plugin, it is recommended to check
|
736 | the return value of this method.
|
737 | */
|
738 | plugin<T>(plugin: ViewPlugin<T>): T | null;
|
739 | /**
|
740 | The top position of the document, in screen coordinates. This
|
741 | may be negative when the editor is scrolled down. Points
|
742 | directly to the top of the first line, not above the padding.
|
743 | */
|
744 | get documentTop(): number;
|
745 | /**
|
746 | Reports the padding above and below the document.
|
747 | */
|
748 | get documentPadding(): {
|
749 | top: number;
|
750 | bottom: number;
|
751 | };
|
752 | /**
|
753 | Find the text line or block widget at the given vertical
|
754 | position (which is interpreted as relative to the [top of the
|
755 | document](https://codemirror.net/6/docs/ref/#view.EditorView.documentTop)
|
756 | */
|
757 | elementAtHeight(height: number): BlockInfo;
|
758 | /**
|
759 | Find the line block (see
|
760 | [`lineBlockAt`](https://codemirror.net/6/docs/ref/#view.EditorView.lineBlockAt) at the given
|
761 | height.
|
762 | */
|
763 | lineBlockAtHeight(height: number): BlockInfo;
|
764 | /**
|
765 | Get the extent and vertical position of all [line
|
766 | blocks](https://codemirror.net/6/docs/ref/#view.EditorView.lineBlockAt) in the viewport. Positions
|
767 | are relative to the [top of the
|
768 | document](https://codemirror.net/6/docs/ref/#view.EditorView.documentTop);
|
769 | */
|
770 | get viewportLineBlocks(): BlockInfo[];
|
771 | /**
|
772 | Find the line block around the given document position. A line
|
773 | block is a range delimited on both sides by either a
|
774 | non-[hidden](https://codemirror.net/6/docs/ref/#view.Decoration^replace) line breaks, or the
|
775 | start/end of the document. It will usually just hold a line of
|
776 | text, but may be broken into multiple textblocks by block
|
777 | widgets.
|
778 | */
|
779 | lineBlockAt(pos: number): BlockInfo;
|
780 | /**
|
781 | The editor's total content height.
|
782 | */
|
783 | get contentHeight(): number;
|
784 | /**
|
785 | Move a cursor position by [grapheme
|
786 | cluster](https://codemirror.net/6/docs/ref/#state.findClusterBreak). `forward` determines whether
|
787 | the motion is away from the line start, or towards it. In
|
788 | bidirectional text, the line is traversed in visual order, using
|
789 | the editor's [text direction](https://codemirror.net/6/docs/ref/#view.EditorView.textDirection).
|
790 | When the start position was the last one on the line, the
|
791 | returned position will be across the line break. If there is no
|
792 | further line, the original position is returned.
|
793 |
|
794 | By default, this method moves over a single cluster. The
|
795 | optional `by` argument can be used to move across more. It will
|
796 | be called with the first cluster as argument, and should return
|
797 | a predicate that determines, for each subsequent cluster,
|
798 | whether it should also be moved over.
|
799 | */
|
800 | moveByChar(start: SelectionRange, forward: boolean, by?: (initial: string) => (next: string) => boolean): SelectionRange;
|
801 | /**
|
802 | Move a cursor position across the next group of either
|
803 | [letters](https://codemirror.net/6/docs/ref/#state.EditorState.charCategorizer) or non-letter
|
804 | non-whitespace characters.
|
805 | */
|
806 | moveByGroup(start: SelectionRange, forward: boolean): SelectionRange;
|
807 | /**
|
808 | Move to the next line boundary in the given direction. If
|
809 | `includeWrap` is true, line wrapping is on, and there is a
|
810 | further wrap point on the current line, the wrap point will be
|
811 | returned. Otherwise this function will return the start or end
|
812 | of the line.
|
813 | */
|
814 | moveToLineBoundary(start: SelectionRange, forward: boolean, includeWrap?: boolean): SelectionRange;
|
815 | /**
|
816 | Move a cursor position vertically. When `distance` isn't given,
|
817 | it defaults to moving to the next line (including wrapped
|
818 | lines). Otherwise, `distance` should provide a positive distance
|
819 | in pixels.
|
820 |
|
821 | When `start` has a
|
822 | [`goalColumn`](https://codemirror.net/6/docs/ref/#state.SelectionRange.goalColumn), the vertical
|
823 | motion will use that as a target horizontal position. Otherwise,
|
824 | the cursor's own horizontal position is used. The returned
|
825 | cursor will have its goal column set to whichever column was
|
826 | used.
|
827 | */
|
828 | moveVertically(start: SelectionRange, forward: boolean, distance?: number): SelectionRange;
|
829 | /**
|
830 | Find the DOM parent node and offset (child offset if `node` is
|
831 | an element, character offset when it is a text node) at the
|
832 | given document position.
|
833 |
|
834 | Note that for positions that aren't currently in
|
835 | `visibleRanges`, the resulting DOM position isn't necessarily
|
836 | meaningful (it may just point before or after a placeholder
|
837 | element).
|
838 | */
|
839 | domAtPos(pos: number): {
|
840 | node: Node;
|
841 | offset: number;
|
842 | };
|
843 | /**
|
844 | Find the document position at the given DOM node. Can be useful
|
845 | for associating positions with DOM events. Will raise an error
|
846 | when `node` isn't part of the editor content.
|
847 | */
|
848 | posAtDOM(node: Node, offset?: number): number;
|
849 | /**
|
850 | Get the document position at the given screen coordinates. For
|
851 | positions not covered by the visible viewport's DOM structure,
|
852 | this will return null, unless `false` is passed as second
|
853 | argument, in which case it'll return an estimated position that
|
854 | would be near the coordinates if it were rendered.
|
855 | */
|
856 | posAtCoords(coords: {
|
857 | x: number;
|
858 | y: number;
|
859 | }, precise: false): number;
|
860 | posAtCoords(coords: {
|
861 | x: number;
|
862 | y: number;
|
863 | }): number | null;
|
864 | /**
|
865 | Get the screen coordinates at the given document position.
|
866 | `side` determines whether the coordinates are based on the
|
867 | element before (-1) or after (1) the position (if no element is
|
868 | available on the given side, the method will transparently use
|
869 | another strategy to get reasonable coordinates).
|
870 | */
|
871 | coordsAtPos(pos: number, side?: -1 | 1): Rect | null;
|
872 | /**
|
873 | The default width of a character in the editor. May not
|
874 | accurately reflect the width of all characters (given variable
|
875 | width fonts or styling of invididual ranges).
|
876 | */
|
877 | get defaultCharacterWidth(): number;
|
878 | /**
|
879 | The default height of a line in the editor. May not be accurate
|
880 | for all lines.
|
881 | */
|
882 | get defaultLineHeight(): number;
|
883 | /**
|
884 | The text direction
|
885 | ([`direction`](https://developer.mozilla.org/en-US/docs/Web/CSS/direction)
|
886 | CSS property) of the editor's content element.
|
887 | */
|
888 | get textDirection(): Direction;
|
889 | /**
|
890 | Find the text direction of the block at the given position, as
|
891 | assigned by CSS. If
|
892 | [`perLineTextDirection`](https://codemirror.net/6/docs/ref/#view.EditorView^perLineTextDirection)
|
893 | isn't enabled, or the given position is outside of the viewport,
|
894 | this will always return the same as
|
895 | [`textDirection`](https://codemirror.net/6/docs/ref/#view.EditorView.textDirection). Note that
|
896 | this may trigger a DOM layout.
|
897 | */
|
898 | textDirectionAt(pos: number): Direction;
|
899 | /**
|
900 | Whether this editor [wraps lines](https://codemirror.net/6/docs/ref/#view.EditorView.lineWrapping)
|
901 | (as determined by the
|
902 | [`white-space`](https://developer.mozilla.org/en-US/docs/Web/CSS/white-space)
|
903 | CSS property of its content element).
|
904 | */
|
905 | get lineWrapping(): boolean;
|
906 | /**
|
907 | Returns the bidirectional text structure of the given line
|
908 | (which should be in the current document) as an array of span
|
909 | objects. The order of these spans matches the [text
|
910 | direction](https://codemirror.net/6/docs/ref/#view.EditorView.textDirection)—if that is
|
911 | left-to-right, the leftmost spans come first, otherwise the
|
912 | rightmost spans come first.
|
913 | */
|
914 | bidiSpans(line: Line): readonly BidiSpan[];
|
915 | /**
|
916 | Check whether the editor has focus.
|
917 | */
|
918 | get hasFocus(): boolean;
|
919 | /**
|
920 | Put focus on the editor.
|
921 | */
|
922 | focus(): void;
|
923 | /**
|
924 | Clean up this editor view, removing its element from the
|
925 | document, unregistering event handlers, and notifying
|
926 | plugins. The view instance can no longer be used after
|
927 | calling this.
|
928 | */
|
929 | destroy(): void;
|
930 | /**
|
931 | Returns an effect that can be
|
932 | [added](https://codemirror.net/6/docs/ref/#state.TransactionSpec.effects) to a transaction to
|
933 | cause it to scroll the given position or range into view.
|
934 | */
|
935 | static scrollIntoView(pos: number | SelectionRange, options?: {
|
936 | /**
|
937 | By default (`"nearest"`) the position will be vertically
|
938 | scrolled only the minimal amount required to move the given
|
939 | position into view. You can set this to `"start"` to move it
|
940 | to the top of the view, `"end"` to move it to the bottom, or
|
941 | `"center"` to move it to the center.
|
942 | */
|
943 | y?: ScrollStrategy;
|
944 | /**
|
945 | Effect similar to
|
946 | [`y`](https://codemirror.net/6/docs/ref/#view.EditorView^scrollIntoView^options.y), but for the
|
947 | horizontal scroll position.
|
948 | */
|
949 | x?: ScrollStrategy;
|
950 | /**
|
951 | Extra vertical distance to add when moving something into
|
952 | view. Not used with the `"center"` strategy. Defaults to 5.
|
953 | */
|
954 | yMargin?: number;
|
955 | /**
|
956 | Extra horizontal distance to add. Not used with the `"center"`
|
957 | strategy. Defaults to 5.
|
958 | */
|
959 | xMargin?: number;
|
960 | }): StateEffect<unknown>;
|
961 | /**
|
962 | Facet to add a [style
|
963 | module](https://github.com/marijnh/style-mod#documentation) to
|
964 | an editor view. The view will ensure that the module is
|
965 | mounted in its [document
|
966 | root](https://codemirror.net/6/docs/ref/#view.EditorView.constructor^config.root).
|
967 | */
|
968 | static styleModule: Facet<StyleModule, readonly StyleModule[]>;
|
969 | /**
|
970 | Returns an extension that can be used to add DOM event handlers.
|
971 | The value should be an object mapping event names to handler
|
972 | functions. For any given event, such functions are ordered by
|
973 | extension precedence, and the first handler to return true will
|
974 | be assumed to have handled that event, and no other handlers or
|
975 | built-in behavior will be activated for it. These are registered
|
976 | on the [content element](https://codemirror.net/6/docs/ref/#view.EditorView.contentDOM), except
|
977 | for `scroll` handlers, which will be called any time the
|
978 | editor's [scroll element](https://codemirror.net/6/docs/ref/#view.EditorView.scrollDOM) or one of
|
979 | its parent nodes is scrolled.
|
980 | */
|
981 | static domEventHandlers(handlers: DOMEventHandlers<any>): Extension;
|
982 | /**
|
983 | An input handler can override the way changes to the editable
|
984 | DOM content are handled. Handlers are passed the document
|
985 | positions between which the change was found, and the new
|
986 | content. When one returns true, no further input handlers are
|
987 | called and the default behavior is prevented.
|
988 | */
|
989 | static inputHandler: Facet<(view: EditorView, from: number, to: number, text: string) => boolean, readonly ((view: EditorView, from: number, to: number, text: string) => boolean)[]>;
|
990 | /**
|
991 | By default, the editor assumes all its content has the same
|
992 | [text direction](https://codemirror.net/6/docs/ref/#view.Direction). Configure this with a `true`
|
993 | value to make it read the text direction of every (rendered)
|
994 | line separately.
|
995 | */
|
996 | static perLineTextDirection: Facet<boolean, boolean>;
|
997 | /**
|
998 | Allows you to provide a function that should be called when the
|
999 | library catches an exception from an extension (mostly from view
|
1000 | plugins, but may be used by other extensions to route exceptions
|
1001 | from user-code-provided callbacks). This is mostly useful for
|
1002 | debugging and logging. See [`logException`](https://codemirror.net/6/docs/ref/#view.logException).
|
1003 | */
|
1004 | static exceptionSink: Facet<(exception: any) => void, readonly ((exception: any) => void)[]>;
|
1005 | /**
|
1006 | A facet that can be used to register a function to be called
|
1007 | every time the view updates.
|
1008 | */
|
1009 | static updateListener: Facet<(update: ViewUpdate) => void, readonly ((update: ViewUpdate) => void)[]>;
|
1010 | /**
|
1011 | Facet that controls whether the editor content DOM is editable.
|
1012 | When its highest-precedence value is `false`, the element will
|
1013 | not have its `contenteditable` attribute set. (Note that this
|
1014 | doesn't affect API calls that change the editor content, even
|
1015 | when those are bound to keys or buttons. See the
|
1016 | [`readOnly`](https://codemirror.net/6/docs/ref/#state.EditorState.readOnly) facet for that.)
|
1017 | */
|
1018 | static editable: Facet<boolean, boolean>;
|
1019 | /**
|
1020 | Allows you to influence the way mouse selection happens. The
|
1021 | functions in this facet will be called for a `mousedown` event
|
1022 | on the editor, and can return an object that overrides the way a
|
1023 | selection is computed from that mouse click or drag.
|
1024 | */
|
1025 | static mouseSelectionStyle: Facet<MakeSelectionStyle, readonly MakeSelectionStyle[]>;
|
1026 | /**
|
1027 | Facet used to configure whether a given selection drag event
|
1028 | should move or copy the selection. The given predicate will be
|
1029 | called with the `mousedown` event, and can return `true` when
|
1030 | the drag should move the content.
|
1031 | */
|
1032 | static dragMovesSelection: Facet<(event: MouseEvent) => boolean, readonly ((event: MouseEvent) => boolean)[]>;
|
1033 | /**
|
1034 | Facet used to configure whether a given selecting click adds a
|
1035 | new range to the existing selection or replaces it entirely. The
|
1036 | default behavior is to check `event.metaKey` on macOS, and
|
1037 | `event.ctrlKey` elsewhere.
|
1038 | */
|
1039 | static clickAddsSelectionRange: Facet<(event: MouseEvent) => boolean, readonly ((event: MouseEvent) => boolean)[]>;
|
1040 | /**
|
1041 | A facet that determines which [decorations](https://codemirror.net/6/docs/ref/#view.Decoration)
|
1042 | are shown in the view. Decorations can be provided in two
|
1043 | ways—directly, or via a function that takes an editor view.
|
1044 |
|
1045 | Only decoration sets provided directly are allowed to influence
|
1046 | the editor's vertical layout structure. The ones provided as
|
1047 | functions are called _after_ the new viewport has been computed,
|
1048 | and thus **must not** introduce block widgets or replacing
|
1049 | decorations that cover line breaks.
|
1050 | */
|
1051 | static decorations: Facet<DecorationSet | ((view: EditorView) => DecorationSet), readonly (DecorationSet | ((view: EditorView) => DecorationSet))[]>;
|
1052 | /**
|
1053 | Used to provide ranges that should be treated as atoms as far as
|
1054 | cursor motion is concerned. This causes methods like
|
1055 | [`moveByChar`](https://codemirror.net/6/docs/ref/#view.EditorView.moveByChar) and
|
1056 | [`moveVertically`](https://codemirror.net/6/docs/ref/#view.EditorView.moveVertically) (and the
|
1057 | commands built on top of them) to skip across such regions when
|
1058 | a selection endpoint would enter them. This does _not_ prevent
|
1059 | direct programmatic [selection
|
1060 | updates](https://codemirror.net/6/docs/ref/#state.TransactionSpec.selection) from moving into such
|
1061 | regions.
|
1062 | */
|
1063 | static atomicRanges: Facet<(view: EditorView) => _codemirror_state.RangeSet<any>, readonly ((view: EditorView) => _codemirror_state.RangeSet<any>)[]>;
|
1064 | /**
|
1065 | Facet that allows extensions to provide additional scroll
|
1066 | margins (space around the sides of the scrolling element that
|
1067 | should be considered invisible). This can be useful when the
|
1068 | plugin introduces elements that cover part of that element (for
|
1069 | example a horizontally fixed gutter).
|
1070 | */
|
1071 | static scrollMargins: Facet<(view: EditorView) => Partial<Rect> | null, readonly ((view: EditorView) => Partial<Rect> | null)[]>;
|
1072 | /**
|
1073 | Create a theme extension. The first argument can be a
|
1074 | [`style-mod`](https://github.com/marijnh/style-mod#documentation)
|
1075 | style spec providing the styles for the theme. These will be
|
1076 | prefixed with a generated class for the style.
|
1077 |
|
1078 | Because the selectors will be prefixed with a scope class, rule
|
1079 | that directly match the editor's [wrapper
|
1080 | element](https://codemirror.net/6/docs/ref/#view.EditorView.dom)—to which the scope class will be
|
1081 | added—need to be explicitly differentiated by adding an `&` to
|
1082 | the selector for that element—for example
|
1083 | `&.cm-focused`.
|
1084 |
|
1085 | When `dark` is set to true, the theme will be marked as dark,
|
1086 | which will cause the `&dark` rules from [base
|
1087 | themes](https://codemirror.net/6/docs/ref/#view.EditorView^baseTheme) to be used (as opposed to
|
1088 | `&light` when a light theme is active).
|
1089 | */
|
1090 | static theme(spec: {
|
1091 | [selector: string]: StyleSpec;
|
1092 | }, options?: {
|
1093 | dark?: boolean;
|
1094 | }): Extension;
|
1095 | /**
|
1096 | This facet records whether a dark theme is active. The extension
|
1097 | returned by [`theme`](https://codemirror.net/6/docs/ref/#view.EditorView^theme) automatically
|
1098 | includes an instance of this when the `dark` option is set to
|
1099 | true.
|
1100 | */
|
1101 | static darkTheme: Facet<boolean, boolean>;
|
1102 | /**
|
1103 | Create an extension that adds styles to the base theme. Like
|
1104 | with [`theme`](https://codemirror.net/6/docs/ref/#view.EditorView^theme), use `&` to indicate the
|
1105 | place of the editor wrapper element when directly targeting
|
1106 | that. You can also use `&dark` or `&light` instead to only
|
1107 | target editors with a dark or light theme.
|
1108 | */
|
1109 | static baseTheme(spec: {
|
1110 | [selector: string]: StyleSpec;
|
1111 | }): Extension;
|
1112 | /**
|
1113 | Facet that provides additional DOM attributes for the editor's
|
1114 | editable DOM element.
|
1115 | */
|
1116 | static contentAttributes: Facet<AttrSource, readonly AttrSource[]>;
|
1117 | /**
|
1118 | Facet that provides DOM attributes for the editor's outer
|
1119 | element.
|
1120 | */
|
1121 | static editorAttributes: Facet<AttrSource, readonly AttrSource[]>;
|
1122 | /**
|
1123 | An extension that enables line wrapping in the editor (by
|
1124 | setting CSS `white-space` to `pre-wrap` in the content).
|
1125 | */
|
1126 | static lineWrapping: Extension;
|
1127 | /**
|
1128 | State effect used to include screen reader announcements in a
|
1129 | transaction. These will be added to the DOM in a visually hidden
|
1130 | element with `aria-live="polite"` set, and should be used to
|
1131 | describe effects that are visually obvious but may not be
|
1132 | noticed by screen reader users (such as moving to the next
|
1133 | search match).
|
1134 | */
|
1135 | static announce: _codemirror_state.StateEffectType<string>;
|
1136 | /**
|
1137 | Retrieve an editor view instance from the view's DOM
|
1138 | representation.
|
1139 | */
|
1140 | static findFromDOM(dom: HTMLElement): EditorView | null;
|
1141 | }
|
1142 | /**
|
1143 | Helper type that maps event names to event object types, or the
|
1144 | `any` type for unknown events.
|
1145 | */
|
1146 | interface DOMEventMap extends HTMLElementEventMap {
|
1147 | [other: string]: any;
|
1148 | }
|
1149 | /**
|
1150 | Event handlers are specified with objects like this. For event
|
1151 | types known by TypeScript, this will infer the event argument type
|
1152 | to hold the appropriate event object type. For unknown events, it
|
1153 | is inferred to `any`, and should be explicitly set if you want type
|
1154 | checking.
|
1155 | */
|
1156 | declare type DOMEventHandlers<This> = {
|
1157 | [event in keyof DOMEventMap]?: (this: This, event: DOMEventMap[event], view: EditorView) => boolean | void;
|
1158 | };
|
1159 |
|
1160 | /**
|
1161 | Key bindings associate key names with
|
1162 | [command](https://codemirror.net/6/docs/ref/#view.Command)-style functions.
|
1163 |
|
1164 | Key names may be strings like `"Shift-Ctrl-Enter"`—a key identifier
|
1165 | prefixed with zero or more modifiers. Key identifiers are based on
|
1166 | the strings that can appear in
|
1167 | [`KeyEvent.key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key).
|
1168 | Use lowercase letters to refer to letter keys (or uppercase letters
|
1169 | if you want shift to be held). You may use `"Space"` as an alias
|
1170 | for the `" "` name.
|
1171 |
|
1172 | Modifiers can be given in any order. `Shift-` (or `s-`), `Alt-` (or
|
1173 | `a-`), `Ctrl-` (or `c-` or `Control-`) and `Cmd-` (or `m-` or
|
1174 | `Meta-`) are recognized.
|
1175 |
|
1176 | When a key binding contains multiple key names separated by
|
1177 | spaces, it represents a multi-stroke binding, which will fire when
|
1178 | the user presses the given keys after each other.
|
1179 |
|
1180 | You can use `Mod-` as a shorthand for `Cmd-` on Mac and `Ctrl-` on
|
1181 | other platforms. So `Mod-b` is `Ctrl-b` on Linux but `Cmd-b` on
|
1182 | macOS.
|
1183 | */
|
1184 | interface KeyBinding {
|
1185 | /**
|
1186 | The key name to use for this binding. If the platform-specific
|
1187 | property (`mac`, `win`, or `linux`) for the current platform is
|
1188 | used as well in the binding, that one takes precedence. If `key`
|
1189 | isn't defined and the platform-specific binding isn't either,
|
1190 | a binding is ignored.
|
1191 | */
|
1192 | key?: string;
|
1193 | /**
|
1194 | Key to use specifically on macOS.
|
1195 | */
|
1196 | mac?: string;
|
1197 | /**
|
1198 | Key to use specifically on Windows.
|
1199 | */
|
1200 | win?: string;
|
1201 | /**
|
1202 | Key to use specifically on Linux.
|
1203 | */
|
1204 | linux?: string;
|
1205 | /**
|
1206 | The command to execute when this binding is triggered. When the
|
1207 | command function returns `false`, further bindings will be tried
|
1208 | for the key.
|
1209 | */
|
1210 | run: Command;
|
1211 | /**
|
1212 | When given, this defines a second binding, using the (possibly
|
1213 | platform-specific) key name prefixed with `Shift-` to activate
|
1214 | this command.
|
1215 | */
|
1216 | shift?: Command;
|
1217 | /**
|
1218 | By default, key bindings apply when focus is on the editor
|
1219 | content (the `"editor"` scope). Some extensions, mostly those
|
1220 | that define their own panels, might want to allow you to
|
1221 | register bindings local to that panel. Such bindings should use
|
1222 | a custom scope name. You may also assign multiple scope names to
|
1223 | a binding, separating them by spaces.
|
1224 | */
|
1225 | scope?: string;
|
1226 | /**
|
1227 | When set to true (the default is false), this will always
|
1228 | prevent the further handling for the bound key, even if the
|
1229 | command(s) return false. This can be useful for cases where the
|
1230 | native behavior of the key is annoying or irrelevant but the
|
1231 | command doesn't always apply (such as, Mod-u for undo selection,
|
1232 | which would cause the browser to view source instead when no
|
1233 | selection can be undone).
|
1234 | */
|
1235 | preventDefault?: boolean;
|
1236 | }
|
1237 | /**
|
1238 | Facet used for registering keymaps.
|
1239 |
|
1240 | You can add multiple keymaps to an editor. Their priorities
|
1241 | determine their precedence (the ones specified early or with high
|
1242 | priority get checked first). When a handler has returned `true`
|
1243 | for a given key, no further handlers are called.
|
1244 | */
|
1245 | declare const keymap: Facet<readonly KeyBinding[], readonly (readonly KeyBinding[])[]>;
|
1246 | /**
|
1247 | Run the key handlers registered for a given scope. The event
|
1248 | object should be a `"keydown"` event. Returns true if any of the
|
1249 | handlers handled it.
|
1250 | */
|
1251 | declare function runScopeHandlers(view: EditorView, event: KeyboardEvent, scope: string): boolean;
|
1252 |
|
1253 | declare type SelectionConfig = {
|
1254 | /**
|
1255 | The length of a full cursor blink cycle, in milliseconds.
|
1256 | Defaults to 1200. Can be set to 0 to disable blinking.
|
1257 | */
|
1258 | cursorBlinkRate?: number;
|
1259 | /**
|
1260 | Whether to show a cursor for non-empty ranges. Defaults to
|
1261 | true.
|
1262 | */
|
1263 | drawRangeCursor?: boolean;
|
1264 | };
|
1265 | /**
|
1266 | Returns an extension that hides the browser's native selection and
|
1267 | cursor, replacing the selection with a background behind the text
|
1268 | (with the `cm-selectionBackground` class), and the
|
1269 | cursors with elements overlaid over the code (using
|
1270 | `cm-cursor-primary` and `cm-cursor-secondary`).
|
1271 |
|
1272 | This allows the editor to display secondary selection ranges, and
|
1273 | tends to produce a type of selection more in line with that users
|
1274 | expect in a text editor (the native selection styling will often
|
1275 | leave gaps between lines and won't fill the horizontal space after
|
1276 | a line when the selection continues past it).
|
1277 |
|
1278 | It does have a performance cost, in that it requires an extra DOM
|
1279 | layout cycle for many updates (the selection is drawn based on DOM
|
1280 | layout information that's only available after laying out the
|
1281 | content).
|
1282 | */
|
1283 | declare function drawSelection(config?: SelectionConfig): Extension;
|
1284 |
|
1285 | /**
|
1286 | Draws a cursor at the current drop position when something is
|
1287 | dragged over the editor.
|
1288 | */
|
1289 | declare function dropCursor(): Extension;
|
1290 |
|
1291 | interface SpecialCharConfig {
|
1292 | /**
|
1293 | An optional function that renders the placeholder elements.
|
1294 |
|
1295 | The `description` argument will be text that clarifies what the
|
1296 | character is, which should be provided to screen readers (for
|
1297 | example with the
|
1298 | [`aria-label`](https://www.w3.org/TR/wai-aria/#aria-label)
|
1299 | attribute) and optionally shown to the user in other ways (such
|
1300 | as the
|
1301 | [`title`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/title)
|
1302 | attribute).
|
1303 |
|
1304 | The given placeholder string is a suggestion for how to display
|
1305 | the character visually.
|
1306 | */
|
1307 | render?: ((code: number, description: string | null, placeholder: string) => HTMLElement) | null;
|
1308 | /**
|
1309 | Regular expression that matches the special characters to
|
1310 | highlight. Must have its 'g'/global flag set.
|
1311 | */
|
1312 | specialChars?: RegExp;
|
1313 | /**
|
1314 | Regular expression that can be used to add characters to the
|
1315 | default set of characters to highlight.
|
1316 | */
|
1317 | addSpecialChars?: RegExp | null;
|
1318 | }
|
1319 | /**
|
1320 | Returns an extension that installs highlighting of special
|
1321 | characters.
|
1322 | */
|
1323 | declare function highlightSpecialChars(
|
1324 | /**
|
1325 | Configuration options.
|
1326 | */
|
1327 | config?: SpecialCharConfig): Extension;
|
1328 |
|
1329 | /**
|
1330 | Returns an extension that makes sure the content has a bottom
|
1331 | margin equivalent to the height of the editor, minus one line
|
1332 | height, so that every line in the document can be scrolled to the
|
1333 | top of the editor.
|
1334 |
|
1335 | This is only meaningful when the editor is scrollable, and should
|
1336 | not be enabled in editors that take the size of their content.
|
1337 | */
|
1338 | declare function scrollPastEnd(): Extension;
|
1339 |
|
1340 | /**
|
1341 | Mark lines that have a cursor on them with the `"cm-activeLine"`
|
1342 | DOM class.
|
1343 | */
|
1344 | declare function highlightActiveLine(): Extension;
|
1345 |
|
1346 | /**
|
1347 | Extension that enables a placeholder—a piece of example content
|
1348 | to show when the editor is empty.
|
1349 | */
|
1350 | declare function placeholder(content: string | HTMLElement): Extension;
|
1351 |
|
1352 | /**
|
1353 | Helper class used to make it easier to maintain decorations on
|
1354 | visible code that matches a given regular expression. To be used
|
1355 | in a [view plugin](https://codemirror.net/6/docs/ref/#view.ViewPlugin). Instances of this object
|
1356 | represent a matching configuration.
|
1357 | */
|
1358 | declare class MatchDecorator {
|
1359 | private regexp;
|
1360 | private getDeco;
|
1361 | private boundary;
|
1362 | private maxLength;
|
1363 | /**
|
1364 | Create a decorator.
|
1365 | */
|
1366 | constructor(config: {
|
1367 | /**
|
1368 | The regular expression to match against the content. Will only
|
1369 | be matched inside lines (not across them). Should have its 'g'
|
1370 | flag set.
|
1371 | */
|
1372 | regexp: RegExp;
|
1373 | /**
|
1374 | The decoration to apply to matches, either directly or as a
|
1375 | function of the match.
|
1376 | */
|
1377 | decoration: Decoration | ((match: RegExpExecArray, view: EditorView, pos: number) => Decoration);
|
1378 | /**
|
1379 | By default, changed lines are re-matched entirely. You can
|
1380 | provide a boundary expression, which should match single
|
1381 | character strings that can never occur in `regexp`, to reduce
|
1382 | the amount of re-matching.
|
1383 | */
|
1384 | boundary?: RegExp;
|
1385 | /**
|
1386 | Matching happens by line, by default, but when lines are
|
1387 | folded or very long lines are only partially drawn, the
|
1388 | decorator may avoid matching part of them for speed. This
|
1389 | controls how much additional invisible content it should
|
1390 | include in its matches. Defaults to 1000.
|
1391 | */
|
1392 | maxLength?: number;
|
1393 | });
|
1394 | /**
|
1395 | Compute the full set of decorations for matches in the given
|
1396 | view's viewport. You'll want to call this when initializing your
|
1397 | plugin.
|
1398 | */
|
1399 | createDeco(view: EditorView): _codemirror_state.RangeSet<Decoration>;
|
1400 | /**
|
1401 | Update a set of decorations for a view update. `deco` _must_ be
|
1402 | the set of decorations produced by _this_ `MatchDecorator` for
|
1403 | the view state before the update.
|
1404 | */
|
1405 | updateDeco(update: ViewUpdate, deco: DecorationSet): DecorationSet;
|
1406 | private updateRange;
|
1407 | }
|
1408 |
|
1409 | /**
|
1410 | Create an extension that enables rectangular selections. By
|
1411 | default, it will react to left mouse drag with the Alt key held
|
1412 | down. When such a selection occurs, the text within the rectangle
|
1413 | that was dragged over will be selected, as one selection
|
1414 | [range](https://codemirror.net/6/docs/ref/#state.SelectionRange) per line.
|
1415 | */
|
1416 | declare function rectangularSelection(options?: {
|
1417 | /**
|
1418 | A custom predicate function, which takes a `mousedown` event and
|
1419 | returns true if it should be used for rectangular selection.
|
1420 | */
|
1421 | eventFilter?: (event: MouseEvent) => boolean;
|
1422 | }): Extension;
|
1423 | /**
|
1424 | Returns an extension that turns the pointer cursor into a
|
1425 | crosshair when a given modifier key, defaulting to Alt, is held
|
1426 | down. Can serve as a visual hint that rectangular selection is
|
1427 | going to happen when paired with
|
1428 | [`rectangularSelection`](https://codemirror.net/6/docs/ref/#view.rectangularSelection).
|
1429 | */
|
1430 | declare function crosshairCursor(options?: {
|
1431 | key?: "Alt" | "Control" | "Shift" | "Meta";
|
1432 | }): Extension;
|
1433 |
|
1434 | /**
|
1435 | Creates an extension that configures tooltip behavior.
|
1436 | */
|
1437 | declare function tooltips(config?: {
|
1438 | /**
|
1439 | By default, tooltips use `"fixed"`
|
1440 | [positioning](https://developer.mozilla.org/en-US/docs/Web/CSS/position),
|
1441 | which has the advantage that tooltips don't get cut off by
|
1442 | scrollable parent elements. However, CSS rules like `contain:
|
1443 | layout` can break fixed positioning in child nodes, which can be
|
1444 | worked about by using `"absolute"` here.
|
1445 |
|
1446 | On iOS, which at the time of writing still doesn't properly
|
1447 | support fixed positioning, the library always uses absolute
|
1448 | positioning.
|
1449 | */
|
1450 | position?: "fixed" | "absolute";
|
1451 | /**
|
1452 | The element to put the tooltips into. By default, they are put
|
1453 | in the editor (`cm-editor`) element, and that is usually what
|
1454 | you want. But in some layouts that can lead to positioning
|
1455 | issues, and you need to use a different parent to work around
|
1456 | those.
|
1457 | */
|
1458 | parent?: HTMLElement;
|
1459 | /**
|
1460 | By default, when figuring out whether there is room for a
|
1461 | tooltip at a given position, the extension considers the entire
|
1462 | space between 0,0 and `innerWidth`,`innerHeight` to be available
|
1463 | for showing tooltips. You can provide a function here that
|
1464 | returns an alternative rectangle.
|
1465 | */
|
1466 | tooltipSpace?: (view: EditorView) => {
|
1467 | top: number;
|
1468 | left: number;
|
1469 | bottom: number;
|
1470 | right: number;
|
1471 | };
|
1472 | }): Extension;
|
1473 | /**
|
1474 | Describes a tooltip. Values of this type, when provided through
|
1475 | the [`showTooltip`](https://codemirror.net/6/docs/ref/#view.showTooltip) facet, control the
|
1476 | individual tooltips on the editor.
|
1477 | */
|
1478 | interface Tooltip {
|
1479 | /**
|
1480 | The document position at which to show the tooltip.
|
1481 | */
|
1482 | pos: number;
|
1483 | /**
|
1484 | The end of the range annotated by this tooltip, if different
|
1485 | from `pos`.
|
1486 | */
|
1487 | end?: number;
|
1488 | /**
|
1489 | A constructor function that creates the tooltip's [DOM
|
1490 | representation](https://codemirror.net/6/docs/ref/#view.TooltipView).
|
1491 | */
|
1492 | create(view: EditorView): TooltipView;
|
1493 | /**
|
1494 | Whether the tooltip should be shown above or below the target
|
1495 | position. Not guaranteed to be respected for hover tooltips
|
1496 | since all hover tooltips for the same range are always
|
1497 | positioned together. Defaults to false.
|
1498 | */
|
1499 | above?: boolean;
|
1500 | /**
|
1501 | Whether the `above` option should be honored when there isn't
|
1502 | enough space on that side to show the tooltip inside the
|
1503 | viewport. Defaults to false.
|
1504 | */
|
1505 | strictSide?: boolean;
|
1506 | /**
|
1507 | When set to true, show a triangle connecting the tooltip element
|
1508 | to position `pos`.
|
1509 | */
|
1510 | arrow?: boolean;
|
1511 | }
|
1512 | /**
|
1513 | Describes the way a tooltip is displayed.
|
1514 | */
|
1515 | interface TooltipView {
|
1516 | /**
|
1517 | The DOM element to position over the editor.
|
1518 | */
|
1519 | dom: HTMLElement;
|
1520 | /**
|
1521 | Adjust the position of the tooltip relative to its anchor
|
1522 | position. A positive `x` value will move the tooltip
|
1523 | horizontally along with the text direction (so right in
|
1524 | left-to-right context, left in right-to-left). A positive `y`
|
1525 | will move the tooltip up when it is above its anchor, and down
|
1526 | otherwise.
|
1527 | */
|
1528 | offset?: {
|
1529 | x: number;
|
1530 | y: number;
|
1531 | };
|
1532 | /**
|
1533 | By default, a tooltip's screen position will be based on the
|
1534 | text position of its `pos` property. This method can be provided
|
1535 | to make the tooltip view itself responsible for finding its
|
1536 | screen position.
|
1537 | */
|
1538 | getCoords?: (pos: number) => Rect;
|
1539 | /**
|
1540 | By default, tooltips are moved when they overlap with other
|
1541 | tooltips. Set this to `true` to disable that behavior for this
|
1542 | tooltip.
|
1543 | */
|
1544 | overlap?: boolean;
|
1545 | /**
|
1546 | Called after the tooltip is added to the DOM for the first time.
|
1547 | */
|
1548 | mount?(view: EditorView): void;
|
1549 | /**
|
1550 | Update the DOM element for a change in the view's state.
|
1551 | */
|
1552 | update?(update: ViewUpdate): void;
|
1553 | /**
|
1554 | Called when the tooltip has been (re)positioned.
|
1555 | */
|
1556 | positioned?(): void;
|
1557 | }
|
1558 | /**
|
1559 | Facet to which an extension can add a value to show a tooltip.
|
1560 | */
|
1561 | declare const showTooltip: Facet<Tooltip | null, readonly (Tooltip | null)[]>;
|
1562 | /**
|
1563 | Set up a hover tooltip, which shows up when the pointer hovers
|
1564 | over ranges of text. The callback is called when the mouse hovers
|
1565 | over the document text. It should, if there is a tooltip
|
1566 | associated with position `pos`, return the tooltip description
|
1567 | (either directly or in a promise). The `side` argument indicates
|
1568 | on which side of the position the pointer is—it will be -1 if the
|
1569 | pointer is before the position, 1 if after the position.
|
1570 |
|
1571 | Note that all hover tooltips are hosted within a single tooltip
|
1572 | container element. This allows multiple tooltips over the same
|
1573 | range to be "merged" together without overlapping.
|
1574 | */
|
1575 | declare function hoverTooltip(source: (view: EditorView, pos: number, side: -1 | 1) => Tooltip | null | Promise<Tooltip | null>, options?: {
|
1576 | /**
|
1577 | Controls whether a transaction hides the tooltip. The default
|
1578 | is to not hide.
|
1579 | */
|
1580 | hideOn?: (tr: Transaction, tooltip: Tooltip) => boolean;
|
1581 | /**
|
1582 | When enabled (this defaults to false), close the tooltip
|
1583 | whenever the document changes or the selection is set.
|
1584 | */
|
1585 | hideOnChange?: boolean | "touch";
|
1586 | /**
|
1587 | Hover time after which the tooltip should appear, in
|
1588 | milliseconds. Defaults to 300ms.
|
1589 | */
|
1590 | hoverTime?: number;
|
1591 | }): Extension;
|
1592 | /**
|
1593 | Get the active tooltip view for a given tooltip, if available.
|
1594 | */
|
1595 | declare function getTooltip(view: EditorView, tooltip: Tooltip): TooltipView | null;
|
1596 | /**
|
1597 | Returns true if any hover tooltips are currently active.
|
1598 | */
|
1599 | declare function hasHoverTooltips(state: EditorState): boolean;
|
1600 | /**
|
1601 | Transaction effect that closes all hover tooltips.
|
1602 | */
|
1603 | declare const closeHoverTooltips: StateEffect<null>;
|
1604 | /**
|
1605 | Tell the tooltip extension to recompute the position of the active
|
1606 | tooltips. This can be useful when something happens (such as a
|
1607 | re-positioning or CSS change affecting the editor) that could
|
1608 | invalidate the existing tooltip positions.
|
1609 | */
|
1610 | declare function repositionTooltips(view: EditorView): void;
|
1611 |
|
1612 | declare type PanelConfig = {
|
1613 | /**
|
1614 | By default, panels will be placed inside the editor's DOM
|
1615 | structure. You can use this option to override where panels with
|
1616 | `top: true` are placed.
|
1617 | */
|
1618 | topContainer?: HTMLElement;
|
1619 | /**
|
1620 | Override where panels with `top: false` are placed.
|
1621 | */
|
1622 | bottomContainer?: HTMLElement;
|
1623 | };
|
1624 | /**
|
1625 | Configures the panel-managing extension.
|
1626 | */
|
1627 | declare function panels(config?: PanelConfig): Extension;
|
1628 | /**
|
1629 | Object that describes an active panel.
|
1630 | */
|
1631 | interface Panel {
|
1632 | /**
|
1633 | The element representing this panel. The library will add the
|
1634 | `"cm-panel"` DOM class to this.
|
1635 | */
|
1636 | dom: HTMLElement;
|
1637 | /**
|
1638 | Optionally called after the panel has been added to the editor.
|
1639 | */
|
1640 | mount?(): void;
|
1641 | /**
|
1642 | Update the DOM for a given view update.
|
1643 | */
|
1644 | update?(update: ViewUpdate): void;
|
1645 | /**
|
1646 | Called when the panel is removed from the editor or the editor
|
1647 | is destroyed.
|
1648 | */
|
1649 | destroy?(): void;
|
1650 | /**
|
1651 | Whether the panel should be at the top or bottom of the editor.
|
1652 | Defaults to false.
|
1653 | */
|
1654 | top?: boolean;
|
1655 | }
|
1656 | /**
|
1657 | Get the active panel created by the given constructor, if any.
|
1658 | This can be useful when you need access to your panels' DOM
|
1659 | structure.
|
1660 | */
|
1661 | declare function getPanel(view: EditorView, panel: PanelConstructor): Panel | null;
|
1662 | /**
|
1663 | A function that initializes a panel. Used in
|
1664 | [`showPanel`](https://codemirror.net/6/docs/ref/#view.showPanel).
|
1665 | */
|
1666 | declare type PanelConstructor = (view: EditorView) => Panel;
|
1667 | /**
|
1668 | Opening a panel is done by providing a constructor function for
|
1669 | the panel through this facet. (The panel is closed again when its
|
1670 | constructor is no longer provided.) Values of `null` are ignored.
|
1671 | */
|
1672 | declare const showPanel: Facet<PanelConstructor | null, readonly (PanelConstructor | null)[]>;
|
1673 |
|
1674 | /**
|
1675 | A gutter marker represents a bit of information attached to a line
|
1676 | in a specific gutter. Your own custom markers have to extend this
|
1677 | class.
|
1678 | */
|
1679 | declare abstract class GutterMarker extends RangeValue {
|
1680 | /**
|
1681 | Compare this marker to another marker of the same type.
|
1682 | */
|
1683 | eq(other: GutterMarker): boolean;
|
1684 | /**
|
1685 | Render the DOM node for this marker, if any.
|
1686 | */
|
1687 | toDOM?(view: EditorView): Node;
|
1688 | /**
|
1689 | This property can be used to add CSS classes to the gutter
|
1690 | element that contains this marker.
|
1691 | */
|
1692 | elementClass: string;
|
1693 | /**
|
1694 | Called if the marker has a `toDOM` method and its representation
|
1695 | was removed from a gutter.
|
1696 | */
|
1697 | destroy(dom: Node): void;
|
1698 | }
|
1699 | /**
|
1700 | Facet used to add a class to all gutter elements for a given line.
|
1701 | Markers given to this facet should _only_ define an
|
1702 | [`elementclass`](https://codemirror.net/6/docs/ref/#view.GutterMarker.elementClass), not a
|
1703 | [`toDOM`](https://codemirror.net/6/docs/ref/#view.GutterMarker.toDOM) (or the marker will appear
|
1704 | in all gutters for the line).
|
1705 | */
|
1706 | declare const gutterLineClass: Facet<RangeSet<GutterMarker>, readonly RangeSet<GutterMarker>[]>;
|
1707 | declare type Handlers = {
|
1708 | [event: string]: (view: EditorView, line: BlockInfo, event: Event) => boolean;
|
1709 | };
|
1710 | interface GutterConfig {
|
1711 | /**
|
1712 | An extra CSS class to be added to the wrapper (`cm-gutter`)
|
1713 | element.
|
1714 | */
|
1715 | class?: string;
|
1716 | /**
|
1717 | Controls whether empty gutter elements should be rendered.
|
1718 | Defaults to false.
|
1719 | */
|
1720 | renderEmptyElements?: boolean;
|
1721 | /**
|
1722 | Retrieve a set of markers to use in this gutter.
|
1723 | */
|
1724 | markers?: (view: EditorView) => (RangeSet<GutterMarker> | readonly RangeSet<GutterMarker>[]);
|
1725 | /**
|
1726 | Can be used to optionally add a single marker to every line.
|
1727 | */
|
1728 | lineMarker?: (view: EditorView, line: BlockInfo, otherMarkers: readonly GutterMarker[]) => GutterMarker | null;
|
1729 | /**
|
1730 | If line markers depend on additional state, and should be
|
1731 | updated when that changes, pass a predicate here that checks
|
1732 | whether a given view update might change the line markers.
|
1733 | */
|
1734 | lineMarkerChange?: null | ((update: ViewUpdate) => boolean);
|
1735 | /**
|
1736 | Add a hidden spacer element that gives the gutter its base
|
1737 | width.
|
1738 | */
|
1739 | initialSpacer?: null | ((view: EditorView) => GutterMarker);
|
1740 | /**
|
1741 | Update the spacer element when the view is updated.
|
1742 | */
|
1743 | updateSpacer?: null | ((spacer: GutterMarker, update: ViewUpdate) => GutterMarker);
|
1744 | /**
|
1745 | Supply event handlers for DOM events on this gutter.
|
1746 | */
|
1747 | domEventHandlers?: Handlers;
|
1748 | }
|
1749 | /**
|
1750 | Define an editor gutter. The order in which the gutters appear is
|
1751 | determined by their extension priority.
|
1752 | */
|
1753 | declare function gutter(config: GutterConfig): Extension;
|
1754 | /**
|
1755 | The gutter-drawing plugin is automatically enabled when you add a
|
1756 | gutter, but you can use this function to explicitly configure it.
|
1757 |
|
1758 | Unless `fixed` is explicitly set to `false`, the gutters are
|
1759 | fixed, meaning they don't scroll along with the content
|
1760 | horizontally (except on Internet Explorer, which doesn't support
|
1761 | CSS [`position:
|
1762 | sticky`](https://developer.mozilla.org/en-US/docs/Web/CSS/position#sticky)).
|
1763 | */
|
1764 | declare function gutters(config?: {
|
1765 | fixed?: boolean;
|
1766 | }): Extension;
|
1767 | interface LineNumberConfig {
|
1768 | /**
|
1769 | How to display line numbers. Defaults to simply converting them
|
1770 | to string.
|
1771 | */
|
1772 | formatNumber?: (lineNo: number, state: EditorState) => string;
|
1773 | /**
|
1774 | Supply event handlers for DOM events on this gutter.
|
1775 | */
|
1776 | domEventHandlers?: Handlers;
|
1777 | }
|
1778 | /**
|
1779 | Facet used to provide markers to the line number gutter.
|
1780 | */
|
1781 | declare const lineNumberMarkers: Facet<RangeSet<GutterMarker>, readonly RangeSet<GutterMarker>[]>;
|
1782 | /**
|
1783 | Create a line number gutter extension.
|
1784 | */
|
1785 | declare function lineNumbers(config?: LineNumberConfig): Extension;
|
1786 | /**
|
1787 | Returns an extension that adds a `cm-activeLineGutter` class to
|
1788 | all gutter elements on the [active
|
1789 | line](https://codemirror.net/6/docs/ref/#view.highlightActiveLine).
|
1790 | */
|
1791 | declare function highlightActiveLineGutter(): Extension;
|
1792 |
|
1793 | export { BidiSpan, BlockInfo, BlockType, Command, DOMEventHandlers, DOMEventMap, Decoration, DecorationSet, Direction, EditorView, EditorViewConfig, GutterMarker, KeyBinding, MatchDecorator, MouseSelectionStyle, Panel, PanelConstructor, PluginSpec, PluginValue, Rect, Tooltip, TooltipView, ViewPlugin, ViewUpdate, WidgetType, closeHoverTooltips, crosshairCursor, drawSelection, dropCursor, getPanel, getTooltip, gutter, gutterLineClass, gutters, hasHoverTooltips, highlightActiveLine, highlightActiveLineGutter, highlightSpecialChars, hoverTooltip, keymap, lineNumberMarkers, lineNumbers, logException, panels, placeholder, rectangularSelection, repositionTooltips, runScopeHandlers, scrollPastEnd, showPanel, showTooltip, tooltips };
|
1794 |
|
\ | No newline at end of file |