monaco-editor
Version:
A browser based code editor
1,263 lines • 2.48 MB
JavaScript
define("vs/toggleHighContrast-LEuD8lYt", ["exports", "./editorWorkerHost-DOv8Y9y5", "./editor-ECyZhXSU"], (function(exports, editorWorkerHost, editor) {
"use strict";
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa;
class ToggleCollapseUnchangedRegions extends editor.Action2 {
constructor() {
super({
id: "diffEditor.toggleCollapseUnchangedRegions",
title: editorWorkerHost.localize2(101, "Toggle Collapse Unchanged Regions"),
icon: editorWorkerHost.Codicon.map,
toggled: editor.ContextKeyExpr.has("config.diffEditor.hideUnchangedRegions.enabled"),
precondition: editor.ContextKeyExpr.has("isInDiffEditor"),
menu: {
when: editor.ContextKeyExpr.has("isInDiffEditor"),
id: editor.MenuId.EditorTitle,
order: 22,
group: "navigation"
}
});
}
run(accessor, ...args) {
const configurationService = accessor.get(editor.IConfigurationService);
const newValue = !configurationService.getValue("diffEditor.hideUnchangedRegions.enabled");
configurationService.updateValue("diffEditor.hideUnchangedRegions.enabled", newValue);
}
}
class ToggleShowMovedCodeBlocks extends editor.Action2 {
constructor() {
super({
id: "diffEditor.toggleShowMovedCodeBlocks",
title: editorWorkerHost.localize2(102, "Toggle Show Moved Code Blocks"),
precondition: editor.ContextKeyExpr.has("isInDiffEditor")
});
}
run(accessor, ...args) {
const configurationService = accessor.get(editor.IConfigurationService);
const newValue = !configurationService.getValue("diffEditor.experimental.showMoves");
configurationService.updateValue("diffEditor.experimental.showMoves", newValue);
}
}
class ToggleUseInlineViewWhenSpaceIsLimited extends editor.Action2 {
constructor() {
super({
id: "diffEditor.toggleUseInlineViewWhenSpaceIsLimited",
title: editorWorkerHost.localize2(103, "Toggle Use Inline View When Space Is Limited"),
precondition: editor.ContextKeyExpr.has("isInDiffEditor")
});
}
run(accessor, ...args) {
const configurationService = accessor.get(editor.IConfigurationService);
const newValue = !configurationService.getValue("diffEditor.useInlineViewWhenSpaceIsLimited");
configurationService.updateValue("diffEditor.useInlineViewWhenSpaceIsLimited", newValue);
}
}
const diffEditorCategory = editorWorkerHost.localize2(104, "Diff Editor");
class SwitchSide extends editor.EditorAction2 {
constructor() {
super({
id: "diffEditor.switchSide",
title: editorWorkerHost.localize2(105, "Switch Side"),
icon: editorWorkerHost.Codicon.arrowSwap,
precondition: editor.ContextKeyExpr.has("isInDiffEditor"),
f1: true,
category: diffEditorCategory
});
}
runEditorCommand(accessor, editor$1, arg) {
const diffEditor = findFocusedDiffEditor(accessor);
if (diffEditor instanceof editor.DiffEditorWidget) {
if (arg && arg.dryRun) {
return { destinationSelection: diffEditor.mapToOtherSide().destinationSelection };
} else {
diffEditor.switchSide();
}
}
return void 0;
}
}
class ExitCompareMove extends editor.EditorAction2 {
constructor() {
super({
id: "diffEditor.exitCompareMove",
title: editorWorkerHost.localize2(106, "Exit Compare Move"),
icon: editorWorkerHost.Codicon.close,
precondition: editor.EditorContextKeys.comparingMovedCode,
f1: false,
category: diffEditorCategory,
keybinding: {
weight: 1e4,
primary: 9
}
});
}
runEditorCommand(accessor, editor$1, ...args) {
const diffEditor = findFocusedDiffEditor(accessor);
if (diffEditor instanceof editor.DiffEditorWidget) {
diffEditor.exitCompareMove();
}
}
}
class CollapseAllUnchangedRegions extends editor.EditorAction2 {
constructor() {
super({
id: "diffEditor.collapseAllUnchangedRegions",
title: editorWorkerHost.localize2(107, "Collapse All Unchanged Regions"),
icon: editorWorkerHost.Codicon.fold,
precondition: editor.ContextKeyExpr.has("isInDiffEditor"),
f1: true,
category: diffEditorCategory
});
}
runEditorCommand(accessor, editor$1, ...args) {
const diffEditor = findFocusedDiffEditor(accessor);
if (diffEditor instanceof editor.DiffEditorWidget) {
diffEditor.collapseAllUnchangedRegions();
}
}
}
class ShowAllUnchangedRegions extends editor.EditorAction2 {
constructor() {
super({
id: "diffEditor.showAllUnchangedRegions",
title: editorWorkerHost.localize2(108, "Show All Unchanged Regions"),
icon: editorWorkerHost.Codicon.unfold,
precondition: editor.ContextKeyExpr.has("isInDiffEditor"),
f1: true,
category: diffEditorCategory
});
}
runEditorCommand(accessor, editor$1, ...args) {
const diffEditor = findFocusedDiffEditor(accessor);
if (diffEditor instanceof editor.DiffEditorWidget) {
diffEditor.showAllUnchangedRegions();
}
}
}
class RevertHunkOrSelection extends editor.Action2 {
constructor() {
super({
id: "diffEditor.revert",
title: editorWorkerHost.localize2(109, "Revert"),
f1: true,
category: diffEditorCategory,
precondition: editor.ContextKeyExpr.has("isInDiffEditor")
});
}
run(accessor, arg) {
return arg ? this.runViaToolbarContext(accessor, arg) : this.runViaCursorOrSelection(accessor);
}
runViaCursorOrSelection(accessor) {
const diffEditor = findFocusedDiffEditor(accessor);
if (diffEditor instanceof editor.DiffEditorWidget) {
diffEditor.revertFocusedRangeMappings();
}
return void 0;
}
runViaToolbarContext(accessor, arg) {
const diffEditor = findDiffEditor(accessor, arg.originalUri, arg.modifiedUri);
if (diffEditor instanceof editor.DiffEditorWidget) {
diffEditor.revertRangeMappings(arg.mapping.innerChanges ?? []);
}
return void 0;
}
}
const accessibleDiffViewerCategory = editorWorkerHost.localize2(110, "Accessible Diff Viewer");
const _AccessibleDiffViewerNext = class _AccessibleDiffViewerNext extends editor.Action2 {
constructor() {
super({
id: _AccessibleDiffViewerNext.id,
title: editorWorkerHost.localize2(111, "Go to Next Difference"),
category: accessibleDiffViewerCategory,
precondition: editor.ContextKeyExpr.has("isInDiffEditor"),
keybinding: {
primary: 65,
weight: 100
/* KeybindingWeight.EditorContrib */
},
f1: true
});
}
run(accessor) {
const diffEditor = findFocusedDiffEditor(accessor);
diffEditor?.accessibleDiffViewerNext();
}
};
_AccessibleDiffViewerNext.id = "editor.action.accessibleDiffViewer.next";
let AccessibleDiffViewerNext = _AccessibleDiffViewerNext;
const _AccessibleDiffViewerPrev = class _AccessibleDiffViewerPrev extends editor.Action2 {
constructor() {
super({
id: _AccessibleDiffViewerPrev.id,
title: editorWorkerHost.localize2(112, "Go to Previous Difference"),
category: accessibleDiffViewerCategory,
precondition: editor.ContextKeyExpr.has("isInDiffEditor"),
keybinding: {
primary: 1024 | 65,
weight: 100
/* KeybindingWeight.EditorContrib */
},
f1: true
});
}
run(accessor) {
const diffEditor = findFocusedDiffEditor(accessor);
diffEditor?.accessibleDiffViewerPrev();
}
};
_AccessibleDiffViewerPrev.id = "editor.action.accessibleDiffViewer.prev";
let AccessibleDiffViewerPrev = _AccessibleDiffViewerPrev;
function findDiffEditor(accessor, originalUri, modifiedUri) {
const codeEditorService = accessor.get(editor.ICodeEditorService);
const diffEditors = codeEditorService.listDiffEditors();
return diffEditors.find((diffEditor) => {
const modified = diffEditor.getModifiedEditor();
const original = diffEditor.getOriginalEditor();
return modified && modified.getModel()?.uri.toString() === modifiedUri.toString() && original && original.getModel()?.uri.toString() === originalUri.toString();
}) || null;
}
function findFocusedDiffEditor(accessor) {
const codeEditorService = accessor.get(editor.ICodeEditorService);
const diffEditors = codeEditorService.listDiffEditors();
const activeElement = editor.getActiveElement();
if (activeElement) {
for (const d of diffEditors) {
const container = d.getContainerDomNode();
if (container.contains(activeElement)) {
return d;
}
}
}
return null;
}
editor.registerAction2(ToggleCollapseUnchangedRegions);
editor.registerAction2(ToggleShowMovedCodeBlocks);
editor.registerAction2(ToggleUseInlineViewWhenSpaceIsLimited);
editor.MenuRegistry.appendMenuItem(editor.MenuId.EditorTitle, {
command: {
id: new ToggleUseInlineViewWhenSpaceIsLimited().desc.id,
title: editorWorkerHost.localize(135, "Use Inline View When Space Is Limited"),
toggled: editor.ContextKeyExpr.has("config.diffEditor.useInlineViewWhenSpaceIsLimited"),
precondition: editor.ContextKeyExpr.has("isInDiffEditor")
},
order: 11,
group: "1_diff",
when: editor.ContextKeyExpr.and(editor.EditorContextKeys.diffEditorRenderSideBySideInlineBreakpointReached, editor.ContextKeyExpr.has("isInDiffEditor"))
});
editor.MenuRegistry.appendMenuItem(editor.MenuId.EditorTitle, {
command: {
id: new ToggleShowMovedCodeBlocks().desc.id,
title: editorWorkerHost.localize(136, "Show Moved Code Blocks"),
icon: editorWorkerHost.Codicon.move,
toggled: editor.ContextKeyEqualsExpr.create("config.diffEditor.experimental.showMoves", true),
precondition: editor.ContextKeyExpr.has("isInDiffEditor")
},
order: 10,
group: "1_diff",
when: editor.ContextKeyExpr.has("isInDiffEditor")
});
editor.registerAction2(RevertHunkOrSelection);
for (const ctx of [
{ icon: editorWorkerHost.Codicon.arrowRight, key: editor.EditorContextKeys.diffEditorInlineMode.toNegated() },
{ icon: editorWorkerHost.Codicon.discard, key: editor.EditorContextKeys.diffEditorInlineMode }
]) {
editor.MenuRegistry.appendMenuItem(editor.MenuId.DiffEditorHunkToolbar, {
command: {
id: new RevertHunkOrSelection().desc.id,
title: editorWorkerHost.localize(137, "Revert Block"),
icon: ctx.icon
},
when: editor.ContextKeyExpr.and(editor.EditorContextKeys.diffEditorModifiedWritable, ctx.key),
order: 5,
group: "primary"
});
editor.MenuRegistry.appendMenuItem(editor.MenuId.DiffEditorSelectionToolbar, {
command: {
id: new RevertHunkOrSelection().desc.id,
title: editorWorkerHost.localize(138, "Revert Selection"),
icon: ctx.icon
},
when: editor.ContextKeyExpr.and(editor.EditorContextKeys.diffEditorModifiedWritable, ctx.key),
order: 5,
group: "primary"
});
}
editor.registerAction2(SwitchSide);
editor.registerAction2(ExitCompareMove);
editor.registerAction2(CollapseAllUnchangedRegions);
editor.registerAction2(ShowAllUnchangedRegions);
editor.MenuRegistry.appendMenuItem(editor.MenuId.EditorTitle, {
command: {
id: AccessibleDiffViewerNext.id,
title: editorWorkerHost.localize(139, "Open Accessible Diff Viewer"),
precondition: editor.ContextKeyExpr.has("isInDiffEditor")
},
order: 10,
group: "2_diff",
when: editor.ContextKeyExpr.and(editor.EditorContextKeys.accessibleDiffViewerVisible.negate(), editor.ContextKeyExpr.has("isInDiffEditor"))
});
editor.CommandsRegistry.registerCommandAlias("editor.action.diffReview.next", AccessibleDiffViewerNext.id);
editor.registerAction2(AccessibleDiffViewerNext);
editor.CommandsRegistry.registerCommandAlias("editor.action.diffReview.prev", AccessibleDiffViewerPrev.id);
editor.registerAction2(AccessibleDiffViewerPrev);
var __decorate$1X = function(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i2 = decorators.length - 1; i2 >= 0; i2--) if (d = decorators[i2]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __param$1X = function(paramIndex, decorator) {
return function(target, key) {
decorator(target, key, paramIndex);
};
};
var SelectionAnchorController_1;
const SelectionAnchorSet = new editor.RawContextKey("selectionAnchorSet", false);
let SelectionAnchorController = (_a = class {
static get(editor2) {
return editor2.getContribution(SelectionAnchorController_1.ID);
}
constructor(editor2, contextKeyService) {
this.editor = editor2;
this.selectionAnchorSetContextKey = SelectionAnchorSet.bindTo(contextKeyService);
this.modelChangeListener = editor2.onDidChangeModel(() => this.selectionAnchorSetContextKey.reset());
}
setSelectionAnchor() {
if (this.editor.hasModel()) {
const position = this.editor.getPosition();
this.editor.changeDecorations((accessor) => {
if (this.decorationId) {
accessor.removeDecoration(this.decorationId);
}
this.decorationId = accessor.addDecoration(editorWorkerHost.Selection.fromPositions(position, position), {
description: "selection-anchor",
stickiness: 1,
hoverMessage: new editor.MarkdownString().appendText(editorWorkerHost.localize(834, "Selection Anchor")),
className: "selection-anchor"
});
});
this.selectionAnchorSetContextKey.set(!!this.decorationId);
editor.alert(editorWorkerHost.localize(835, "Anchor set at {0}:{1}", position.lineNumber, position.column));
}
}
goToSelectionAnchor() {
if (this.editor.hasModel() && this.decorationId) {
const anchorPosition = this.editor.getModel().getDecorationRange(this.decorationId);
if (anchorPosition) {
this.editor.setPosition(anchorPosition.getStartPosition());
}
}
}
selectFromAnchorToCursor() {
if (this.editor.hasModel() && this.decorationId) {
const start = this.editor.getModel().getDecorationRange(this.decorationId);
if (start) {
const end = this.editor.getPosition();
this.editor.setSelection(editorWorkerHost.Selection.fromPositions(start.getStartPosition(), end));
this.cancelSelectionAnchor();
}
}
}
cancelSelectionAnchor() {
if (this.decorationId) {
const decorationId = this.decorationId;
this.editor.changeDecorations((accessor) => {
accessor.removeDecoration(decorationId);
this.decorationId = void 0;
});
this.selectionAnchorSetContextKey.set(false);
}
}
dispose() {
this.cancelSelectionAnchor();
this.modelChangeListener.dispose();
}
}, SelectionAnchorController_1 = _a, _a.ID = "editor.contrib.selectionAnchorController", _a);
SelectionAnchorController = SelectionAnchorController_1 = __decorate$1X([
__param$1X(1, editor.IContextKeyService)
], SelectionAnchorController);
class SetSelectionAnchor extends editor.EditorAction {
constructor() {
super({
id: "editor.action.setSelectionAnchor",
label: editorWorkerHost.localize2(836, "Set Selection Anchor"),
precondition: void 0,
kbOpts: {
kbExpr: editor.EditorContextKeys.editorTextFocus,
primary: editorWorkerHost.KeyChord(
2048 | 41,
2048 | 32
/* KeyCode.KeyB */
),
weight: 100
/* KeybindingWeight.EditorContrib */
}
});
}
async run(_accessor, editor2) {
SelectionAnchorController.get(editor2)?.setSelectionAnchor();
}
}
class GoToSelectionAnchor extends editor.EditorAction {
constructor() {
super({
id: "editor.action.goToSelectionAnchor",
label: editorWorkerHost.localize2(837, "Go to Selection Anchor"),
precondition: SelectionAnchorSet
});
}
async run(_accessor, editor2) {
SelectionAnchorController.get(editor2)?.goToSelectionAnchor();
}
}
class SelectFromAnchorToCursor extends editor.EditorAction {
constructor() {
super({
id: "editor.action.selectFromAnchorToCursor",
label: editorWorkerHost.localize2(838, "Select from Anchor to Cursor"),
precondition: SelectionAnchorSet,
kbOpts: {
kbExpr: editor.EditorContextKeys.editorTextFocus,
primary: editorWorkerHost.KeyChord(
2048 | 41,
2048 | 41
/* KeyCode.KeyK */
),
weight: 100
/* KeybindingWeight.EditorContrib */
}
});
}
async run(_accessor, editor2) {
SelectionAnchorController.get(editor2)?.selectFromAnchorToCursor();
}
}
class CancelSelectionAnchor extends editor.EditorAction {
constructor() {
super({
id: "editor.action.cancelSelectionAnchor",
label: editorWorkerHost.localize2(839, "Cancel Selection Anchor"),
precondition: SelectionAnchorSet,
kbOpts: {
kbExpr: editor.EditorContextKeys.editorTextFocus,
primary: 9,
weight: 100
/* KeybindingWeight.EditorContrib */
}
});
}
async run(_accessor, editor2) {
SelectionAnchorController.get(editor2)?.cancelSelectionAnchor();
}
}
editor.registerEditorContribution(
SelectionAnchorController.ID,
SelectionAnchorController,
4
/* EditorContributionInstantiation.Lazy */
);
editor.registerEditorAction(SetSelectionAnchor);
editor.registerEditorAction(GoToSelectionAnchor);
editor.registerEditorAction(SelectFromAnchorToCursor);
editor.registerEditorAction(CancelSelectionAnchor);
const overviewRulerBracketMatchForeground = editor.registerColor("editorOverviewRuler.bracketMatchForeground", "#A0A0A0", editorWorkerHost.localize(840, "Overview ruler marker color for matching brackets."));
class JumpToBracketAction extends editor.EditorAction {
constructor() {
super({
id: "editor.action.jumpToBracket",
label: editorWorkerHost.localize2(842, "Go to Bracket"),
precondition: void 0,
kbOpts: {
kbExpr: editor.EditorContextKeys.editorTextFocus,
primary: 2048 | 1024 | 93,
weight: 100
/* KeybindingWeight.EditorContrib */
}
});
}
run(accessor, editor2) {
BracketMatchingController.get(editor2)?.jumpToBracket();
}
}
class SelectToBracketAction extends editor.EditorAction {
constructor() {
super({
id: "editor.action.selectToBracket",
label: editorWorkerHost.localize2(843, "Select to Bracket"),
precondition: void 0,
metadata: {
description: editorWorkerHost.localize2(844, "Select the text inside and including the brackets or curly braces"),
args: [{
name: "args",
schema: {
type: "object",
properties: {
"selectBrackets": {
type: "boolean",
default: true
}
}
}
}]
}
});
}
run(accessor, editor2, args) {
let selectBrackets = true;
if (args && args.selectBrackets === false) {
selectBrackets = false;
}
BracketMatchingController.get(editor2)?.selectToBracket(selectBrackets);
}
}
class RemoveBracketsAction extends editor.EditorAction {
constructor() {
super({
id: "editor.action.removeBrackets",
label: editorWorkerHost.localize2(845, "Remove Brackets"),
precondition: void 0,
kbOpts: {
kbExpr: editor.EditorContextKeys.editorTextFocus,
primary: 2048 | 512 | 1,
weight: 100
/* KeybindingWeight.EditorContrib */
},
canTriggerInlineEdits: true
});
}
run(accessor, editor2) {
BracketMatchingController.get(editor2)?.removeBrackets(this.id);
}
}
class BracketsData {
constructor(position, brackets, options) {
this.position = position;
this.brackets = brackets;
this.options = options;
}
}
const _BracketMatchingController = class _BracketMatchingController extends editorWorkerHost.Disposable {
static get(editor2) {
return editor2.getContribution(_BracketMatchingController.ID);
}
constructor(editor2) {
super();
this._editor = editor2;
this._lastBracketsData = [];
this._lastVersionId = 0;
this._decorations = this._editor.createDecorationsCollection();
this._updateBracketsSoon = this._register(new editorWorkerHost.RunOnceScheduler(() => this._updateBrackets(), 50));
this._matchBrackets = this._editor.getOption(
80
/* EditorOption.matchBrackets */
);
this._updateBracketsSoon.schedule();
this._register(editor2.onDidChangeCursorPosition((e) => {
if (this._matchBrackets === "never") {
return;
}
this._updateBracketsSoon.schedule();
}));
this._register(editor2.onDidChangeModelContent((e) => {
this._updateBracketsSoon.schedule();
}));
this._register(editor2.onDidChangeModel((e) => {
this._lastBracketsData = [];
this._updateBracketsSoon.schedule();
}));
this._register(editor2.onDidChangeModelLanguageConfiguration((e) => {
this._lastBracketsData = [];
this._updateBracketsSoon.schedule();
}));
this._register(editor2.onDidChangeConfiguration((e) => {
if (e.hasChanged(
80
/* EditorOption.matchBrackets */
)) {
this._matchBrackets = this._editor.getOption(
80
/* EditorOption.matchBrackets */
);
this._decorations.clear();
this._lastBracketsData = [];
this._lastVersionId = 0;
this._updateBracketsSoon.schedule();
}
}));
this._register(editor2.onDidBlurEditorWidget(() => {
this._updateBracketsSoon.schedule();
}));
this._register(editor2.onDidFocusEditorWidget(() => {
this._updateBracketsSoon.schedule();
}));
}
jumpToBracket() {
if (!this._editor.hasModel()) {
return;
}
const model = this._editor.getModel();
const newSelections = this._editor.getSelections().map((selection) => {
const position = selection.getStartPosition();
const brackets = model.bracketPairs.matchBracket(position);
let newCursorPosition = null;
if (brackets) {
if (brackets[0].containsPosition(position) && !brackets[1].containsPosition(position)) {
newCursorPosition = brackets[1].getStartPosition();
} else if (brackets[1].containsPosition(position)) {
newCursorPosition = brackets[0].getStartPosition();
}
} else {
const enclosingBrackets = model.bracketPairs.findEnclosingBrackets(position);
if (enclosingBrackets) {
newCursorPosition = enclosingBrackets[1].getStartPosition();
} else {
const nextBracket = model.bracketPairs.findNextBracket(position);
if (nextBracket && nextBracket.range) {
newCursorPosition = nextBracket.range.getStartPosition();
}
}
}
if (newCursorPosition) {
return new editorWorkerHost.Selection(newCursorPosition.lineNumber, newCursorPosition.column, newCursorPosition.lineNumber, newCursorPosition.column);
}
return new editorWorkerHost.Selection(position.lineNumber, position.column, position.lineNumber, position.column);
});
this._editor.setSelections(newSelections);
this._editor.revealRange(newSelections[0]);
}
selectToBracket(selectBrackets) {
if (!this._editor.hasModel()) {
return;
}
const model = this._editor.getModel();
const newSelections = [];
this._editor.getSelections().forEach((selection) => {
const position = selection.getStartPosition();
let brackets = model.bracketPairs.matchBracket(position);
if (!brackets) {
brackets = model.bracketPairs.findEnclosingBrackets(position);
if (!brackets) {
const nextBracket = model.bracketPairs.findNextBracket(position);
if (nextBracket && nextBracket.range) {
brackets = model.bracketPairs.matchBracket(nextBracket.range.getStartPosition());
}
}
}
let selectFrom = null;
let selectTo = null;
if (brackets) {
brackets.sort(editorWorkerHost.Range.compareRangesUsingStarts);
const [open, close] = brackets;
selectFrom = selectBrackets ? open.getStartPosition() : open.getEndPosition();
selectTo = selectBrackets ? close.getEndPosition() : close.getStartPosition();
if (close.containsPosition(position)) {
const tmp = selectFrom;
selectFrom = selectTo;
selectTo = tmp;
}
}
if (selectFrom && selectTo) {
newSelections.push(new editorWorkerHost.Selection(selectFrom.lineNumber, selectFrom.column, selectTo.lineNumber, selectTo.column));
}
});
if (newSelections.length > 0) {
this._editor.setSelections(newSelections);
this._editor.revealRange(newSelections[0]);
}
}
removeBrackets(editSource) {
if (!this._editor.hasModel()) {
return;
}
const model = this._editor.getModel();
this._editor.getSelections().forEach((selection) => {
const position = selection.getPosition();
let brackets = model.bracketPairs.matchBracket(position);
if (!brackets) {
brackets = model.bracketPairs.findEnclosingBrackets(position);
}
if (brackets) {
this._editor.pushUndoStop();
this._editor.executeEdits(editSource, [
{ range: brackets[0], text: "" },
{ range: brackets[1], text: "" }
]);
this._editor.pushUndoStop();
}
});
}
_updateBrackets() {
if (this._matchBrackets === "never") {
return;
}
this._recomputeBrackets();
const newDecorations = [];
let newDecorationsLen = 0;
for (const bracketData of this._lastBracketsData) {
const brackets = bracketData.brackets;
if (brackets) {
newDecorations[newDecorationsLen++] = { range: brackets[0], options: bracketData.options };
newDecorations[newDecorationsLen++] = { range: brackets[1], options: bracketData.options };
}
}
this._decorations.set(newDecorations);
}
_recomputeBrackets() {
if (!this._editor.hasModel() || !this._editor.hasWidgetFocus()) {
this._lastBracketsData = [];
this._lastVersionId = 0;
return;
}
const selections = this._editor.getSelections();
if (selections.length > 100) {
this._lastBracketsData = [];
this._lastVersionId = 0;
return;
}
const model = this._editor.getModel();
const versionId = model.getVersionId();
let previousData = [];
if (this._lastVersionId === versionId) {
previousData = this._lastBracketsData;
}
const positions = [];
let positionsLen = 0;
for (let i2 = 0, len = selections.length; i2 < len; i2++) {
const selection = selections[i2];
if (selection.isEmpty()) {
positions[positionsLen++] = selection.getStartPosition();
}
}
if (positions.length > 1) {
positions.sort(editorWorkerHost.Position.compare);
}
const newData = [];
let newDataLen = 0;
let previousIndex = 0;
const previousLen = previousData.length;
for (let i2 = 0, len = positions.length; i2 < len; i2++) {
const position = positions[i2];
while (previousIndex < previousLen && previousData[previousIndex].position.isBefore(position)) {
previousIndex++;
}
if (previousIndex < previousLen && previousData[previousIndex].position.equals(position)) {
newData[newDataLen++] = previousData[previousIndex];
} else {
let brackets = model.bracketPairs.matchBracket(
position,
20
/* give at most 20ms to compute */
);
let options = _BracketMatchingController._DECORATION_OPTIONS_WITH_OVERVIEW_RULER;
if (!brackets && this._matchBrackets === "always") {
brackets = model.bracketPairs.findEnclosingBrackets(
position,
20
/* give at most 20ms to compute */
);
options = _BracketMatchingController._DECORATION_OPTIONS_WITHOUT_OVERVIEW_RULER;
}
newData[newDataLen++] = new BracketsData(position, brackets, options);
}
}
this._lastBracketsData = newData;
this._lastVersionId = versionId;
}
};
_BracketMatchingController.ID = "editor.contrib.bracketMatchingController";
_BracketMatchingController._DECORATION_OPTIONS_WITH_OVERVIEW_RULER = editor.ModelDecorationOptions.register({
description: "bracket-match-overview",
stickiness: 1,
className: "bracket-match",
inlineClassName: "bracket-match-inline",
overviewRuler: {
color: editor.themeColorFromId(overviewRulerBracketMatchForeground),
position: editorWorkerHost.OverviewRulerLane.Center
}
});
_BracketMatchingController._DECORATION_OPTIONS_WITHOUT_OVERVIEW_RULER = editor.ModelDecorationOptions.register({
description: "bracket-match-no-overview",
stickiness: 1,
className: "bracket-match",
inlineClassName: "bracket-match-inline"
});
let BracketMatchingController = _BracketMatchingController;
editor.registerEditorContribution(
BracketMatchingController.ID,
BracketMatchingController,
1
/* EditorContributionInstantiation.AfterFirstRender */
);
editor.registerEditorAction(SelectToBracketAction);
editor.registerEditorAction(JumpToBracketAction);
editor.registerEditorAction(RemoveBracketsAction);
editor.MenuRegistry.appendMenuItem(editor.MenuId.MenubarGoMenu, {
group: "5_infile_nav",
command: {
id: "editor.action.jumpToBracket",
title: editorWorkerHost.localize(841, "Go to &&Bracket")
},
order: 2
});
editor.registerThemingParticipant((theme, collector) => {
const bracketMatchForeground = theme.getColor(editor.editorBracketMatchForeground);
if (bracketMatchForeground) {
collector.addRule(`.monaco-editor .bracket-match-inline { color: ${bracketMatchForeground} !important; }`);
}
});
class MoveCaretCommand {
constructor(selection, isMovingLeft) {
this._selection = selection;
this._isMovingLeft = isMovingLeft;
}
getEditOperations(model, builder) {
if (this._selection.startLineNumber !== this._selection.endLineNumber || this._selection.isEmpty()) {
return;
}
const lineNumber = this._selection.startLineNumber;
const startColumn = this._selection.startColumn;
const endColumn = this._selection.endColumn;
if (this._isMovingLeft && startColumn === 1) {
return;
}
if (!this._isMovingLeft && endColumn === model.getLineMaxColumn(lineNumber)) {
return;
}
if (this._isMovingLeft) {
const rangeBefore = new editorWorkerHost.Range(lineNumber, startColumn - 1, lineNumber, startColumn);
const charBefore = model.getValueInRange(rangeBefore);
builder.addEditOperation(rangeBefore, null);
builder.addEditOperation(new editorWorkerHost.Range(lineNumber, endColumn, lineNumber, endColumn), charBefore);
} else {
const rangeAfter = new editorWorkerHost.Range(lineNumber, endColumn, lineNumber, endColumn + 1);
const charAfter = model.getValueInRange(rangeAfter);
builder.addEditOperation(rangeAfter, null);
builder.addEditOperation(new editorWorkerHost.Range(lineNumber, startColumn, lineNumber, startColumn), charAfter);
}
}
computeCursorState(model, helper) {
if (this._isMovingLeft) {
return new editorWorkerHost.Selection(this._selection.startLineNumber, this._selection.startColumn - 1, this._selection.endLineNumber, this._selection.endColumn - 1);
} else {
return new editorWorkerHost.Selection(this._selection.startLineNumber, this._selection.startColumn + 1, this._selection.endLineNumber, this._selection.endColumn + 1);
}
}
}
class MoveCaretAction extends editor.EditorAction {
constructor(left, opts) {
super(opts);
this.left = left;
}
run(accessor, editor2) {
if (!editor2.hasModel()) {
return;
}
const commands = [];
const selections = editor2.getSelections();
for (const selection of selections) {
commands.push(new MoveCaretCommand(selection, this.left));
}
editor2.pushUndoStop();
editor2.executeCommands(this.id, commands);
editor2.pushUndoStop();
}
}
class MoveCaretLeftAction extends MoveCaretAction {
constructor() {
super(true, {
id: "editor.action.moveCarretLeftAction",
label: editorWorkerHost.localize2(846, "Move Selected Text Left"),
precondition: editor.EditorContextKeys.writable
});
}
}
class MoveCaretRightAction extends MoveCaretAction {
constructor() {
super(false, {
id: "editor.action.moveCarretRightAction",
label: editorWorkerHost.localize2(847, "Move Selected Text Right"),
precondition: editor.EditorContextKeys.writable
});
}
}
editor.registerEditorAction(MoveCaretLeftAction);
editor.registerEditorAction(MoveCaretRightAction);
class TransposeLettersAction extends editor.EditorAction {
constructor() {
super({
id: "editor.action.transposeLetters",
label: editorWorkerHost.localize2(848, "Transpose Letters"),
precondition: editor.EditorContextKeys.writable,
kbOpts: {
kbExpr: editor.EditorContextKeys.textInputFocus,
primary: 0,
mac: {
primary: 256 | 50
/* KeyCode.KeyT */
},
weight: 100
/* KeybindingWeight.EditorContrib */
}
});
}
run(accessor, editor$1) {
if (!editor$1.hasModel()) {
return;
}
const model = editor$1.getModel();
const commands = [];
const selections = editor$1.getSelections();
for (const selection of selections) {
if (!selection.isEmpty()) {
continue;
}
const lineNumber = selection.startLineNumber;
const column = selection.startColumn;
const lastColumn = model.getLineMaxColumn(lineNumber);
if (lineNumber === 1 && (column === 1 || column === 2 && lastColumn === 2)) {
continue;
}
const endPosition = column === lastColumn ? selection.getPosition() : editor.MoveOperations.rightPosition(model, selection.getPosition().lineNumber, selection.getPosition().column);
const middlePosition = editor.MoveOperations.leftPosition(model, endPosition);
const beginPosition = editor.MoveOperations.leftPosition(model, middlePosition);
const leftChar = model.getValueInRange(editorWorkerHost.Range.fromPositions(beginPosition, middlePosition));
const rightChar = model.getValueInRange(editorWorkerHost.Range.fromPositions(middlePosition, endPosition));
const replaceRange = editorWorkerHost.Range.fromPositions(beginPosition, endPosition);
commands.push(new editor.ReplaceCommand(replaceRange, rightChar + leftChar));
}
if (commands.length > 0) {
editor$1.pushUndoStop();
editor$1.executeCommands(this.id, commands);
editor$1.pushUndoStop();
}
}
}
editor.registerEditorAction(TransposeLettersAction);
const _HierarchicalKind = class _HierarchicalKind {
constructor(value) {
this.value = value;
}
equals(other) {
return this.value === other.value;
}
contains(other) {
return this.equals(other) || this.value === "" || other.value.startsWith(this.value + _HierarchicalKind.sep);
}
intersects(other) {
return this.contains(other) || other.contains(this);
}
append(...parts) {
return new _HierarchicalKind((this.value ? [this.value, ...parts] : parts).join(_HierarchicalKind.sep));
}
};
_HierarchicalKind.sep = ".";
_HierarchicalKind.None = new _HierarchicalKind("@@none@@");
_HierarchicalKind.Empty = new _HierarchicalKind("");
let HierarchicalKind = _HierarchicalKind;
var __decorate$1W = function(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i2 = decorators.length - 1; i2 >= 0; i2--) if (d = decorators[i2]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __param$1W = function(paramIndex, decorator) {
return function(target, key) {
decorator(target, key, paramIndex);
};
};
const inlineProgressDecoration = editor.ModelDecorationOptions.register({
description: "inline-progress-widget",
stickiness: 1,
showIfCollapsed: true,
after: {
content: editorWorkerHost.noBreakWhitespace,
inlineClassName: "inline-editor-progress-decoration",
inlineClassNameAffectsLetterSpacing: true
}
});
const _InlineProgressWidget = class _InlineProgressWidget extends editorWorkerHost.Disposable {
constructor(typeId, editor2, range, title, delegate) {
super();
this.typeId = typeId;
this.editor = editor2;
this.range = range;
this.delegate = delegate;
this.allowEditorOverflow = false;
this.suppressMouseDown = true;
this.create(title);
this.editor.addContentWidget(this);
this.editor.layoutContentWidget(this);
}
create(title) {
this.domNode = editor.$(".inline-progress-widget");
this.domNode.role = "button";
this.domNode.title = title;
const iconElement = editor.$("span.icon");
this.domNode.append(iconElement);
iconElement.classList.add(...editor.ThemeIcon.asClassNameArray(editorWorkerHost.Codicon.loading), "codicon-modifier-spin");
const updateSize = () => {
const lineHeight = this.editor.getOption(
75
/* EditorOption.lineHeight */
);
this.domNode.style.height = `${lineHeight}px`;
this.domNode.style.width = `${Math.ceil(0.8 * lineHeight)}px`;
};
updateSize();
this._register(this.editor.onDidChangeConfiguration((c) => {
if (c.hasChanged(
61
/* EditorOption.fontSize */
) || c.hasChanged(
75
/* EditorOption.lineHeight */
)) {
updateSize();
}
}));
this._register(editor.addDisposableListener(this.domNode, editor.EventType.CLICK, (e) => {
this.delegate.cancel();
}));
}
getId() {
return _InlineProgressWidget.baseId + "." + this.typeId;
}
getDomNode() {
return this.domNode;
}
getPosition() {
return {
position: { lineNumber: this.range.startLineNumber, column: this.range.startColumn },
preference: [
0
/* ContentWidgetPositionPreference.EXACT */
]
};
}
dispose() {
super.dispose();
this.editor.removeContentWidget(this);
}
};
_InlineProgressWidget.baseId = "editor.widget.inlineProgressWidget";
let InlineProgressWidget = _InlineProgressWidget;
let InlineProgressManager = class InlineProgressManager extends editorWorkerHost.Disposable {
constructor(id, _editor, _instantiationService) {
super();
this.id = id;
this._editor = _editor;
this._instantiationService = _instantiationService;
this._showDelay = 500;
this._showPromise = this._register(new editorWorkerHost.MutableDisposable());
this._currentWidget = this._register(new editorWorkerHost.MutableDisposable());
this._operationIdPool = 0;
this._currentDecorations = _editor.createDecorationsCollection();
}
dispose() {
super.dispose();
this._currentDecorations.clear();
}
async showWhile(position, title, promise, delegate, delayOverride) {
const operationId = this._operationIdPool++;
this._currentOperation = operationId;
this.clear();
this._showPromise.value = editorWorkerHost.disposableTimeout(() => {
const range = editorWorkerHost.Range.fromPositions(position);
const decorationIds = this._currentDecorations.set([{
range,
options: inlineProgressDecoration
}]);
if (decorationIds.length > 0) {
this._currentWidget.value = this._instantiationService.createInstance(InlineProgressWidget, this.id, this._editor, range, title, delegate);
}
}, delayOverride ?? this._showDelay);
try {
return await promise;
} finally {
if (this._currentOperation === operationId) {
this.clear();
this._currentOperation = void 0;
}
}
}
clear() {
this._showPromise.clear();
this._currentDecorations.clear();
this._currentWidget.clear();
}
};
InlineProgressManager = __decorate$1W([
__param$1W(2, editor.IInstantiationService)
], InlineProgressManager);
var __decorate$1V = function(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i2 = decorators.length - 1; i2 >= 0; i2--) if (d = decorators[i2]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __param$1V = function(paramIndex, decorator) {
return function(target, key) {
decorator(target, key, paramIndex);
};
};
var MessageController_1;
let MessageController = (_b = class {
static get(editor2) {
return editor2.getContribution(MessageController_1.ID);
}
constructor(editor2, contextKeyService, _openerService) {
this._openerService = _openerService;
this._messageWidget = new editorWorkerHost.MutableDisposable();
this._messageListeners = new editorWorkerHost.DisposableStore();
this._mouseOverMessage = false;
this._editor = editor2;
this._visible = MessageController_1.MESSAGE_VISIBLE.bindTo(contextKeyService);
}
dispose() {
this._messageListeners.dispose();
this._messageWidget.dispose();
this._visible.reset();
}
showMessage(message, position) {
editor.alert(editor.isMarkdownString(message) ? message.value : message);
this._visible.set(true);
this._messageWidget.clear();
this._messageListeners.clear();
if (editor.isMarkdownString(message)) {
const renderedMessage = this._messageListeners.add(editor.renderMarkdown(message, {
actionHandler: (url, mdStr) => {
this.closeMessage();
editor.openLinkFromMarkdown(this._openerService, url, mdStr.isTrusted);
}
}));
this._messageWidget.value = new MessageWidget$1(this._editor, position, renderedMessage.element);
} else {
this._messageWidget.value = new MessageWidget$1(this._editor, position, message);
}
this._messageListeners.add(editorWorkerHost.Event.debounce(this._editor.onDidBlurEditorText, (last, event) => event, 0)(() => {
if (this._mouseOverMessage) {
return;
}
if (this._messageWidget.value && editor.isAncestor(editor.getActiveElement(), this._messageWidget.value.getDomNode())) {
return;
}
this.closeMessage();
}));
this._messageListeners.add(this._editor.onDidChangeCursorPosition(() => this.closeMessage()));
this._messageListeners.add(this._editor.onDidDispose(() => this.closeMessage()));
this._messageListeners.add(this._editor.onDidChangeModel(() => this.closeMessage()));
this._messageListeners.add(editor.addDisposableListener(this._messageWidget.value.getDomNode(), editor.EventType.MOUSE_ENTER, () => this._mouseOverMessage = true, true));
this._messageListeners.add(editor.addDisposableListener(this._messageWidget.value.getDomNode(), editor.EventType.MOUSE_LEAVE, () => this._mouseOverMessage = false, true));
let bounds;
this._messageListeners.add(this._editor.onMouseMove((e) => {
if (!e.target.position) {
return;
}
if (!bounds) {
bounds = new editorWorkerHost.Range(position.lineNumber - 3, 1, e.target.position.lineNumber + 3, 1);
} else if (!bounds.containsPosition(e.target.position)) {
this.closeMessage();
}
}));
}
closeMessage() {
this._visible.reset();
this._messageListeners.clear();
if (this._messageWidget.value) {
this._messageListeners.add(MessageWidget$1.fadeOut(this._messageWidget.value));
}
}
}, MessageController_1 = _b, _b.ID = "editor.contrib.messageController", _b.MESSAGE_VISIBLE = new editor.RawContextKey("messageVisible", false, editorWorkerHost.localize(1333, "Whether the editor is currently showing an inline message")), _b);
MessageController = MessageController_1 = __decorate$1V([
__param$1V(1, editor.IContextKeyService),
__param$1V(2, editor.IOpenerService)
], MessageController);
const MessageCommand = editor.EditorCommand.bindToContribution(MessageController.get);
editor.registerEditorCommand(new MessageCommand({
id: "leaveEditorMessage",
precondition: MessageController.MESSAGE_VISIBLE,
handler: (c) => c.closeMessage(),
kbOpts: {
weight: 100 + 30,
primary: 9
/* KeyCode.Escape */
}
}));
let MessageWidget$1 = class MessageWidget {
static fadeOut(messageWidget) {
const dispose = () => {
messageWidget.dispose();
clearTimeout(handle);
messageWidget.getDomNode().removeEventListener("animationend", dispose);
};
const handle = setTimeout(dispose, 110);
messageWidget.getDomNode().addEventListener("animationend", dispose);
messageWidget.getDomNode().classList.add("fadeOut");
return { dispose };
}
constructor(editor2, { lineNumber, column }, text) {
this.allowEditorOverflow = true;
this.suppressMouseDown = false;
this._editor = editor2;
this._editor.revealLinesInCenterIfOutsideViewport(
lineNumber,
lineNumber,
0
/* ScrollType.Smooth */
);
this._position = { lineNumber, column };
this._domNode = document.createElement("div");
this._domNode.classList.add("monaco-editor-overlaymessage");
this._domNode.style.marginLeft = "-6px";
const anchorTop = document.createElement("div");
anchorTop.classList.add("anchor", "top");
this._domNode.appendChild(anchorTop);
const message = document.createElement("div");
if (typeof text === "string") {
message.classList.add("message");
message.textContent = text;
} else {
text.classList.add("message");
message.appendChild(text);
}
this._domNode.appendChild(message);
const anchorBottom = document.createElement("div");
anchorBottom.classList.add("anchor", "below");
this._domNode.appendChild(anchorBottom);
this._editor.addContentWidget(this);
this._domNode.classList.add("fadeIn");
}
dispose() {
this._editor.removeContentWidget(this);
}
getId() {
return "messageoverlay";
}
getDomNode() {
return this._domNode;
}
getPosition() {
return {
position: this._position,
preference: [
1,
2
],
positionAffinity: 1
};
}
afterRender(position) {
this._domNode.classList.toggle(
"below",
position === 2
/* ContentWidgetPositionPreference.BELOW */
);
}
};
editor.registerEditorContribution(
MessageController.ID,
MessageController,
4
/* EditorContributionInstantiation.Lazy */
);
var __decorate$1U = function(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropert