UNPKG

4.83 kBTypeScriptView Raw
1import { DecorationPropsChangedEvent, DisplayMarker, Disposable } from "../index";
2
3/**
4 * Represents a decoration that follows a DisplayMarker. A decoration is basically
5 * a visual representation of a marker. It allows you to add CSS classes to line
6 * numbers in the gutter, lines, and add selection-line regions around marked ranges
7 * of text.
8 */
9export interface Decoration {
10 /** The identifier for this Decoration. */
11 readonly id: number;
12
13 // Construction and Destruction
14 /**
15 * Destroy this marker decoration.
16 * You can also destroy the marker if you own it, which will destroy this decoration.
17 */
18 destroy(): void;
19
20 // Event Subscription
21 /** When the Decoration is updated via Decoration::setProperties. */
22 onDidChangeProperties(callback: (event: DecorationPropsChangedEvent) => void): Disposable;
23
24 /** Invoke the given callback when the Decoration is destroyed. */
25 onDidDestroy(callback: () => void): Disposable;
26
27 // Decoration Details
28 /** An id unique across all Decoration objects. */
29 getId(): number;
30
31 /** Returns the marker associated with this Decoration. */
32 getMarker(): DisplayMarker;
33
34 /**
35 * Check if this decoration is of the given type.
36 * @param type A decoration type, such as `line-number` or `line`. This may also
37 * be an array of decoration types, with isType returning true if the decoration's
38 * type matches any in the array.
39 */
40 isType(type: string | string[]): boolean;
41
42 // Properties
43 /** Returns the Decoration's properties. */
44 getProperties(): DecorationOptions;
45
46 /**
47 * Update the marker with new Properties. Allows you to change the decoration's
48 * class.
49 */
50 setProperties(newProperties: DecorationOptions): void;
51}
52
53export interface SharedDecorationOptions {
54 /**
55 * This CSS class will be applied to the decorated line number, line, highlight,
56 * or overlay.
57 */
58 class?: string | undefined;
59
60 /**
61 * An Object containing CSS style properties to apply to the relevant DOM
62 * node. Currently this only works with a type of cursor or text.
63 */
64 style?: object | undefined;
65
66 /**
67 * An HTMLElement or a model Object with a corresponding view registered. Only
68 * applicable to the gutter, overlay and block types.
69 */
70 item?: object | undefined;
71
72 /**
73 * If true, the decoration will only be applied to the head of the DisplayMarker.
74 * Only applicable to the line and line-number types.
75 */
76 onlyHead?: boolean | undefined;
77
78 /**
79 * If true, the decoration will only be applied if the associated DisplayMarker
80 * is empty. Only applicable to the gutter, line, and line-number types.
81 */
82 onlyEmpty?: boolean | undefined;
83
84 /**
85 * If true, the decoration will only be applied if the associated DisplayMarker
86 * is non-empty. Only applicable to the gutter, line, and line-number types.
87 */
88 onlyNonEmpty?: boolean | undefined;
89
90 /**
91 * If false, the decoration will be applied to the last row of a non-empty
92 * range, even if it ends at column 0. Defaults to true. Only applicable
93 * to the gutter, line, and line-number decoration types.
94 */
95 omitEmptyLastRow?: boolean | undefined;
96
97 /**
98 * Only applicable to decorations of type overlay and block. Controls where the
99 * view is positioned relative to the TextEditorMarker. Values can be
100 * 'head' (the default) or 'tail' for overlay decorations, and 'before' (the default)
101 * or 'after' for block decorations.
102 */
103 position?: "head" | "tail" | "before" | "after" | undefined;
104
105 /**
106 * Only applicable to decorations of type block. Controls where the view is
107 * positioned relative to other block decorations at the same screen row.
108 * If unspecified, block decorations render oldest to newest.
109 */
110 order?: number | undefined;
111
112 /**
113 * Only applicable to decorations of type overlay. Determines whether the decoration
114 * adjusts its horizontal or vertical position to remain fully visible when it would
115 * otherwise overflow the editor. Defaults to true.
116 */
117 avoidOverflow?: boolean | undefined;
118}
119
120export interface DecorationLayerOptions extends SharedDecorationOptions {
121 /** One of several supported decoration types. */
122 type?: "line" | "line-number" | "text" | "highlight" | "block" | "cursor" | undefined;
123}
124
125export interface DecorationOptions extends SharedDecorationOptions {
126 /** One of several supported decoration types. */
127 type?: "line" | "line-number" | "text" | "highlight" | "overlay" | "gutter" | "block" | "cursor" | undefined;
128
129 /** The name of the gutter we're decorating, if type is "gutter". */
130 gutterName?: string | undefined;
131}