-
Notifications
You must be signed in to change notification settings - Fork 28.9k
/
hoverActions.ts
453 lines (406 loc) · 14.2 KB
/
hoverActions.ts
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { DECREASE_HOVER_VERBOSITY_ACTION_ID, DECREASE_HOVER_VERBOSITY_ACTION_LABEL, GO_TO_BOTTOM_HOVER_ACTION_ID, GO_TO_TOP_HOVER_ACTION_ID, INCREASE_HOVER_VERBOSITY_ACTION_ID, INCREASE_HOVER_VERBOSITY_ACTION_LABEL, PAGE_DOWN_HOVER_ACTION_ID, PAGE_UP_HOVER_ACTION_ID, SCROLL_DOWN_HOVER_ACTION_ID, SCROLL_LEFT_HOVER_ACTION_ID, SCROLL_RIGHT_HOVER_ACTION_ID, SCROLL_UP_HOVER_ACTION_ID, SHOW_DEFINITION_PREVIEW_HOVER_ACTION_ID, SHOW_OR_FOCUS_HOVER_ACTION_ID } from 'vs/editor/contrib/hover/browser/hoverActionIds';
import { KeyChord, KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { EditorAction, ServicesAccessor } from 'vs/editor/browser/editorExtensions';
import { EditorOption } from 'vs/editor/common/config/editorOptions';
import { Range } from 'vs/editor/common/core/range';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { GotoDefinitionAtPositionEditorContribution } from 'vs/editor/contrib/gotoSymbol/browser/link/goToDefinitionAtPosition';
import { HoverStartMode, HoverStartSource } from 'vs/editor/contrib/hover/browser/hoverOperation';
import { AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { HoverController } from 'vs/editor/contrib/hover/browser/hoverController';
import { HoverVerbosityAction } from 'vs/editor/common/languages';
import * as nls from 'vs/nls';
import 'vs/css!./hover';
enum HoverFocusBehavior {
NoAutoFocus = 'noAutoFocus',
FocusIfVisible = 'focusIfVisible',
AutoFocusImmediately = 'autoFocusImmediately'
}
export class ShowOrFocusHoverAction extends EditorAction {
constructor() {
super({
id: SHOW_OR_FOCUS_HOVER_ACTION_ID,
label: nls.localize({
key: 'showOrFocusHover',
comment: [
'Label for action that will trigger the showing/focusing of a hover in the editor.',
'If the hover is not visible, it will show the hover.',
'This allows for users to show the hover without using the mouse.'
]
}, "Show or Focus Hover"),
metadata: {
description: nls.localize2('showOrFocusHoverDescription', 'Show or focus the editor hover which shows documentation, references, and other content for a symbol at the current cursor position.'),
args: [{
name: 'args',
schema: {
type: 'object',
properties: {
'focus': {
description: 'Controls if and when the hover should take focus upon being triggered by this action.',
enum: [HoverFocusBehavior.NoAutoFocus, HoverFocusBehavior.FocusIfVisible, HoverFocusBehavior.AutoFocusImmediately],
enumDescriptions: [
nls.localize('showOrFocusHover.focus.noAutoFocus', 'The hover will not automatically take focus.'),
nls.localize('showOrFocusHover.focus.focusIfVisible', 'The hover will take focus only if it is already visible.'),
nls.localize('showOrFocusHover.focus.autoFocusImmediately', 'The hover will automatically take focus when it appears.'),
],
default: HoverFocusBehavior.FocusIfVisible,
}
},
}
}]
},
alias: 'Show or Focus Hover',
precondition: undefined,
kbOpts: {
kbExpr: EditorContextKeys.editorTextFocus,
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyMod.CtrlCmd | KeyCode.KeyI),
weight: KeybindingWeight.EditorContrib
}
});
}
public run(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void {
if (!editor.hasModel()) {
return;
}
const controller = HoverController.get(editor);
if (!controller) {
return;
}
const focusArgument = args?.focus;
let focusOption = HoverFocusBehavior.FocusIfVisible;
if (Object.values(HoverFocusBehavior).includes(focusArgument)) {
focusOption = focusArgument;
} else if (typeof focusArgument === 'boolean' && focusArgument) {
focusOption = HoverFocusBehavior.AutoFocusImmediately;
}
const showContentHover = (focus: boolean) => {
const position = editor.getPosition();
const range = new Range(position.lineNumber, position.column, position.lineNumber, position.column);
controller.showContentHover(range, HoverStartMode.Immediate, HoverStartSource.Keyboard, focus);
};
const accessibilitySupportEnabled = editor.getOption(EditorOption.accessibilitySupport) === AccessibilitySupport.Enabled;
if (controller.isHoverVisible) {
if (focusOption !== HoverFocusBehavior.NoAutoFocus) {
controller.focus();
} else {
showContentHover(accessibilitySupportEnabled);
}
} else {
showContentHover(accessibilitySupportEnabled || focusOption === HoverFocusBehavior.AutoFocusImmediately);
}
}
}
export class ShowDefinitionPreviewHoverAction extends EditorAction {
constructor() {
super({
id: SHOW_DEFINITION_PREVIEW_HOVER_ACTION_ID,
label: nls.localize({
key: 'showDefinitionPreviewHover',
comment: [
'Label for action that will trigger the showing of definition preview hover in the editor.',
'This allows for users to show the definition preview hover without using the mouse.'
]
}, "Show Definition Preview Hover"),
alias: 'Show Definition Preview Hover',
precondition: undefined,
metadata: {
description: nls.localize2('showDefinitionPreviewHoverDescription', 'Show the definition preview hover in the editor.'),
},
});
}
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
const controller = HoverController.get(editor);
if (!controller) {
return;
}
const position = editor.getPosition();
if (!position) {
return;
}
const range = new Range(position.lineNumber, position.column, position.lineNumber, position.column);
const goto = GotoDefinitionAtPositionEditorContribution.get(editor);
if (!goto) {
return;
}
const promise = goto.startFindDefinitionFromCursor(position);
promise.then(() => {
controller.showContentHover(range, HoverStartMode.Immediate, HoverStartSource.Keyboard, true);
});
}
}
export class ScrollUpHoverAction extends EditorAction {
constructor() {
super({
id: SCROLL_UP_HOVER_ACTION_ID,
label: nls.localize({
key: 'scrollUpHover',
comment: [
'Action that allows to scroll up in the hover widget with the up arrow when the hover widget is focused.'
]
}, "Scroll Up Hover"),
alias: 'Scroll Up Hover',
precondition: EditorContextKeys.hoverFocused,
kbOpts: {
kbExpr: EditorContextKeys.hoverFocused,
primary: KeyCode.UpArrow,
weight: KeybindingWeight.EditorContrib
},
metadata: {
description: nls.localize2('scrollUpHoverDescription', 'Scroll up the editor hover.')
},
});
}
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
const controller = HoverController.get(editor);
if (!controller) {
return;
}
controller.scrollUp();
}
}
export class ScrollDownHoverAction extends EditorAction {
constructor() {
super({
id: SCROLL_DOWN_HOVER_ACTION_ID,
label: nls.localize({
key: 'scrollDownHover',
comment: [
'Action that allows to scroll down in the hover widget with the up arrow when the hover widget is focused.'
]
}, "Scroll Down Hover"),
alias: 'Scroll Down Hover',
precondition: EditorContextKeys.hoverFocused,
kbOpts: {
kbExpr: EditorContextKeys.hoverFocused,
primary: KeyCode.DownArrow,
weight: KeybindingWeight.EditorContrib
},
metadata: {
description: nls.localize2('scrollDownHoverDescription', 'Scroll down the editor hover.'),
},
});
}
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
const controller = HoverController.get(editor);
if (!controller) {
return;
}
controller.scrollDown();
}
}
export class ScrollLeftHoverAction extends EditorAction {
constructor() {
super({
id: SCROLL_LEFT_HOVER_ACTION_ID,
label: nls.localize({
key: 'scrollLeftHover',
comment: [
'Action that allows to scroll left in the hover widget with the left arrow when the hover widget is focused.'
]
}, "Scroll Left Hover"),
alias: 'Scroll Left Hover',
precondition: EditorContextKeys.hoverFocused,
kbOpts: {
kbExpr: EditorContextKeys.hoverFocused,
primary: KeyCode.LeftArrow,
weight: KeybindingWeight.EditorContrib
},
metadata: {
description: nls.localize2('scrollLeftHoverDescription', 'Scroll left the editor hover.'),
},
});
}
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
const controller = HoverController.get(editor);
if (!controller) {
return;
}
controller.scrollLeft();
}
}
export class ScrollRightHoverAction extends EditorAction {
constructor() {
super({
id: SCROLL_RIGHT_HOVER_ACTION_ID,
label: nls.localize({
key: 'scrollRightHover',
comment: [
'Action that allows to scroll right in the hover widget with the right arrow when the hover widget is focused.'
]
}, "Scroll Right Hover"),
alias: 'Scroll Right Hover',
precondition: EditorContextKeys.hoverFocused,
kbOpts: {
kbExpr: EditorContextKeys.hoverFocused,
primary: KeyCode.RightArrow,
weight: KeybindingWeight.EditorContrib
},
metadata: {
description: nls.localize2('scrollRightHoverDescription', 'Scroll right the editor hover.')
},
});
}
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
const controller = HoverController.get(editor);
if (!controller) {
return;
}
controller.scrollRight();
}
}
export class PageUpHoverAction extends EditorAction {
constructor() {
super({
id: PAGE_UP_HOVER_ACTION_ID,
label: nls.localize({
key: 'pageUpHover',
comment: [
'Action that allows to page up in the hover widget with the page up command when the hover widget is focused.'
]
}, "Page Up Hover"),
alias: 'Page Up Hover',
precondition: EditorContextKeys.hoverFocused,
kbOpts: {
kbExpr: EditorContextKeys.hoverFocused,
primary: KeyCode.PageUp,
secondary: [KeyMod.Alt | KeyCode.UpArrow],
weight: KeybindingWeight.EditorContrib
},
metadata: {
description: nls.localize2('pageUpHoverDescription', 'Page up the editor hover.'),
},
});
}
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
const controller = HoverController.get(editor);
if (!controller) {
return;
}
controller.pageUp();
}
}
export class PageDownHoverAction extends EditorAction {
constructor() {
super({
id: PAGE_DOWN_HOVER_ACTION_ID,
label: nls.localize({
key: 'pageDownHover',
comment: [
'Action that allows to page down in the hover widget with the page down command when the hover widget is focused.'
]
}, "Page Down Hover"),
alias: 'Page Down Hover',
precondition: EditorContextKeys.hoverFocused,
kbOpts: {
kbExpr: EditorContextKeys.hoverFocused,
primary: KeyCode.PageDown,
secondary: [KeyMod.Alt | KeyCode.DownArrow],
weight: KeybindingWeight.EditorContrib
},
metadata: {
description: nls.localize2('pageDownHoverDescription', 'Page down the editor hover.'),
},
});
}
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
const controller = HoverController.get(editor);
if (!controller) {
return;
}
controller.pageDown();
}
}
export class GoToTopHoverAction extends EditorAction {
constructor() {
super({
id: GO_TO_TOP_HOVER_ACTION_ID,
label: nls.localize({
key: 'goToTopHover',
comment: [
'Action that allows to go to the top of the hover widget with the home command when the hover widget is focused.'
]
}, "Go To Top Hover"),
alias: 'Go To Bottom Hover',
precondition: EditorContextKeys.hoverFocused,
kbOpts: {
kbExpr: EditorContextKeys.hoverFocused,
primary: KeyCode.Home,
secondary: [KeyMod.CtrlCmd | KeyCode.UpArrow],
weight: KeybindingWeight.EditorContrib
},
metadata: {
description: nls.localize2('goToTopHoverDescription', 'Go to the top of the editor hover.'),
},
});
}
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
const controller = HoverController.get(editor);
if (!controller) {
return;
}
controller.goToTop();
}
}
export class GoToBottomHoverAction extends EditorAction {
constructor() {
super({
id: GO_TO_BOTTOM_HOVER_ACTION_ID,
label: nls.localize({
key: 'goToBottomHover',
comment: [
'Action that allows to go to the bottom in the hover widget with the end command when the hover widget is focused.'
]
}, "Go To Bottom Hover"),
alias: 'Go To Bottom Hover',
precondition: EditorContextKeys.hoverFocused,
kbOpts: {
kbExpr: EditorContextKeys.hoverFocused,
primary: KeyCode.End,
secondary: [KeyMod.CtrlCmd | KeyCode.DownArrow],
weight: KeybindingWeight.EditorContrib
},
metadata: {
description: nls.localize2('goToBottomHoverDescription', 'Go to the bottom of the editor hover.')
},
});
}
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
const controller = HoverController.get(editor);
if (!controller) {
return;
}
controller.goToBottom();
}
}
export class IncreaseHoverVerbosityLevel extends EditorAction {
constructor() {
super({
id: INCREASE_HOVER_VERBOSITY_ACTION_ID,
label: INCREASE_HOVER_VERBOSITY_ACTION_LABEL,
alias: 'Increase Hover Verbosity Level',
precondition: EditorContextKeys.hoverVisible
});
}
public run(accessor: ServicesAccessor, editor: ICodeEditor, args?: { index: number; focus: boolean }): void {
HoverController.get(editor)?.updateMarkdownHoverVerbosityLevel(HoverVerbosityAction.Increase, args?.index, args?.focus);
}
}
export class DecreaseHoverVerbosityLevel extends EditorAction {
constructor() {
super({
id: DECREASE_HOVER_VERBOSITY_ACTION_ID,
label: DECREASE_HOVER_VERBOSITY_ACTION_LABEL,
alias: 'Decrease Hover Verbosity Level',
precondition: EditorContextKeys.hoverVisible
});
}
public run(accessor: ServicesAccessor, editor: ICodeEditor, args?: { index: number; focus: boolean }): void {
HoverController.get(editor)?.updateMarkdownHoverVerbosityLevel(HoverVerbosityAction.Decrease, args?.index, args?.focus);
}
}