@codingame/monaco-editor-wrapper 4.0.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/keybindings/vim.d.ts +1 -1
- package/dist/main.js +1 -1
- package/dist/services.js +1 -6
- package/dist/tools.d.ts +15 -3
- package/dist/tools.js +286 -27
- package/package.json +2 -1
- package/stats.html +1 -1
- package/dist/node_modules/@codingame/monaco-vscode-files-service-override/external/tslib/tslib.es6.js +0 -11
- package/dist/node_modules/@codingame/monaco-vscode-files-service-override/files.js +0 -396
- package/dist/node_modules/@codingame/monaco-vscode-files-service-override/override/vs/platform/dialogs/common/dialogs.js +0 -8
- package/dist/node_modules/@codingame/monaco-vscode-files-service-override/vscode/src/vs/platform/files/browser/indexedDBFileSystemProvider.js +0 -406
- package/dist/node_modules/@codingame/monaco-vscode-files-service-override/vscode/src/vs/platform/files/common/fileService.js +0 -989
- package/dist/node_modules/@codingame/monaco-vscode-files-service-override/vscode/src/vs/platform/files/common/io.js +0 -77
- package/dist/node_modules/@codingame/monaco-vscode-files-service-override/vscode/src/vs/workbench/services/textfile/browser/browserTextFileService.js +0 -58
- package/dist/node_modules/@codingame/monaco-vscode-files-service-override/vscode/src/vs/workbench/services/textfile/browser/textFileService.js +0 -641
- package/dist/node_modules/@codingame/monaco-vscode-files-service-override/vscode/src/vs/workbench/services/textfile/common/textFileEditorModelManager.js +0 -404
- package/dist/node_modules/@codingame/monaco-vscode-files-service-override/vscode/src/vs/workbench/services/textfile/common/textFileSaveParticipant.js +0 -64
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { IDisposable } from 'monaco-editor';
|
|
2
2
|
import * as monaco from 'monaco-editor';
|
|
3
|
-
export declare function initVimMode(editor: monaco.editor.
|
|
3
|
+
export declare function initVimMode(editor: monaco.editor.ICodeEditor, statusBarElement: Element): IDisposable;
|
package/dist/main.js
CHANGED
|
@@ -6,5 +6,5 @@ export { getMonacoLanguage, loadLanguage } from './languages/index.js';
|
|
|
6
6
|
export { updateEditorKeybindingsMode, updateKeybindings } from './keybindings/index.js';
|
|
7
7
|
import './style.js';
|
|
8
8
|
export { setUseGlobalPicker } from './services.js';
|
|
9
|
-
export { collapseCodeSections, hideCodeWithoutDecoration, lockCodeWithoutDecoration } from './tools.js';
|
|
9
|
+
export { addPlaceholder, collapseCodeSections, hideCodeWithoutDecoration, lockCodeWithoutDecoration, mapClipboard, preventAlwaysConsumeTouchEvent, registerTextDecorationProvider, runOnAllEditors } from './tools.js';
|
|
10
10
|
export { getUserConfiguration, onUserConfigurationChange, updateUserConfiguration } from '@codingame/monaco-vscode-configuration-service-override';
|
package/dist/services.js
CHANGED
|
@@ -19,12 +19,7 @@ import getLogServiceOverride from '@codingame/monaco-vscode-log-service-override
|
|
|
19
19
|
import getWorkingCopyServiceOverride from '@codingame/monaco-vscode-working-copy-service-override';
|
|
20
20
|
import { initialize as initialize$1, StandaloneServices, ILogService, LogLevel } from 'vscode/services';
|
|
21
21
|
import * as monaco from 'monaco-editor';
|
|
22
|
-
import { initFile } from '
|
|
23
|
-
import 'vscode/vscode/vs/platform/files/common/files';
|
|
24
|
-
import 'vscode/vscode/vs/platform/files/browser/htmlFileSystemProvider';
|
|
25
|
-
import 'vscode/vscode/vs/platform/files/common/inMemoryFilesystemProvider';
|
|
26
|
-
import 'vscode/vscode/vs/base/browser/indexedDB';
|
|
27
|
-
import './node_modules/@codingame/monaco-vscode-files-service-override/vscode/src/vs/platform/files/browser/indexedDBFileSystemProvider.js';
|
|
22
|
+
import { initFile } from '@codingame/monaco-vscode-files-service-override';
|
|
28
23
|
import EditorOpenHandlerRegistry from './tools/EditorOpenHandlerRegistry.js';
|
|
29
24
|
import 'vscode/localExtensionHost';
|
|
30
25
|
|
package/dist/tools.d.ts
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import * as monaco from 'monaco-editor';
|
|
2
|
-
export declare function lockCodeWithoutDecoration(editor: monaco.editor.
|
|
3
|
-
export declare function hideCodeWithoutDecoration(editor: monaco.editor.
|
|
2
|
+
export declare function lockCodeWithoutDecoration(editor: monaco.editor.ICodeEditor, decorationFilter: (decoration: monaco.editor.IModelDecoration) => boolean, allowChangeFromSources?: string[], errorMessage?: string): monaco.IDisposable;
|
|
3
|
+
export declare function hideCodeWithoutDecoration(editor: monaco.editor.ICodeEditor, decorationFilter: (decoration: monaco.editor.IModelDecoration) => boolean): monaco.IDisposable;
|
|
4
4
|
/**
|
|
5
5
|
* Collapse everything between startToken and endToken
|
|
6
6
|
*/
|
|
7
|
-
export declare function collapseCodeSections(editor: monaco.editor.
|
|
7
|
+
export declare function collapseCodeSections(editor: monaco.editor.ICodeEditor, startToken: string, endToken: string, isRegex?: boolean): Promise<void>;
|
|
8
|
+
interface IDecorationProvider {
|
|
9
|
+
provideDecorations(model: monaco.editor.ITextModel): monaco.editor.IModelDeltaDecoration[];
|
|
10
|
+
}
|
|
11
|
+
export declare function registerTextDecorationProvider(provider: IDecorationProvider): monaco.IDisposable;
|
|
12
|
+
export declare function runOnAllEditors(cb: (editor: monaco.editor.ICodeEditor) => monaco.IDisposable): monaco.IDisposable;
|
|
13
|
+
export declare function preventAlwaysConsumeTouchEvent(editor: monaco.editor.ICodeEditor): void;
|
|
14
|
+
export declare function addPlaceholder(editor: monaco.editor.ICodeEditor, placeholder: string): monaco.IDisposable;
|
|
15
|
+
export declare function mapClipboard(editor: monaco.editor.ICodeEditor, { toClipboard, fromClipboard }: {
|
|
16
|
+
toClipboard: (data: string) => string;
|
|
17
|
+
fromClipboard: (data: string) => string;
|
|
18
|
+
}): monaco.IDisposable;
|
|
19
|
+
export {};
|
package/dist/tools.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import * as monaco from 'monaco-editor';
|
|
2
|
+
import { DisposableStore, KeybindingsRegistry, ContextKeyExpr } from 'vscode/monaco';
|
|
2
3
|
|
|
3
4
|
function isPasteAction(handlerId, payload) {
|
|
4
5
|
return handlerId === 'paste';
|
|
5
6
|
}
|
|
6
|
-
function lockCodeWithoutDecoration(editor,
|
|
7
|
+
function lockCodeWithoutDecoration(editor, decorationFilter, allowChangeFromSources = [], errorMessage) {
|
|
8
|
+
const disposableStore = new DisposableStore();
|
|
7
9
|
function displayLockedCodeError(position) {
|
|
8
10
|
if (errorMessage == null) {
|
|
9
11
|
return;
|
|
@@ -14,8 +16,14 @@ function lockCodeWithoutDecoration(editor, decorations, allowChangeFromSources =
|
|
|
14
16
|
function canEditRange(range) {
|
|
15
17
|
const model = editor.getModel();
|
|
16
18
|
if (model != null) {
|
|
17
|
-
const editableRanges =
|
|
18
|
-
|
|
19
|
+
const editableRanges = model
|
|
20
|
+
.getAllDecorations()
|
|
21
|
+
.filter(decorationFilter)
|
|
22
|
+
.map((decoration) => decoration.range);
|
|
23
|
+
if (editableRanges.length === 0) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
return editableRanges.some((editableRange) => editableRange.containsRange(range));
|
|
19
27
|
}
|
|
20
28
|
return false;
|
|
21
29
|
}
|
|
@@ -34,7 +42,12 @@ function lockCodeWithoutDecoration(editor, decorations, allowChangeFromSources =
|
|
|
34
42
|
const originalTrigger = editor.trigger;
|
|
35
43
|
editor.trigger = function (source, handlerId, payload) {
|
|
36
44
|
// Try to transform whole file pasting into a paste in the editable area only
|
|
37
|
-
const
|
|
45
|
+
const editableRanges = editor
|
|
46
|
+
.getModel()
|
|
47
|
+
.getAllDecorations()
|
|
48
|
+
.filter(decorationFilter)
|
|
49
|
+
.map((decoration) => decoration.range);
|
|
50
|
+
const lastEditableRange = editableRanges.length > 0 ? editableRanges[editableRanges.length - 1] : undefined;
|
|
38
51
|
if (isPasteAction(handlerId) && lastEditableRange != null) {
|
|
39
52
|
const selections = editor.getSelections();
|
|
40
53
|
const model = editor.getModel();
|
|
@@ -47,7 +60,8 @@ function lockCodeWithoutDecoration(editor, decorations, allowChangeFromSources =
|
|
|
47
60
|
const before = model.getOffsetAt(lastEditableRange.getStartPosition());
|
|
48
61
|
const after = currentEditorValue.length - model.getOffsetAt(lastEditableRange.getEndPosition());
|
|
49
62
|
if (currentEditorValue.slice(0, before) === payload.text.slice(0, before) &&
|
|
50
|
-
currentEditorValue.slice(currentEditorValue.length - after) ===
|
|
63
|
+
currentEditorValue.slice(currentEditorValue.length - after) ===
|
|
64
|
+
payload.text.slice(payload.text.length - after)) {
|
|
51
65
|
editor.setSelection(lastEditableRange);
|
|
52
66
|
const newPayload = {
|
|
53
67
|
...payload,
|
|
@@ -60,7 +74,7 @@ function lockCodeWithoutDecoration(editor, decorations, allowChangeFromSources =
|
|
|
60
74
|
}
|
|
61
75
|
if (['type', 'paste', 'cut'].includes(handlerId)) {
|
|
62
76
|
const selections = editor.getSelections();
|
|
63
|
-
if (selections != null && selections.some(range => !canEditRange(range))) {
|
|
77
|
+
if (selections != null && selections.some((range) => !canEditRange(range))) {
|
|
64
78
|
displayLockedCodeError(editor.getPosition());
|
|
65
79
|
return;
|
|
66
80
|
}
|
|
@@ -90,8 +104,7 @@ function lockCodeWithoutDecoration(editor, decorations, allowChangeFromSources =
|
|
|
90
104
|
if (currentEditSource != null && allowChangeFromSources.includes(currentEditSource)) {
|
|
91
105
|
return originalApplyEdit.call(model, operations, computeUndoEdits);
|
|
92
106
|
}
|
|
93
|
-
const filteredOperations = operations
|
|
94
|
-
.filter(operation => canEditRange(operation.range));
|
|
107
|
+
const filteredOperations = operations.filter((operation) => canEditRange(operation.range));
|
|
95
108
|
if (filteredOperations.length === 0 && operations.length > 0) {
|
|
96
109
|
const firstRange = operations[0].range;
|
|
97
110
|
displayLockedCodeError(new monaco.Position(firstRange.startLineNumber, firstRange.startColumn));
|
|
@@ -102,10 +115,10 @@ function lockCodeWithoutDecoration(editor, decorations, allowChangeFromSources =
|
|
|
102
115
|
model.applyEdits = originalApplyEdit;
|
|
103
116
|
};
|
|
104
117
|
}
|
|
105
|
-
|
|
118
|
+
disposableStore.add(editor.onDidChangeModel(lockModel));
|
|
106
119
|
lockModel();
|
|
107
120
|
// Handle selection of the last line of an editable range
|
|
108
|
-
|
|
121
|
+
disposableStore.add(editor.onDidChangeCursorSelection((e) => {
|
|
109
122
|
if (canEditRange(e.selection)) {
|
|
110
123
|
return;
|
|
111
124
|
}
|
|
@@ -117,23 +130,31 @@ function lockCodeWithoutDecoration(editor, decorations, allowChangeFromSources =
|
|
|
117
130
|
if (canEditRange(shiftedRange)) {
|
|
118
131
|
editor.setSelection(shiftedRange);
|
|
119
132
|
}
|
|
133
|
+
}));
|
|
134
|
+
disposableStore.add({
|
|
135
|
+
dispose() {
|
|
136
|
+
restoreModelApplyEdit();
|
|
137
|
+
editor.executeEdits = originalExecuteEdit;
|
|
138
|
+
editor.executeCommands = originalExecuteCommands;
|
|
139
|
+
editor.trigger = originalTrigger;
|
|
140
|
+
}
|
|
120
141
|
});
|
|
121
|
-
return
|
|
122
|
-
selectionDisposable.dispose();
|
|
123
|
-
restoreModelApplyEdit();
|
|
124
|
-
editorChangeModelDisposable.dispose();
|
|
125
|
-
editor.executeEdits = originalExecuteEdit;
|
|
126
|
-
editor.executeCommands = originalExecuteCommands;
|
|
127
|
-
editor.trigger = originalTrigger;
|
|
128
|
-
};
|
|
142
|
+
return disposableStore;
|
|
129
143
|
}
|
|
130
|
-
function hideCodeWithoutDecoration(editor,
|
|
131
|
-
|
|
132
|
-
let otherHiddenAreas = editor._getViewModel()._lines.getHiddenAreas();
|
|
144
|
+
function hideCodeWithoutDecoration(editor, decorationFilter) {
|
|
145
|
+
let otherHiddenAreas = editor._getViewModel()?.getHiddenAreas() ?? [];
|
|
133
146
|
function getHiddenAreas() {
|
|
134
147
|
const model = editor.getModel();
|
|
148
|
+
if (model == null) {
|
|
149
|
+
return [];
|
|
150
|
+
}
|
|
151
|
+
const decorations = model.getAllDecorations()
|
|
152
|
+
.filter(decorationFilter);
|
|
153
|
+
if (decorations.length === 0) {
|
|
154
|
+
return otherHiddenAreas;
|
|
155
|
+
}
|
|
135
156
|
const ranges = decorations
|
|
136
|
-
.map(decoration =>
|
|
157
|
+
.map(decoration => decoration.range)
|
|
137
158
|
.sort((a, b) => a.startLineNumber - b.startLineNumber)
|
|
138
159
|
// merge ranges
|
|
139
160
|
.reduce((acc, range) => {
|
|
@@ -180,11 +201,22 @@ function hideCodeWithoutDecoration(editor, decorations) {
|
|
|
180
201
|
otherHiddenAreas = ranges;
|
|
181
202
|
updateHiddenAreas();
|
|
182
203
|
};
|
|
204
|
+
const disposableStore = new DisposableStore();
|
|
205
|
+
disposableStore.add(editor.onDidChangeModel(() => {
|
|
206
|
+
otherHiddenAreas = editor._getViewModel()?.getHiddenAreas() ?? [];
|
|
207
|
+
updateHiddenAreas();
|
|
208
|
+
}));
|
|
209
|
+
disposableStore.add(editor.onDidChangeModelDecorations(() => {
|
|
210
|
+
updateHiddenAreas();
|
|
211
|
+
}));
|
|
183
212
|
updateHiddenAreas();
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
213
|
+
disposableStore.add({
|
|
214
|
+
dispose() {
|
|
215
|
+
editor.setHiddenAreas = originalSetHiddenAreas;
|
|
216
|
+
editor.setHiddenAreas(otherHiddenAreas);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
return disposableStore;
|
|
188
220
|
}
|
|
189
221
|
/**
|
|
190
222
|
* Collapse everything between startToken and endToken
|
|
@@ -231,5 +263,232 @@ async function collapseCodeSections(editor, startToken, endToken, isRegex = fals
|
|
|
231
263
|
}
|
|
232
264
|
}
|
|
233
265
|
}
|
|
266
|
+
function registerTextDecorationProvider(provider) {
|
|
267
|
+
const disposableStore = new DisposableStore();
|
|
268
|
+
const watchEditor = (editor) => {
|
|
269
|
+
const disposableStore = new DisposableStore();
|
|
270
|
+
const decorationCollection = editor.createDecorationsCollection();
|
|
271
|
+
const checkEditor = () => {
|
|
272
|
+
const model = editor.getModel();
|
|
273
|
+
if (model != null) {
|
|
274
|
+
decorationCollection.set(provider.provideDecorations(model));
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
decorationCollection.clear();
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
disposableStore.add(editor.onDidChangeModel(checkEditor));
|
|
281
|
+
disposableStore.add(editor.onDidChangeModelContent(checkEditor));
|
|
282
|
+
disposableStore.add({
|
|
283
|
+
dispose() {
|
|
284
|
+
decorationCollection.clear();
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
checkEditor();
|
|
288
|
+
return disposableStore;
|
|
289
|
+
};
|
|
290
|
+
monaco.editor.getEditors().forEach(editor => disposableStore.add(watchEditor(editor)));
|
|
291
|
+
disposableStore.add(monaco.editor.onDidCreateEditor(editor => disposableStore.add(watchEditor(editor))));
|
|
292
|
+
return disposableStore;
|
|
293
|
+
}
|
|
294
|
+
function runOnAllEditors(cb) {
|
|
295
|
+
const disposableStore = new DisposableStore();
|
|
296
|
+
const handleEditor = (editor) => {
|
|
297
|
+
const disposable = cb(editor);
|
|
298
|
+
disposableStore.add(disposable);
|
|
299
|
+
const disposeEventDisposable = editor.onDidDispose(() => {
|
|
300
|
+
disposableStore.delete(disposable);
|
|
301
|
+
disposableStore.delete(disposeEventDisposable);
|
|
302
|
+
});
|
|
303
|
+
disposableStore.add(disposeEventDisposable);
|
|
304
|
+
};
|
|
305
|
+
monaco.editor.getEditors().forEach(handleEditor);
|
|
306
|
+
disposableStore.add(monaco.editor.onDidCreateEditor(handleEditor));
|
|
307
|
+
return disposableStore;
|
|
308
|
+
}
|
|
309
|
+
function preventAlwaysConsumeTouchEvent(editor) {
|
|
310
|
+
let firstX = 0;
|
|
311
|
+
let firstY = 0;
|
|
312
|
+
let atTop = false;
|
|
313
|
+
let atBottom = false;
|
|
314
|
+
let atLeft = false;
|
|
315
|
+
let atRight = false;
|
|
316
|
+
let useBrowserBehavior = null;
|
|
317
|
+
editor.onDidChangeModel(() => {
|
|
318
|
+
const domNode = editor.getDomNode();
|
|
319
|
+
if (domNode == null) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
domNode.addEventListener('touchstart', (e) => {
|
|
323
|
+
const firstTouch = e.targetTouches.item(0);
|
|
324
|
+
if (firstTouch == null) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
// Prevent monaco-editor from trying to call preventDefault on the touchstart event
|
|
328
|
+
// so we'll be able to use the default behavior of the touchmove event
|
|
329
|
+
e.preventDefault = () => { };
|
|
330
|
+
firstX = firstTouch.clientX;
|
|
331
|
+
firstY = firstTouch.clientY;
|
|
332
|
+
const layoutInfo = editor.getLayoutInfo();
|
|
333
|
+
atTop = editor.getScrollTop() <= 0;
|
|
334
|
+
atBottom = editor.getScrollTop() >= editor.getContentHeight() - layoutInfo.height;
|
|
335
|
+
atLeft = editor.getScrollLeft() <= 0;
|
|
336
|
+
atRight = editor.getScrollLeft() >= editor.getContentWidth() - layoutInfo.width;
|
|
337
|
+
useBrowserBehavior = null;
|
|
338
|
+
});
|
|
339
|
+
domNode.addEventListener('touchmove', (e) => {
|
|
340
|
+
const firstTouch = e.changedTouches.item(0);
|
|
341
|
+
if (firstTouch == null) {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
if (useBrowserBehavior == null) {
|
|
345
|
+
const dx = firstTouch.clientX - firstX;
|
|
346
|
+
const dy = firstTouch.clientY - firstY;
|
|
347
|
+
if (Math.abs(dx) > Math.abs(dy)) {
|
|
348
|
+
// It's an horizontal scroll
|
|
349
|
+
useBrowserBehavior = (dx < 0 && atRight) || (dx > 0 && atLeft);
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
// It's a vertical scroll
|
|
353
|
+
useBrowserBehavior = (dy < 0 && atBottom) || (dy > 0 && atTop);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
if (useBrowserBehavior) {
|
|
357
|
+
// Stop the event before monaco tries to preventDefault on it
|
|
358
|
+
e.stopPropagation();
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
domNode.addEventListener('touchend', (e) => {
|
|
362
|
+
if (useBrowserBehavior ?? false) {
|
|
363
|
+
// Prevent monaco from trying to open its context menu
|
|
364
|
+
// It thinks it's a long press because it didn't receive the move events
|
|
365
|
+
e.stopPropagation();
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
// https://github.com/microsoft/monaco-editor/issues/568
|
|
371
|
+
class PlaceholderContentWidget {
|
|
372
|
+
constructor(editor, placeholder) {
|
|
373
|
+
this.editor = editor;
|
|
374
|
+
this.placeholder = placeholder;
|
|
375
|
+
}
|
|
376
|
+
getId() {
|
|
377
|
+
return PlaceholderContentWidget.ID;
|
|
378
|
+
}
|
|
379
|
+
getDomNode() {
|
|
380
|
+
if (this.domNode == null) {
|
|
381
|
+
this.domNode = document.createElement('pre');
|
|
382
|
+
this.domNode.style.width = 'max-content';
|
|
383
|
+
this.domNode.textContent = this.placeholder;
|
|
384
|
+
this.domNode.style.pointerEvents = 'none';
|
|
385
|
+
this.domNode.style.color = '#aaa';
|
|
386
|
+
this.domNode.style.margin = '0';
|
|
387
|
+
this.editor.applyFontInfo(this.domNode);
|
|
388
|
+
}
|
|
389
|
+
return this.domNode;
|
|
390
|
+
}
|
|
391
|
+
getPosition() {
|
|
392
|
+
return {
|
|
393
|
+
position: { lineNumber: 1, column: 1 },
|
|
394
|
+
preference: [monaco.editor.ContentWidgetPositionPreference.EXACT]
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
PlaceholderContentWidget.ID = 'editor.widget.placeholderHint';
|
|
399
|
+
function addPlaceholder(editor, placeholder) {
|
|
400
|
+
const widget = new PlaceholderContentWidget(editor, placeholder);
|
|
401
|
+
function onDidChangeModelContent() {
|
|
402
|
+
if (editor.getValue() === '') {
|
|
403
|
+
editor.addContentWidget(widget);
|
|
404
|
+
}
|
|
405
|
+
else {
|
|
406
|
+
editor.removeContentWidget(widget);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
onDidChangeModelContent();
|
|
410
|
+
const changeDisposable = editor.onDidChangeModelContent(() => onDidChangeModelContent());
|
|
411
|
+
return {
|
|
412
|
+
dispose() {
|
|
413
|
+
changeDisposable.dispose();
|
|
414
|
+
editor.removeContentWidget(widget);
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
function mapClipboard(editor, { toClipboard, fromClipboard }) {
|
|
419
|
+
const disposableStore = new DisposableStore();
|
|
420
|
+
let copiedText = '';
|
|
421
|
+
disposableStore.add(KeybindingsRegistry.registerCommandAndKeybindingRule({
|
|
422
|
+
id: 'customCopy',
|
|
423
|
+
weight: 1000,
|
|
424
|
+
handler: () => {
|
|
425
|
+
copiedText = editor.getModel().getValueInRange(editor.getSelection());
|
|
426
|
+
document.execCommand('copy');
|
|
427
|
+
},
|
|
428
|
+
when: ContextKeyExpr.equals('editorId', editor.getId()),
|
|
429
|
+
primary: monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyC
|
|
430
|
+
}));
|
|
431
|
+
disposableStore.add(KeybindingsRegistry.registerCommandAndKeybindingRule({
|
|
432
|
+
id: 'customCut',
|
|
433
|
+
weight: 1000,
|
|
434
|
+
handler: () => {
|
|
435
|
+
copiedText = editor.getModel().getValueInRange(editor.getSelection());
|
|
436
|
+
document.execCommand('copy');
|
|
437
|
+
},
|
|
438
|
+
when: ContextKeyExpr.equals('editorId', editor.getId()),
|
|
439
|
+
primary: monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyX
|
|
440
|
+
}));
|
|
441
|
+
const originalTrigger = editor.trigger;
|
|
442
|
+
editor.trigger = function (source, handlerId, payload) {
|
|
443
|
+
if (handlerId === 'editor.action.clipboardCopyAction') {
|
|
444
|
+
copiedText = editor.getModel().getValueInRange(editor.getSelection());
|
|
445
|
+
}
|
|
446
|
+
else if (handlerId === 'editor.action.clipboardCutAction') {
|
|
447
|
+
copiedText = editor.getModel().getValueInRange(editor.getSelection());
|
|
448
|
+
}
|
|
449
|
+
else if (handlerId === 'paste') {
|
|
450
|
+
const newText = fromClipboard(payload.text);
|
|
451
|
+
if (newText !== payload.text) {
|
|
452
|
+
payload = {
|
|
453
|
+
...payload,
|
|
454
|
+
text: newText
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
originalTrigger.call(this, source, handlerId, payload);
|
|
459
|
+
};
|
|
460
|
+
disposableStore.add({
|
|
461
|
+
dispose() {
|
|
462
|
+
editor.trigger = originalTrigger;
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
function mapCopy(event) {
|
|
466
|
+
const clipdata = event.clipboardData ?? window.clipboardData;
|
|
467
|
+
let content = clipdata.getData('Text');
|
|
468
|
+
if (content.length === 0) {
|
|
469
|
+
content = copiedText;
|
|
470
|
+
}
|
|
471
|
+
const transformed = toClipboard(content);
|
|
472
|
+
if (transformed !== content) {
|
|
473
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
474
|
+
if (clipdata.types != null) {
|
|
475
|
+
clipdata.types.forEach(type => clipdata.setData(type, toClipboard(content)));
|
|
476
|
+
}
|
|
477
|
+
else {
|
|
478
|
+
clipdata.setData('text/plain', toClipboard(content));
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
const editorDomNode = editor.getContainerDomNode();
|
|
483
|
+
editorDomNode.addEventListener('copy', mapCopy);
|
|
484
|
+
editorDomNode.addEventListener('cut', mapCopy);
|
|
485
|
+
disposableStore.add({
|
|
486
|
+
dispose() {
|
|
487
|
+
editorDomNode.removeEventListener('copy', mapCopy);
|
|
488
|
+
editorDomNode.removeEventListener('cut', mapCopy);
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
return disposableStore;
|
|
492
|
+
}
|
|
234
493
|
|
|
235
|
-
export { collapseCodeSections, hideCodeWithoutDecoration, lockCodeWithoutDecoration };
|
|
494
|
+
export { addPlaceholder, collapseCodeSections, hideCodeWithoutDecoration, lockCodeWithoutDecoration, mapClipboard, preventAlwaysConsumeTouchEvent, registerTextDecorationProvider, runOnAllEditors };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codingame/monaco-editor-wrapper",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Enhanced Monaco editor with TextMate grammars and more",
|
|
6
6
|
"scripts": {
|
|
@@ -82,6 +82,7 @@
|
|
|
82
82
|
"@codingame/monaco-vscode-diff-default-extension": "~2.0.0",
|
|
83
83
|
"@codingame/monaco-vscode-editor-service-override": "~2.0.0",
|
|
84
84
|
"@codingame/monaco-vscode-extensions-service-override": "~2.0.0",
|
|
85
|
+
"@codingame/monaco-vscode-files-service-override": "~2.0.2",
|
|
85
86
|
"@codingame/monaco-vscode-fsharp-default-extension": "~2.0.0",
|
|
86
87
|
"@codingame/monaco-vscode-go-default-extension": "~2.0.0",
|
|
87
88
|
"@codingame/monaco-vscode-groovy-default-extension": "~2.0.0",
|