@node-projects/web-component-designer-codeview-monaco 0.2.0 → 0.2.1
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.
|
@@ -10,6 +10,8 @@ export declare class CodeViewMonaco extends BaseCustomWebComponentLazyAppend imp
|
|
|
10
10
|
Range: typeof monacoType.Range;
|
|
11
11
|
}>;
|
|
12
12
|
private _disableSelectionAfterSel;
|
|
13
|
+
private _setSelectionTimeout;
|
|
14
|
+
private _pendingSelectionKey;
|
|
13
15
|
dispose(): void;
|
|
14
16
|
canvasElement: HTMLElement;
|
|
15
17
|
elementsToPackages: Map<string, string>;
|
|
@@ -46,4 +48,5 @@ export declare class CodeViewMonaco extends BaseCustomWebComponentLazyAppend imp
|
|
|
46
48
|
update(code: string, instanceServiceContainer?: InstanceServiceContainer): void;
|
|
47
49
|
getText(): string;
|
|
48
50
|
setSelection(position: IStringPosition): void;
|
|
51
|
+
private clearPendingSetSelection;
|
|
49
52
|
}
|
|
@@ -14,6 +14,8 @@ export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
|
|
|
14
14
|
return monaco;
|
|
15
15
|
}
|
|
16
16
|
_disableSelectionAfterSel;
|
|
17
|
+
_setSelectionTimeout;
|
|
18
|
+
_pendingSelectionKey;
|
|
17
19
|
dispose() {
|
|
18
20
|
this._monacoEditor?.dispose();
|
|
19
21
|
}
|
|
@@ -211,6 +213,7 @@ export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
|
|
|
211
213
|
this.#code = code;
|
|
212
214
|
this._instanceServiceContainer = instanceServiceContainer;
|
|
213
215
|
if (this._monacoEditor) {
|
|
216
|
+
this.clearPendingSetSelection();
|
|
214
217
|
this._disableSelectionAfterUpd = true;
|
|
215
218
|
if (this._monacoEditor)
|
|
216
219
|
this._monacoEditor.setValue(code);
|
|
@@ -226,11 +229,17 @@ export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
|
|
|
226
229
|
}
|
|
227
230
|
setSelection(position) {
|
|
228
231
|
if (this._monacoEditor && !this._disableSelection && !this._disableSelectionAfterSel && position) {
|
|
232
|
+
const selectionKey = `${position.start}:${position.length}`;
|
|
233
|
+
if (this._pendingSelectionKey === selectionKey)
|
|
234
|
+
return;
|
|
229
235
|
this._disableSelectionAfterSel = true;
|
|
236
|
+
this._pendingSelectionKey = selectionKey;
|
|
230
237
|
let model = this._monacoEditor.getModel();
|
|
231
238
|
let point1 = model.getPositionAt(position.start);
|
|
232
239
|
let point2 = model.getPositionAt(position.start + position.length);
|
|
233
|
-
setTimeout(() => {
|
|
240
|
+
this._setSelectionTimeout = setTimeout(async () => {
|
|
241
|
+
this._setSelectionTimeout = null;
|
|
242
|
+
this._pendingSelectionKey = null;
|
|
234
243
|
this._monacoEditor.setSelection({ startLineNumber: point1.lineNumber, startColumn: point1.column, endLineNumber: point2.lineNumber, endColumn: point2.column });
|
|
235
244
|
CodeViewMonaco.getMonacoLib().then(monaco => {
|
|
236
245
|
this._monacoEditor.revealRangeInCenterIfOutsideViewport(new monaco.Range(point1.lineNumber, point1.column, point2.lineNumber, point2.column), 1);
|
|
@@ -241,5 +250,13 @@ export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
|
|
|
241
250
|
}, 50);
|
|
242
251
|
}
|
|
243
252
|
}
|
|
253
|
+
clearPendingSetSelection() {
|
|
254
|
+
if (this._setSelectionTimeout) {
|
|
255
|
+
clearTimeout(this._setSelectionTimeout);
|
|
256
|
+
this._setSelectionTimeout = null;
|
|
257
|
+
}
|
|
258
|
+
this._pendingSelectionKey = null;
|
|
259
|
+
this._disableSelectionAfterSel = false;
|
|
260
|
+
}
|
|
244
261
|
}
|
|
245
262
|
customElements.define('node-projects-code-view-monaco', CodeViewMonaco);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"description": "web-component-designer addon: Code Editor using Monaco",
|
|
3
3
|
"name": "@node-projects/web-component-designer-codeview-monaco",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/widgets/codeView/code-view-monaco.js",
|
|
7
7
|
"author": "jochen.kuehner@gmx.de",
|