Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/debug/browser/breakpointWidget.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import * as dom from '../../../../base/browser/dom.js';
7
import { StandardKeyboardEvent } from '../../../../base/browser/keyboardEvent.js';
8
import { Button } from '../../../../base/browser/ui/button/button.js';
9
import { getDefaultHoverDelegate } from '../../../../base/browser/ui/hover/hoverDelegateFactory.js';
10
import { ISelectOptionItem, SelectBox } from '../../../../base/browser/ui/selectBox/selectBox.js';
11
import { CancellationToken } from '../../../../base/common/cancellation.js';
12
import { onUnexpectedError } from '../../../../base/common/errors.js';
13
import { KeyCode, KeyMod } from '../../../../base/common/keyCodes.js';
14
import * as lifecycle from '../../../../base/common/lifecycle.js';
15
import { URI as uri } from '../../../../base/common/uri.js';
16
import { IActiveCodeEditor, ICodeEditor } from '../../../../editor/browser/editorBrowser.js';
17
import { EditorCommand, ServicesAccessor, registerEditorCommand } from '../../../../editor/browser/editorExtensions.js';
18
import { ICodeEditorService } from '../../../../editor/browser/services/codeEditorService.js';
19
import { CodeEditorWidget } from '../../../../editor/browser/widget/codeEditor/codeEditorWidget.js';
20
import { EditorOption, IEditorOptions } from '../../../../editor/common/config/editorOptions.js';
21
import { IPosition, Position } from '../../../../editor/common/core/position.js';
22
import { IRange, Range } from '../../../../editor/common/core/range.js';
23
import { IDecorationOptions } from '../../../../editor/common/editorCommon.js';
24
import { EditorContextKeys } from '../../../../editor/common/editorContextKeys.js';
25
import { CompletionContext, CompletionItemKind, CompletionList } from '../../../../editor/common/languages.js';
26
import { PLAINTEXT_LANGUAGE_ID } from '../../../../editor/common/languages/modesRegistry.js';
27
import { ITextModel } from '../../../../editor/common/model.js';
28
import { ILanguageFeaturesService } from '../../../../editor/common/services/languageFeatures.js';
29
import { IModelService } from '../../../../editor/common/services/model.js';
30
import { ITextModelService } from '../../../../editor/common/services/resolverService.js';
31
import { CompletionOptions, provideSuggestionItems } from '../../../../editor/contrib/suggest/browser/suggest.js';
32
import { ZoneWidget } from '../../../../editor/contrib/zoneWidget/browser/zoneWidget.js';
33
import * as nls from '../../../../nls.js';
34
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
35
import { IContextViewService } from '../../../../platform/contextview/browser/contextView.js';
36
import { IHoverService } from '../../../../platform/hover/browser/hover.js';
37
import { IInstantiationService, createDecorator } from '../../../../platform/instantiation/common/instantiation.js';
38
import { ServiceCollection } from '../../../../platform/instantiation/common/serviceCollection.js';
39
import { IKeybindingService } from '../../../../platform/keybinding/common/keybinding.js';
40
import { KeybindingWeight } from '../../../../platform/keybinding/common/keybindingsRegistry.js';
41
import { ILabelService } from '../../../../platform/label/common/label.js';
42
import { defaultButtonStyles, defaultSelectBoxStyles } from '../../../../platform/theme/browser/defaultStyles.js';
43
import { editorForeground } from '../../../../platform/theme/common/colorRegistry.js';
44
import { IColorTheme, IThemeService } from '../../../../platform/theme/common/themeService.js';
45
import { hasNativeContextMenu } from '../../../../platform/window/common/window.js';
46
import { getSimpleCodeEditorWidgetOptions, getSimpleEditorOptions } from '../../codeEditor/browser/simpleEditorOptions.js';
47
import { BREAKPOINT_EDITOR_CONTRIBUTION_ID, CONTEXT_BREAKPOINT_WIDGET_VISIBLE, CONTEXT_IN_BREAKPOINT_WIDGET, BreakpointWidgetContext as Context, DEBUG_SCHEME, IBreakpoint, IBreakpointEditorContribution, IBreakpointUpdateData, IDebugService } from '../common/debug.js';
48
import './media/breakpointWidget.css';
49
50
const $ = dom.$;
51
const IPrivateBreakpointWidgetService = createDecorator<IPrivateBreakpointWidgetService>('privateBreakpointWidgetService');
52
interface IPrivateBreakpointWidgetService {
53
readonly _serviceBrand: undefined;
54
close(success: boolean): void;
55
}
56
const DECORATION_KEY = 'breakpointwidgetdecoration';
57
58
function isPositionInCurlyBracketBlock(input: IActiveCodeEditor): boolean {
59
const model = input.getModel();
60
const bracketPairs = model.bracketPairs.getBracketPairsInRange(Range.fromPositions(input.getPosition()));
61
return bracketPairs.some(p => p.openingBracketInfo.bracketText === '{');
62
}
63
64
function createDecorations(theme: IColorTheme, placeHolder: string): IDecorationOptions[] {
65
const transparentForeground = theme.getColor(editorForeground)?.transparent(0.4);
66
return [{
67
range: {
68
startLineNumber: 0,
69
endLineNumber: 0,
70
startColumn: 0,
71
endColumn: 1
72
},
73
renderOptions: {
74
after: {
75
contentText: placeHolder,
76
color: transparentForeground ? transparentForeground.toString() : undefined
77
}
78
}
79
}];
80
}
81
82
export class BreakpointWidget extends ZoneWidget implements IPrivateBreakpointWidgetService {
83
declare readonly _serviceBrand: undefined;
84
85
private selectContainer!: HTMLElement;
86
private inputContainer!: HTMLElement;
87
private selectBreakpointContainer!: HTMLElement;
88
private input!: IActiveCodeEditor;
89
private selectBreakpointBox!: SelectBox;
90
private selectModeBox?: SelectBox;
91
private store: lifecycle.DisposableStore;
92
private conditionInput = '';
93
private hitCountInput = '';
94
private logMessageInput = '';
95
private modeInput?: DebugProtocol.BreakpointMode;
96
private breakpoint: IBreakpoint | undefined;
97
private context: Context;
98
private heightInPx: number | undefined;
99
private triggeredByBreakpointInput: IBreakpoint | undefined;
100
101
constructor(editor: ICodeEditor, private lineNumber: number, private column: number | undefined, context: Context | undefined,
102
@IContextViewService private readonly contextViewService: IContextViewService,
103
@IDebugService private readonly debugService: IDebugService,
104
@IThemeService private readonly themeService: IThemeService,
105
@IInstantiationService private readonly instantiationService: IInstantiationService,
106
@IModelService private readonly modelService: IModelService,
107
@ICodeEditorService private readonly codeEditorService: ICodeEditorService,
108
@IConfigurationService private readonly _configurationService: IConfigurationService,
109
@ILanguageFeaturesService private readonly languageFeaturesService: ILanguageFeaturesService,
110
@IKeybindingService private readonly keybindingService: IKeybindingService,
111
@ILabelService private readonly labelService: ILabelService,
112
@ITextModelService private readonly textModelService: ITextModelService,
113
@IHoverService private readonly hoverService: IHoverService
114
) {
115
super(editor, { showFrame: true, showArrow: false, frameWidth: 1, isAccessible: true });
116
117
this.store = new lifecycle.DisposableStore();
118
const model = this.editor.getModel();
119
if (model) {
120
const uri = model.uri;
121
const breakpoints = this.debugService.getModel().getBreakpoints({ lineNumber: this.lineNumber, column: this.column, uri });
122
this.breakpoint = breakpoints.length ? breakpoints[0] : undefined;
123
}
124
125
if (context === undefined) {
126
if (this.breakpoint && !this.breakpoint.condition && !this.breakpoint.hitCondition && this.breakpoint.logMessage) {
127
this.context = Context.LOG_MESSAGE;
128
} else if (this.breakpoint && !this.breakpoint.condition && this.breakpoint.hitCondition) {
129
this.context = Context.HIT_COUNT;
130
} else if (this.breakpoint && this.breakpoint.triggeredBy) {
131
this.context = Context.TRIGGER_POINT;
132
} else {
133
this.context = Context.CONDITION;
134
}
135
} else {
136
this.context = context;
137
}
138
139
this.store.add(this.debugService.getModel().onDidChangeBreakpoints(e => {
140
if (this.breakpoint && e && e.removed && e.removed.indexOf(this.breakpoint) >= 0) {
141
this.dispose();
142
}
143
}));
144
this.codeEditorService.registerDecorationType('breakpoint-widget', DECORATION_KEY, {});
145
146
this.create();
147
}
148
149
private get placeholder(): string {
150
const acceptString = this.keybindingService.lookupKeybinding(AcceptBreakpointWidgetInputAction.ID)?.getLabel() || 'Enter';
151
const closeString = this.keybindingService.lookupKeybinding(CloseBreakpointWidgetCommand.ID)?.getLabel() || 'Escape';
152
switch (this.context) {
153
case Context.LOG_MESSAGE:
154
return nls.localize('breakpointWidgetLogMessagePlaceholder', "Message to log when breakpoint is hit. Expressions within {} are interpolated. '{0}' to accept, '{1}' to cancel.", acceptString, closeString);
155
case Context.HIT_COUNT:
156
return nls.localize('breakpointWidgetHitCountPlaceholder', "Break when hit count condition is met. '{0}' to accept, '{1}' to cancel.", acceptString, closeString);
157
default:
158
return nls.localize('breakpointWidgetExpressionPlaceholder', "Break when expression evaluates to true. '{0}' to accept, '{1}' to cancel.", acceptString, closeString);
159
}
160
}
161
162
private getInputValue(breakpoint: IBreakpoint | undefined): string {
163
switch (this.context) {
164
case Context.LOG_MESSAGE:
165
return breakpoint && breakpoint.logMessage ? breakpoint.logMessage : this.logMessageInput;
166
case Context.HIT_COUNT:
167
return breakpoint && breakpoint.hitCondition ? breakpoint.hitCondition : this.hitCountInput;
168
default:
169
return breakpoint && breakpoint.condition ? breakpoint.condition : this.conditionInput;
170
}
171
}
172
173
private rememberInput(): void {
174
if (this.context !== Context.TRIGGER_POINT) {
175
const value = this.input.getModel().getValue();
176
switch (this.context) {
177
case Context.LOG_MESSAGE:
178
this.logMessageInput = value;
179
break;
180
case Context.HIT_COUNT:
181
this.hitCountInput = value;
182
break;
183
default:
184
this.conditionInput = value;
185
}
186
}
187
}
188
189
private setInputMode(): void {
190
if (this.editor.hasModel()) {
191
// Use plaintext language for log messages, otherwise respect underlying editor language #125619
192
const languageId = this.context === Context.LOG_MESSAGE ? PLAINTEXT_LANGUAGE_ID : this.editor.getModel().getLanguageId();
193
this.input.getModel().setLanguage(languageId);
194
}
195
}
196
197
override show(rangeOrPos: IRange | IPosition): void {
198
const lineNum = this.input.getModel().getLineCount();
199
super.show(rangeOrPos, lineNum + 1);
200
}
201
202
fitHeightToContent(): void {
203
const lineNum = this.input.getModel().getLineCount();
204
this._relayout(lineNum + 1);
205
}
206
207
protected _fillContainer(container: HTMLElement): void {
208
this.setCssClass('breakpoint-widget');
209
const selectBox = this.store.add(new SelectBox([
210
{ text: nls.localize('expression', "Expression") },
211
{ text: nls.localize('hitCount', "Hit Count") },
212
{ text: nls.localize('logMessage', "Log Message") },
213
{ text: nls.localize('triggeredBy', "Wait for Breakpoint") },
214
] satisfies ISelectOptionItem[], this.context, this.contextViewService, defaultSelectBoxStyles, { ariaLabel: nls.localize('breakpointType', 'Breakpoint Type'), useCustomDrawn: !hasNativeContextMenu(this._configurationService) }));
215
this.selectContainer = $('.breakpoint-select-container');
216
selectBox.render(dom.append(container, this.selectContainer));
217
selectBox.onDidSelect(e => {
218
this.rememberInput();
219
this.context = e.index;
220
this.updateContextInput();
221
});
222
223
this.createModesInput(container);
224
225
this.inputContainer = $('.inputContainer');
226
this.store.add(this.hoverService.setupManagedHover(getDefaultHoverDelegate('mouse'), this.inputContainer, this.placeholder));
227
this.createBreakpointInput(dom.append(container, this.inputContainer));
228
229
this.input.getModel().setValue(this.getInputValue(this.breakpoint));
230
this.store.add(this.input.getModel().onDidChangeContent(() => {
231
this.fitHeightToContent();
232
}));
233
this.input.setPosition({ lineNumber: 1, column: this.input.getModel().getLineMaxColumn(1) });
234
235
this.createTriggerBreakpointInput(container);
236
237
this.updateContextInput();
238
// Due to an electron bug we have to do the timeout, otherwise we do not get focus
239
setTimeout(() => this.focusInput(), 150);
240
}
241
242
private createModesInput(container: HTMLElement) {
243
const modes = this.debugService.getModel().getBreakpointModes('source');
244
if (modes.length <= 1) {
245
return;
246
}
247
248
const sb = this.selectModeBox = new SelectBox(
249
[
250
{ text: nls.localize('bpMode', 'Mode'), isDisabled: true },
251
...modes.map(mode => ({ text: mode.label, description: mode.description })),
252
],
253
modes.findIndex(m => m.mode === this.breakpoint?.mode) + 1,
254
this.contextViewService,
255
defaultSelectBoxStyles,
256
{ useCustomDrawn: !hasNativeContextMenu(this._configurationService) }
257
);
258
this.store.add(sb);
259
this.store.add(sb.onDidSelect(e => {
260
this.modeInput = modes[e.index - 1];
261
}));
262
263
const modeWrapper = $('.select-mode-container');
264
const selectionWrapper = $('.select-box-container');
265
dom.append(modeWrapper, selectionWrapper);
266
sb.render(selectionWrapper);
267
dom.append(container, modeWrapper);
268
}
269
270
private createTriggerBreakpointInput(container: HTMLElement) {
271
const breakpoints = this.debugService.getModel().getBreakpoints().filter(bp => bp !== this.breakpoint && !bp.logMessage);
272
const breakpointOptions: ISelectOptionItem[] = [
273
{ text: nls.localize('noTriggerByBreakpoint', 'None'), isDisabled: true },
274
...breakpoints.map(bp => ({
275
text: `${this.labelService.getUriLabel(bp.uri, { relative: true })}: ${bp.lineNumber}`,
276
description: nls.localize('triggerByLoading', 'Loading...')
277
})),
278
];
279
280
const index = breakpoints.findIndex((bp) => this.breakpoint?.triggeredBy === bp.getId());
281
for (const [i, bp] of breakpoints.entries()) {
282
this.textModelService.createModelReference(bp.uri).then(ref => {
283
try {
284
breakpointOptions[i + 1].description = ref.object.textEditorModel.getLineContent(bp.lineNumber).trim();
285
} finally {
286
ref.dispose();
287
}
288
}).catch(() => {
289
breakpointOptions[i + 1].description = nls.localize('noBpSource', 'Could not load source.');
290
});
291
}
292
293
const selectBreakpointBox = this.selectBreakpointBox = new SelectBox(breakpointOptions, index + 1, this.contextViewService, defaultSelectBoxStyles, { ariaLabel: nls.localize('selectBreakpoint', 'Select breakpoint'), useCustomDrawn: !hasNativeContextMenu(this._configurationService) });
294
selectBreakpointBox.onDidSelect(e => {
295
if (e.index === 0) {
296
this.triggeredByBreakpointInput = undefined;
297
} else {
298
this.triggeredByBreakpointInput = breakpoints[e.index - 1];
299
}
300
});
301
this.store.add(selectBreakpointBox);
302
this.selectBreakpointContainer = $('.select-breakpoint-container');
303
this.store.add(dom.addDisposableListener(this.selectBreakpointContainer, dom.EventType.KEY_DOWN, e => {
304
const event = new StandardKeyboardEvent(e);
305
if (event.equals(KeyCode.Escape)) {
306
this.close(false);
307
}
308
}));
309
310
const selectionWrapper = $('.select-box-container');
311
dom.append(this.selectBreakpointContainer, selectionWrapper);
312
selectBreakpointBox.render(selectionWrapper);
313
314
dom.append(container, this.selectBreakpointContainer);
315
316
const closeButton = new Button(this.selectBreakpointContainer, defaultButtonStyles);
317
closeButton.label = nls.localize('ok', "OK");
318
this.store.add(closeButton.onDidClick(() => this.close(true)));
319
this.store.add(closeButton);
320
}
321
322
private updateContextInput() {
323
if (this.context === Context.TRIGGER_POINT) {
324
this.inputContainer.hidden = true;
325
this.selectBreakpointContainer.hidden = false;
326
} else {
327
this.inputContainer.hidden = false;
328
this.selectBreakpointContainer.hidden = true;
329
this.setInputMode();
330
const value = this.getInputValue(this.breakpoint);
331
this.input.getModel().setValue(value);
332
this.focusInput();
333
}
334
}
335
336
protected override _doLayout(heightInPixel: number, widthInPixel: number): void {
337
this.heightInPx = heightInPixel;
338
this.input.layout({ height: heightInPixel, width: widthInPixel - 113 });
339
this.centerInputVertically();
340
}
341
342
protected override _onWidth(widthInPixel: number): void {
343
if (typeof this.heightInPx === 'number') {
344
this._doLayout(this.heightInPx, widthInPixel);
345
}
346
}
347
348
private createBreakpointInput(container: HTMLElement): void {
349
const scopedInstatiationService = this.instantiationService.createChild(new ServiceCollection(
350
[IPrivateBreakpointWidgetService, this]
351
));
352
this.store.add(scopedInstatiationService);
353
354
const options = this.createEditorOptions();
355
const codeEditorWidgetOptions = getSimpleCodeEditorWidgetOptions();
356
this.input = <IActiveCodeEditor>scopedInstatiationService.createInstance(CodeEditorWidget, container, options, codeEditorWidgetOptions);
357
358
CONTEXT_IN_BREAKPOINT_WIDGET.bindTo(this.input.contextKeyService).set(true);
359
const model = this.modelService.createModel('', null, uri.parse(`${DEBUG_SCHEME}:${this.editor.getId()}:breakpointinput`), true);
360
if (this.editor.hasModel()) {
361
model.setLanguage(this.editor.getModel().getLanguageId());
362
}
363
this.input.setModel(model);
364
this.setInputMode();
365
this.store.add(model);
366
const setDecorations = () => {
367
const value = this.input.getModel().getValue();
368
const decorations = !!value ? [] : createDecorations(this.themeService.getColorTheme(), this.placeholder);
369
this.input.setDecorationsByType('breakpoint-widget', DECORATION_KEY, decorations);
370
};
371
this.input.getModel().onDidChangeContent(() => setDecorations());
372
this.themeService.onDidColorThemeChange(() => setDecorations());
373
374
this.store.add(this.languageFeaturesService.completionProvider.register({ scheme: DEBUG_SCHEME, hasAccessToAllModels: true }, {
375
_debugDisplayName: 'breakpointWidget',
376
provideCompletionItems: (model: ITextModel, position: Position, _context: CompletionContext, token: CancellationToken): Promise<CompletionList> => {
377
let suggestionsPromise: Promise<CompletionList>;
378
const underlyingModel = this.editor.getModel();
379
if (underlyingModel && (this.context === Context.CONDITION || (this.context === Context.LOG_MESSAGE && isPositionInCurlyBracketBlock(this.input)))) {
380
suggestionsPromise = provideSuggestionItems(this.languageFeaturesService.completionProvider, underlyingModel, new Position(this.lineNumber, 1), new CompletionOptions(undefined, new Set<CompletionItemKind>().add(CompletionItemKind.Snippet)), _context, token).then(suggestions => {
381
382
let overwriteBefore = 0;
383
if (this.context === Context.CONDITION) {
384
overwriteBefore = position.column - 1;
385
} else {
386
// Inside the currly brackets, need to count how many useful characters are behind the position so they would all be taken into account
387
const value = this.input.getModel().getValue();
388
while ((position.column - 2 - overwriteBefore >= 0) && value[position.column - 2 - overwriteBefore] !== '{' && value[position.column - 2 - overwriteBefore] !== ' ') {
389
overwriteBefore++;
390
}
391
}
392
393
return {
394
suggestions: suggestions.items.map(s => {
395
s.completion.range = Range.fromPositions(position.delta(0, -overwriteBefore), position);
396
return s.completion;
397
})
398
};
399
});
400
} else {
401
suggestionsPromise = Promise.resolve({ suggestions: [] });
402
}
403
404
return suggestionsPromise;
405
}
406
}));
407
408
this.store.add(this._configurationService.onDidChangeConfiguration((e) => {
409
if (e.affectsConfiguration('editor.fontSize') || e.affectsConfiguration('editor.lineHeight')) {
410
this.input.updateOptions(this.createEditorOptions());
411
this.centerInputVertically();
412
}
413
}));
414
}
415
416
private createEditorOptions(): IEditorOptions {
417
const editorConfig = this._configurationService.getValue<IEditorOptions>('editor');
418
const options = getSimpleEditorOptions(this._configurationService);
419
options.fontSize = editorConfig.fontSize;
420
options.fontFamily = editorConfig.fontFamily;
421
options.lineHeight = editorConfig.lineHeight;
422
options.fontLigatures = editorConfig.fontLigatures;
423
options.ariaLabel = this.placeholder;
424
return options;
425
}
426
427
private centerInputVertically() {
428
if (this.container && typeof this.heightInPx === 'number') {
429
const lineHeight = this.input.getOption(EditorOption.lineHeight);
430
const lineNum = this.input.getModel().getLineCount();
431
const newTopMargin = (this.heightInPx - lineNum * lineHeight) / 2;
432
this.inputContainer.style.marginTop = newTopMargin + 'px';
433
}
434
}
435
436
close(success: boolean): void {
437
if (success) {
438
// if there is already a breakpoint on this location - remove it.
439
440
let condition: string | undefined = undefined;
441
let hitCondition: string | undefined = undefined;
442
let logMessage: string | undefined = undefined;
443
let triggeredBy: string | undefined = undefined;
444
let mode: string | undefined = undefined;
445
let modeLabel: string | undefined = undefined;
446
447
this.rememberInput();
448
449
if (this.conditionInput || this.context === Context.CONDITION) {
450
condition = this.conditionInput;
451
}
452
if (this.hitCountInput || this.context === Context.HIT_COUNT) {
453
hitCondition = this.hitCountInput;
454
}
455
if (this.logMessageInput || this.context === Context.LOG_MESSAGE) {
456
logMessage = this.logMessageInput;
457
}
458
if (this.selectModeBox) {
459
mode = this.modeInput?.mode;
460
modeLabel = this.modeInput?.label;
461
}
462
if (this.context === Context.TRIGGER_POINT) {
463
// currently, trigger points don't support additional conditions:
464
condition = undefined;
465
hitCondition = undefined;
466
logMessage = undefined;
467
triggeredBy = this.triggeredByBreakpointInput?.getId();
468
}
469
470
if (this.breakpoint) {
471
const data = new Map<string, IBreakpointUpdateData>();
472
data.set(this.breakpoint.getId(), {
473
condition,
474
hitCondition,
475
logMessage,
476
triggeredBy,
477
mode,
478
modeLabel,
479
});
480
this.debugService.updateBreakpoints(this.breakpoint.originalUri, data, false).then(undefined, onUnexpectedError);
481
} else {
482
const model = this.editor.getModel();
483
if (model) {
484
this.debugService.addBreakpoints(model.uri, [{
485
lineNumber: this.lineNumber,
486
column: this.column,
487
enabled: true,
488
condition,
489
hitCondition,
490
logMessage,
491
triggeredBy,
492
mode,
493
modeLabel,
494
}]);
495
}
496
}
497
}
498
499
this.dispose();
500
}
501
502
private focusInput() {
503
if (this.context === Context.TRIGGER_POINT) {
504
this.selectBreakpointBox.focus();
505
} else {
506
this.input.focus();
507
}
508
}
509
510
override dispose(): void {
511
super.dispose();
512
this.input.dispose();
513
lifecycle.dispose(this.store);
514
setTimeout(() => this.editor.focus(), 0);
515
}
516
}
517
518
class AcceptBreakpointWidgetInputAction extends EditorCommand {
519
static ID = 'breakpointWidget.action.acceptInput';
520
constructor() {
521
super({
522
id: AcceptBreakpointWidgetInputAction.ID,
523
precondition: CONTEXT_BREAKPOINT_WIDGET_VISIBLE,
524
kbOpts: {
525
kbExpr: CONTEXT_IN_BREAKPOINT_WIDGET,
526
primary: KeyCode.Enter,
527
weight: KeybindingWeight.EditorContrib
528
}
529
});
530
}
531
532
runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor): void {
533
accessor.get(IPrivateBreakpointWidgetService).close(true);
534
}
535
}
536
537
class CloseBreakpointWidgetCommand extends EditorCommand {
538
static ID = 'closeBreakpointWidget';
539
constructor() {
540
super({
541
id: CloseBreakpointWidgetCommand.ID,
542
precondition: CONTEXT_BREAKPOINT_WIDGET_VISIBLE,
543
kbOpts: {
544
kbExpr: EditorContextKeys.textInputFocus,
545
primary: KeyCode.Escape,
546
secondary: [KeyMod.Shift | KeyCode.Escape],
547
weight: KeybindingWeight.EditorContrib
548
}
549
});
550
}
551
552
runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void {
553
const debugContribution = editor.getContribution<IBreakpointEditorContribution>(BREAKPOINT_EDITOR_CONTRIBUTION_ID);
554
if (debugContribution) {
555
// if focus is in outer editor we need to use the debug contribution to close
556
return debugContribution.closeBreakpointWidget();
557
}
558
559
accessor.get(IPrivateBreakpointWidgetService).close(false);
560
}
561
}
562
563
registerEditorCommand(new AcceptBreakpointWidgetInputAction());
564
registerEditorCommand(new CloseBreakpointWidgetCommand());
565
566