@node-projects/web-component-designer-codeview-monaco 0.1.11 → 0.1.13

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.
@@ -1,5 +1,5 @@
1
1
  import { BaseCustomWebComponentLazyAppend, TypedEvent } from '@node-projects/base-custom-webcomponent';
2
- import { IActivateable, ICodeView, IStringPosition, IUiCommand, IUiCommandHandler } from '@node-projects/web-component-designer';
2
+ import { IActivateable, ICodeView, InstanceServiceContainer, IStringPosition, IUiCommand, IUiCommandHandler } from '@node-projects/web-component-designer';
3
3
  import type * as monacoType from 'monaco-editor';
4
4
  export declare class CodeViewMonaco extends BaseCustomWebComponentLazyAppend implements ICodeView, IActivateable, IUiCommandHandler {
5
5
  private static _initalized;
@@ -23,6 +23,8 @@ export declare class CodeViewMonaco extends BaseCustomWebComponentLazyAppend imp
23
23
  };
24
24
  private _monacoEditor;
25
25
  private _editor;
26
+ private _instanceServiceContainer;
27
+ private _disableSelection;
26
28
  static readonly style: CSSStyleSheet;
27
29
  static readonly template: HTMLTemplateElement;
28
30
  executeCommand(command: IUiCommand): void;
@@ -35,7 +37,7 @@ export declare class CodeViewMonaco extends BaseCustomWebComponentLazyAppend imp
35
37
  ready(): Promise<void>;
36
38
  focusEditor(): void;
37
39
  activated(): void;
38
- update(code: any): void;
40
+ update(code: string, instanceServiceContainer?: InstanceServiceContainer): void;
39
41
  getText(): string;
40
42
  setSelection(position: IStringPosition): void;
41
43
  }
@@ -29,6 +29,8 @@ export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
29
29
  };
30
30
  _monacoEditor;
31
31
  _editor;
32
+ _instanceServiceContainer;
33
+ _disableSelection;
32
34
  static style = css `
33
35
  :host {
34
36
  display: block;
@@ -149,6 +151,19 @@ export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
149
151
  this.onTextChanged.emit(this._monacoEditor.getValue());
150
152
  });
151
153
  });
154
+ this._monacoEditor.onDidChangeCursorPosition(e => {
155
+ const offset = this._monacoEditor.getModel().getOffsetAt(e.position);
156
+ let debounce = false;
157
+ if (this._instanceServiceContainer && debounce) {
158
+ debounce = true;
159
+ this._disableSelection = true;
160
+ setTimeout(() => {
161
+ debounce = false;
162
+ }, 50);
163
+ this._instanceServiceContainer.selectionService.setSelectionByTextRange(offset, offset);
164
+ this._disableSelection = false;
165
+ }
166
+ });
152
167
  this._monacoEditor.focus();
153
168
  resizeObserver.disconnect();
154
169
  }
@@ -168,8 +183,9 @@ export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
168
183
  if (this._monacoEditor)
169
184
  this._monacoEditor.layout();
170
185
  }
171
- update(code) {
186
+ update(code, instanceServiceContainer) {
172
187
  this.code = code;
188
+ this._instanceServiceContainer = instanceServiceContainer;
173
189
  if (this._monacoEditor) {
174
190
  if (this._monacoEditor)
175
191
  this._monacoEditor.setValue(code);
@@ -181,7 +197,7 @@ export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
181
197
  return this._monacoEditor.getValue();
182
198
  }
183
199
  setSelection(position) {
184
- if (this._monacoEditor) {
200
+ if (this._monacoEditor && !this._disableSelection) {
185
201
  let model = this._monacoEditor.getModel();
186
202
  let point1 = model.getPositionAt(position.start);
187
203
  let point2 = model.getPositionAt(position.start + position.length);
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.1.11",
4
+ "version": "0.1.13",
5
5
  "type": "module",
6
6
  "main": "./dist/widgets/codeView/code-view-monaco.js",
7
7
  "author": "jochen.kuehner@gmx.de",