@codingame/monaco-editor-wrapper 1.8.1 → 1.9.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/features/htmlContribution.d.ts +3 -0
- package/dist/features/htmlContribution.js +104 -0
- package/dist/index.js +1210 -0
- package/dist/main.js +3 -1208
- package/package.json +1 -1
- package/stats.html +1 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import * as monaco from 'monaco-editor/esm/vs/editor/edcore.main';
|
|
1
2
|
import 'monaco-editor/esm/vs/language/html/monaco.contribution';
|
|
3
|
+
import { r as registerConfigurations, g as getConfiguration, o as onConfigurationChanged } from '../index.js';
|
|
2
4
|
import { r as registerWorkerLoader } from '../worker.js';
|
|
3
5
|
|
|
4
6
|
const workerLoader = async () => (await import(
|
|
@@ -8,3 +10,105 @@ const workerLoader = async () => (await import(
|
|
|
8
10
|
registerWorkerLoader('html', workerLoader);
|
|
9
11
|
registerWorkerLoader('handlebars', workerLoader);
|
|
10
12
|
registerWorkerLoader('razor', workerLoader);
|
|
13
|
+
/**
|
|
14
|
+
* Start autoclosing html tags
|
|
15
|
+
* Inspired by https://github.com/microsoft/monaco-editor/issues/221
|
|
16
|
+
* and https://github.com/microsoft/vscode/blob/5943dac8ba32df1963a1760c660b3f16f5fcdc51/extensions/html-language-features/client/src/autoInsertion.ts
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
registerConfigurations([{
|
|
20
|
+
id: 'html',
|
|
21
|
+
order: 20,
|
|
22
|
+
type: 'object',
|
|
23
|
+
title: 'HTML',
|
|
24
|
+
properties: {
|
|
25
|
+
'html.autoClosingTags': {
|
|
26
|
+
type: 'boolean',
|
|
27
|
+
scope: monaco.extra.ConfigurationScope.RESOURCE,
|
|
28
|
+
default: true,
|
|
29
|
+
description: 'Enable/disable autoclosing of HTML tags.'
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}]);
|
|
33
|
+
let autoClosingTags = getConfiguration(undefined, 'html.autoClosingTags');
|
|
34
|
+
onConfigurationChanged(e => {
|
|
35
|
+
if (e.affectsConfiguration('html.autoClosingTags')) {
|
|
36
|
+
autoClosingTags = getConfiguration(undefined, 'html.autoClosingTags');
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
function autoCloseHtmlTags(editor) {
|
|
41
|
+
const disposableStore = new monaco.DisposableStore();
|
|
42
|
+
let timeout;
|
|
43
|
+
disposableStore.add({
|
|
44
|
+
dispose: () => {
|
|
45
|
+
if (timeout != null) {
|
|
46
|
+
window.clearTimeout(timeout);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
disposableStore.add(editor.onDidChangeModelContent(e => {
|
|
51
|
+
if (timeout != null) {
|
|
52
|
+
window.clearTimeout(timeout);
|
|
53
|
+
timeout = undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!autoClosingTags || e.isRedoing || e.isUndoing) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const model = editor.getModel();
|
|
61
|
+
|
|
62
|
+
if (model == null || model.getLanguageId() !== 'html') {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
timeout = window.setTimeout(() => {
|
|
67
|
+
for (const {
|
|
68
|
+
range,
|
|
69
|
+
rangeLength,
|
|
70
|
+
text
|
|
71
|
+
} of e.changes) {
|
|
72
|
+
var _untilLine$match;
|
|
73
|
+
|
|
74
|
+
if (!text.endsWith('>')) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const untilLine = model.getValueInRange({
|
|
79
|
+
startLineNumber: 1,
|
|
80
|
+
startColumn: 1,
|
|
81
|
+
endLineNumber: range.endLineNumber,
|
|
82
|
+
endColumn: range.endColumn + rangeLength + 1
|
|
83
|
+
});
|
|
84
|
+
const enclosingTag = (_untilLine$match = untilLine.match(/.*<(\w+)>$/)) === null || _untilLine$match === void 0 ? void 0 : _untilLine$match[1];
|
|
85
|
+
|
|
86
|
+
if (enclosingTag == null || enclosingTag.includes('/')) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const newRange = new monaco.Range(range.endLineNumber, range.endColumn + rangeLength + 1, range.endLineNumber, range.endColumn + rangeLength + enclosingTag.length + 1);
|
|
91
|
+
const rest = model.getValueInRange(newRange);
|
|
92
|
+
model.applyEdits([{
|
|
93
|
+
range: newRange,
|
|
94
|
+
text: "</".concat(enclosingTag, ">").concat(rest),
|
|
95
|
+
forceMoveMarkers: true
|
|
96
|
+
}]);
|
|
97
|
+
}
|
|
98
|
+
}, 100);
|
|
99
|
+
}));
|
|
100
|
+
return disposableStore;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const codeEditors = monaco.extra.StandaloneServices.get(monaco.extra.ICodeEditorService).listCodeEditors();
|
|
104
|
+
|
|
105
|
+
for (const editor of codeEditors) {
|
|
106
|
+
autoCloseHtmlTags(editor);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
monaco.editor.onDidCreateEditor(editor => {
|
|
110
|
+
autoCloseHtmlTags(editor);
|
|
111
|
+
});
|
|
112
|
+
/**
|
|
113
|
+
* End autoclosing html tags
|
|
114
|
+
*/
|