-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginApi.d.ts
More file actions
152 lines (127 loc) · 3.97 KB
/
PluginApi.d.ts
File metadata and controls
152 lines (127 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
export interface EditorPlugin {
/**
* Display name of your plugin. This will be displayed under 'Installed Plugins' menu and under 'Plugins' top menu.
*/
name: string,
/**
* This is not supported yet, but once it is implemented, you can provide this array to add items to editors right-click menu.
*/
contextMenuItems?: Array<EditorMenuItem>,
/**
* Menu items that will be displayed under your plugin's name at the 'Plugin' top menu.
*/
applicationMenuItems?: Array<EditorMenuItem>,
/**
* Menu items that will be displayed at the toolbar (right bar). This menu items has to provide the tool window content (HTML) that will be displayed when the related tool window is opened.
*/
toolbarMenuItems?: Array<ToolbarMenuItem>,
/**
* This will be called whenever the editor is initialized (e.g. on every tab change).
* Since the calling frequency of this function is fully depends on the user, it's plugin developer's responsibility to avoid unnecessary re-initializations that will slow down the application.
* @param editor
*/
initializePlugin: (editor: EditorWrapper) => void,
/**
* Return all action code that your plugin will listen to. This action codes will be sent to 'doAction' method when it needs to be executed.
*/
getAvailableActions: () => Array<string>,
/**
* This will be called whenever user is performed your plugin's menu item via mouse click or keyboard shortcut.
* @param code: The code that you provided in 'applicationMenuItems'
*/
doAction: (code: string) => void,
}
export interface EditorMenuItem {
/**
* Label to show as the wrapper menu
*/
label: string,
/**
* Actions that will be placed under submenu of this label
*/
actions: Array<EditorAction>
}
export interface EditorAction {
/**
* Display name.
*/
label: string,
/**
* Action code.
*/
code: string,
/**
* Action hook.
* @param editor
*/
perform?: (editor: EditorWrapper) => void
/**
* Keyboard shortcut in electron format. (example: CmdOrCtrl+Shift+F, Ctrl+F, Alt+R)
*/
accelerator?: string,
}
/**
* Tool windows.
*/
export interface ToolbarMenuItem {
/**
* Display name.
*/
label: string,
/**
* Icon (base64 url).
*/
icon: string,
/**
* Hook to call whenever the related tool window is opened.
* @param parent
*/
onContentMount?: (parent: ShadowRoot) => void,
/**
* HTML content to render in tool window.
*/
getToolbarWindowContent: () => string
}
export interface EditorWrapper {
/**
* Returns the selection range in a single cursor editor.
*/
getSingleSelectionRange: () => any;
/**
* Returns the array of selection ranges in a multi cursor editor.
*/
getAllSelectionRanges: () => Array<any>;
/**
* Replaces single cursor selection with given text.
* @param text
*/
replaceSelection: (text: string) => void,
/**
* Replaces the content in the given range with provided string.
* @param range: Range to replace
* @param text
*/
replaceRange: (range: any, text: string) => void,
/**
* Replaces the contents of each selection range with the given string. Supports both single cursor and multiple cursors.
* @param text: Text to replace selections with
*/
replaceAllSelectionRanges: (text: string) => void
/**
* Returns the selected text. If the editor is in multi cursor mode, returns the concatenation of the all selections.
*/
getSelectedText: () => string;
/**
* Returns the language mode of the editor.
*/
getLanguage: () => string;
/**
* Returns the text that is included by the given range.
* @param range: Range to search
*/
getTextRange: (range: any) => string;
/**
* Returns the current value of the editor.
*/
getValue: () => string;
}