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

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,14 @@ 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
+ if (this._instanceServiceContainer) {
157
+ this._disableSelection = true;
158
+ this._instanceServiceContainer.selectionService.setSelectionByTextRange(offset, offset);
159
+ this._disableSelection = false;
160
+ }
161
+ });
152
162
  this._monacoEditor.focus();
153
163
  resizeObserver.disconnect();
154
164
  }
@@ -168,8 +178,9 @@ export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
168
178
  if (this._monacoEditor)
169
179
  this._monacoEditor.layout();
170
180
  }
171
- update(code) {
181
+ update(code, instanceServiceContainer) {
172
182
  this.code = code;
183
+ this._instanceServiceContainer = instanceServiceContainer;
173
184
  if (this._monacoEditor) {
174
185
  if (this._monacoEditor)
175
186
  this._monacoEditor.setValue(code);
@@ -181,7 +192,7 @@ export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
181
192
  return this._monacoEditor.getValue();
182
193
  }
183
194
  setSelection(position) {
184
- if (this._monacoEditor) {
195
+ if (this._monacoEditor && !this._disableSelection) {
185
196
  let model = this._monacoEditor.getModel();
186
197
  let point1 = model.getPositionAt(position.start);
187
198
  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.12",
5
5
  "type": "module",
6
6
  "main": "./dist/widgets/codeView/code-view-monaco.js",
7
7
  "author": "jochen.kuehner@gmx.de",