@node-projects/web-component-designer-codeview-monaco 0.1.15 → 0.1.17

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.
@@ -25,6 +25,7 @@ export declare class CodeViewMonaco extends BaseCustomWebComponentLazyAppend imp
25
25
  private _editor;
26
26
  private _instanceServiceContainer;
27
27
  private _disableSelection;
28
+ private _disableSelectionAfterUpd;
28
29
  static readonly style: CSSStyleSheet;
29
30
  static readonly template: HTMLTemplateElement;
30
31
  executeCommand(command: IUiCommand): void;
@@ -31,6 +31,7 @@ export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
31
31
  _editor;
32
32
  _instanceServiceContainer;
33
33
  _disableSelection;
34
+ _disableSelectionAfterUpd;
34
35
  static style = css `
35
36
  :host {
36
37
  display: block;
@@ -142,26 +143,46 @@ export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
142
143
  }
143
144
  });
144
145
  CodeViewMonaco.initMonacoEditor(CodeViewMonaco.monacoLib);
146
+ let selectionTimeout;
147
+ let disableCursorChange;
145
148
  let changeContentListener = this._monacoEditor.getModel().onDidChangeContent(e => {
149
+ console.log('text change');
150
+ if (selectionTimeout) {
151
+ clearTimeout(selectionTimeout);
152
+ selectionTimeout = null;
153
+ }
154
+ disableCursorChange = true;
155
+ setTimeout(() => {
156
+ disableCursorChange = false;
157
+ }, 50);
146
158
  this.onTextChanged.emit(this._monacoEditor.getValue());
147
159
  });
148
160
  this._monacoEditor.onDidChangeModel(e => {
149
161
  changeContentListener.dispose();
150
162
  changeContentListener = this._monacoEditor.getModel().onDidChangeContent(e => {
163
+ console.log('text change');
164
+ if (selectionTimeout) {
165
+ clearTimeout(selectionTimeout);
166
+ selectionTimeout = null;
167
+ }
168
+ disableCursorChange = true;
169
+ setTimeout(() => {
170
+ disableCursorChange = false;
171
+ }, 50);
151
172
  this.onTextChanged.emit(this._monacoEditor.getValue());
152
173
  });
153
174
  });
154
175
  this._monacoEditor.onDidChangeCursorPosition(e => {
155
176
  const offset = this._monacoEditor.getModel().getOffsetAt(e.position);
156
- let debounce = false;
157
- if (this._instanceServiceContainer && !debounce && !this._disableSelection) {
158
- debounce = true;
177
+ if (this._instanceServiceContainer && !this._disableSelectionAfterUpd && !disableCursorChange) {
159
178
  this._disableSelection = true;
160
- setTimeout(() => {
161
- debounce = false;
179
+ if (selectionTimeout)
180
+ clearTimeout(selectionTimeout);
181
+ selectionTimeout = setTimeout(() => {
182
+ selectionTimeout = null;
183
+ this._instanceServiceContainer.selectionService.setSelectionByTextRange(offset, offset);
184
+ this._disableSelection = false;
162
185
  }, 50);
163
- this._instanceServiceContainer.selectionService.setSelectionByTextRange(offset, offset);
164
- this._disableSelection = false;
165
186
  }
166
187
  });
167
188
  this._monacoEditor.focus();
@@ -184,21 +205,23 @@ export class CodeViewMonaco extends BaseCustomWebComponentLazyAppend {
184
205
  this._monacoEditor.layout();
185
206
  }
186
207
  update(code, instanceServiceContainer) {
208
+ console.log('update text');
187
209
  this.code = code;
188
210
  this._instanceServiceContainer = instanceServiceContainer;
189
211
  if (this._monacoEditor) {
190
- this._disableSelection = true;
212
+ this._disableSelectionAfterUpd = true;
191
213
  if (this._monacoEditor)
192
214
  this._monacoEditor.setValue(code);
193
215
  CodeViewMonaco.monacoLib.editor.setModelLanguage(this._monacoEditor.getModel(), this.language);
194
216
  CodeViewMonaco.monacoLib.editor.setTheme(this.theme);
195
- this._disableSelection = false;
217
+ this._disableSelectionAfterUpd = false;
196
218
  }
197
219
  }
198
220
  getText() {
199
221
  return this._monacoEditor.getValue();
200
222
  }
201
223
  setSelection(position) {
224
+ console.log('set selection');
202
225
  if (this._monacoEditor && !this._disableSelection) {
203
226
  let model = this._monacoEditor.getModel();
204
227
  let point1 = model.getPositionAt(position.start);
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.15",
4
+ "version": "0.1.17",
5
5
  "type": "module",
6
6
  "main": "./dist/widgets/codeView/code-view-monaco.js",
7
7
  "author": "jochen.kuehner@gmx.de",