@lvce-editor/editor-worker 10.0.0 → 10.1.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.
@@ -1066,6 +1066,39 @@ const createMockRpc = ({
1066
1066
  return mockRpc;
1067
1067
  };
1068
1068
 
1069
+ const Backspace = 1;
1070
+ const Tab$1 = 2;
1071
+ const Enter = 3;
1072
+ const Escape = 8;
1073
+ const Space$1 = 9;
1074
+ const End = 255;
1075
+ const Home = 12;
1076
+ const LeftArrow = 13;
1077
+ const UpArrow = 14;
1078
+ const RightArrow = 15;
1079
+ const DownArrow = 16;
1080
+ const Delete = 18;
1081
+ const KeyA = 29;
1082
+ const KeyC = 31;
1083
+ const KeyD = 32;
1084
+ const KeyF = 34;
1085
+ const KeyH = 36;
1086
+ const KeyJ = 38;
1087
+ const KeyK = 39;
1088
+ const KeyL = 40;
1089
+ const KeyO = 43;
1090
+ const KeyV = 50;
1091
+ const KeyX = 52;
1092
+ const KeyZ = 54;
1093
+ const F2 = 58;
1094
+ const F3 = 59;
1095
+ const F4 = 60;
1096
+ const F12 = 68;
1097
+ const Period = 87;
1098
+ const Slash$1 = 88;
1099
+ const BracketLeft = 90;
1100
+ const BracketRight = 92;
1101
+
1069
1102
  const CodeGenerator = 1;
1070
1103
  const ColorPicker$1 = 2;
1071
1104
  const Completion = 3;
@@ -1075,6 +1108,10 @@ const Hover = 6;
1075
1108
  const Rename$1 = 7;
1076
1109
  const SourceAction$1 = 8;
1077
1110
 
1111
+ const CtrlCmd = 1 << 11 >>> 0;
1112
+ const Shift = 1 << 10 >>> 0;
1113
+ const Alt$1 = 1 << 9 >>> 0;
1114
+
1078
1115
  const DebugWorker = 55;
1079
1116
  const EditorWorker = 99;
1080
1117
  const ExtensionHostWorker = 44;
@@ -2194,18 +2231,18 @@ const loadTokenizers = async languageIds => {
2194
2231
 
2195
2232
  const EmptyString = '';
2196
2233
  const NewLine = '\n';
2197
- const Space$1 = ' ';
2198
- const Tab$1 = '\t';
2234
+ const Space = ' ';
2235
+ const Tab = '\t';
2199
2236
  const DoubleQuote$1 = '"';
2200
2237
 
2201
2238
  const normalizeText = (text, normalize, tabSize) => {
2202
2239
  if (normalize) {
2203
- return text.replaceAll(Tab$1, Space$1.repeat(tabSize));
2240
+ return text.replaceAll(Tab, Space.repeat(tabSize));
2204
2241
  }
2205
2242
  return text;
2206
2243
  };
2207
2244
  const shouldNormalizeText = text => {
2208
- return text.includes(Tab$1);
2245
+ return text.includes(Tab);
2209
2246
  };
2210
2247
 
2211
2248
  // based on https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/common/arrays.ts#L625 (License MIT)
@@ -2694,7 +2731,7 @@ const getSelectionPairs = (selections, i) => {
2694
2731
  const getTabCount = string => {
2695
2732
  let count = 0;
2696
2733
  for (const element of string) {
2697
- if (element === Tab$1) {
2734
+ if (element === Tab) {
2698
2735
  count++;
2699
2736
  }
2700
2737
  }
@@ -3850,7 +3887,7 @@ const guessOffset = (eventX, averageCharWidth) => {
3850
3887
  const normalizeGuess = (line, guess, tabSize) => {
3851
3888
  let normalizedGuess = guess;
3852
3889
  for (let i = 0; i < guess; i++) {
3853
- if (line[i] === Tab$1) {
3890
+ if (line[i] === Tab) {
3854
3891
  normalizedGuess -= tabSize - 1;
3855
3892
  }
3856
3893
  }
@@ -4519,7 +4556,7 @@ const characterRight = (line, columnIndex) => {
4519
4556
  return next.segment.length;
4520
4557
  };
4521
4558
  const isWhitespace = char => {
4522
- return char === Space$1 || char === Tab$1;
4559
+ return char === Space || char === Tab;
4523
4560
  };
4524
4561
  const lineCharacterStart = (line, columnIndex) => {
4525
4562
  if (line.length === 0) {
@@ -5331,55 +5368,6 @@ const goToTypeDefinition = async (editor, explicit = true) => {
5331
5368
  });
5332
5369
  };
5333
5370
 
5334
- const Editor = 3;
5335
-
5336
- const handleContextMenu = async (editor, button, x, y) => {
5337
- await invoke$9(/* ContextMenu.show */'ContextMenu.show', /* x */x, /* y */y, /* id */Editor);
5338
- return editor;
5339
- };
5340
-
5341
- // @ts-ignore
5342
-
5343
- // match all words, including umlauts, see https://stackoverflow.com/questions/5436824/matching-accented-characters-with-javascript-regexes/#answer-11550799
5344
- const RE_WORD_START = /^[a-z\u00C0-\u017F\d]+/i;
5345
- const RE_WORD_END = /[a-z\u00C0-\u017F\d]+$/i;
5346
-
5347
- // @ts-ignore
5348
- const getNewSelections$7 = (line, rowIndex, columnIndex) => {
5349
- const before = line.slice(0, columnIndex);
5350
- const after = line.slice(columnIndex);
5351
- const beforeMatch = before.match(RE_WORD_END);
5352
- const afterMatch = after.match(RE_WORD_START);
5353
- const columnStart = columnIndex - (beforeMatch ? beforeMatch[0].length : 0);
5354
- const columnEnd = columnIndex + (afterMatch ? afterMatch[0].length : 0);
5355
- const newSelections = new Uint32Array([rowIndex, columnStart, rowIndex, columnEnd]);
5356
- return newSelections;
5357
- };
5358
-
5359
- // @ts-ignore
5360
- const selectWord = (editor, rowIndex, columnIndex) => {
5361
- const line = getLine(editor, rowIndex);
5362
- const newSelections = getNewSelections$7(line, rowIndex, columnIndex);
5363
- return scheduleSelections(editor, newSelections);
5364
- };
5365
-
5366
- const handleDoubleClick = (editor, modifier, x, y) => {
5367
- const position = at(editor, x, y);
5368
- return selectWord(editor, position.rowIndex, position.columnIndex);
5369
- };
5370
-
5371
- const WhenExpressionEditorText = 12;
5372
- const handleFocus$1 = editor => {
5373
- // TODO make change events functional,
5374
- // when rendering, send focus changes to renderer worker
5375
- invoke$9('Focus.setFocus', WhenExpressionEditorText);
5376
- return editor;
5377
- };
5378
-
5379
- const Single = 1;
5380
- const Double = 2;
5381
- const Triple = 3;
5382
-
5383
5371
  const state$3 = {
5384
5372
  position: {
5385
5373
  rowIndex: 0,
@@ -5439,7 +5427,7 @@ const handleSingleClickWithCtrl = async (editor, position) => {
5439
5427
  };
5440
5428
 
5441
5429
  const Ctrl = 1;
5442
- const Alt$1 = 2;
5430
+ const Alt = 2;
5443
5431
 
5444
5432
  const handleSingleClickDefault = (editor, position) => {
5445
5433
  setPosition$1(position);
@@ -5451,7 +5439,7 @@ const handleSingleClickDefault = (editor, position) => {
5451
5439
  };
5452
5440
  const getClickHandler = modifier => {
5453
5441
  switch (modifier) {
5454
- case Alt$1:
5442
+ case Alt:
5455
5443
  return handleSingleClickWithAlt;
5456
5444
  case Ctrl:
5457
5445
  return handleSingleClickWithCtrl;
@@ -5460,26 +5448,75 @@ const getClickHandler = modifier => {
5460
5448
  }
5461
5449
  };
5462
5450
 
5451
+ const handleClickAtPosition = async (editor, modifier, rowIndex, columnIndex) => {
5452
+ object(editor);
5453
+ number(modifier);
5454
+ number(rowIndex);
5455
+ number(columnIndex);
5456
+ const fn = getClickHandler(modifier);
5457
+ const newEditor = await fn(editor, {
5458
+ rowIndex,
5459
+ columnIndex
5460
+ });
5461
+ return newEditor;
5462
+ };
5463
+
5464
+ const Editor = 3;
5465
+
5466
+ const handleContextMenu = async (editor, button, x, y) => {
5467
+ await invoke$9(/* ContextMenu.show */'ContextMenu.show', /* x */x, /* y */y, /* id */Editor);
5468
+ return editor;
5469
+ };
5470
+
5471
+ // @ts-ignore
5472
+
5473
+ // match all words, including umlauts, see https://stackoverflow.com/questions/5436824/matching-accented-characters-with-javascript-regexes/#answer-11550799
5474
+ const RE_WORD_START = /^[a-z\u00C0-\u017F\d]+/i;
5475
+ const RE_WORD_END = /[a-z\u00C0-\u017F\d]+$/i;
5476
+
5477
+ // @ts-ignore
5478
+ const getNewSelections$7 = (line, rowIndex, columnIndex) => {
5479
+ const before = line.slice(0, columnIndex);
5480
+ const after = line.slice(columnIndex);
5481
+ const beforeMatch = before.match(RE_WORD_END);
5482
+ const afterMatch = after.match(RE_WORD_START);
5483
+ const columnStart = columnIndex - (beforeMatch ? beforeMatch[0].length : 0);
5484
+ const columnEnd = columnIndex + (afterMatch ? afterMatch[0].length : 0);
5485
+ const newSelections = new Uint32Array([rowIndex, columnStart, rowIndex, columnEnd]);
5486
+ return newSelections;
5487
+ };
5488
+
5489
+ // @ts-ignore
5490
+ const selectWord = (editor, rowIndex, columnIndex) => {
5491
+ const line = getLine(editor, rowIndex);
5492
+ const newSelections = getNewSelections$7(line, rowIndex, columnIndex);
5493
+ return scheduleSelections(editor, newSelections);
5494
+ };
5495
+
5496
+ const handleDoubleClick = (editor, modifier, x, y) => {
5497
+ const position = at(editor, x, y);
5498
+ return selectWord(editor, position.rowIndex, position.columnIndex);
5499
+ };
5500
+
5501
+ const WhenExpressionEditorText = 12;
5502
+ const handleFocus$1 = editor => {
5503
+ // TODO make change events functional,
5504
+ // when rendering, send focus changes to renderer worker
5505
+ invoke$9('Focus.setFocus', WhenExpressionEditorText);
5506
+ return editor;
5507
+ };
5508
+
5509
+ const Single = 1;
5510
+ const Double = 2;
5511
+ const Triple = 3;
5512
+
5463
5513
  const handleSingleClick = async (editor, modifier, x, y) => {
5464
5514
  object(editor);
5465
5515
  number(modifier);
5466
5516
  number(x);
5467
5517
  number(y);
5468
5518
  const position = at(editor, x, y);
5469
- const fn = getClickHandler(modifier);
5470
- const newEditor = await fn(editor, position);
5471
- // switch (newEditor.completionState) {
5472
- // case EditorCompletionState.None:
5473
- // case EditorCompletionState.Visible:
5474
- // case EditorCompletionState.Loading:
5475
- // return {
5476
- // newState: newEditor,
5477
- // commands: [],
5478
- // }
5479
- // default:
5480
- // break
5481
- // }
5482
- return newEditor;
5519
+ return handleClickAtPosition(editor, modifier, position.rowIndex, position.columnIndex);
5483
5520
  };
5484
5521
 
5485
5522
  // @ts-ignore
@@ -7343,8 +7380,12 @@ const setLanguageId = async (editor, languageId, tokenizePath) => {
7343
7380
  textInfos,
7344
7381
  differences
7345
7382
  } = await getVisible$1(editor, syncIncremental);
7383
+ const latest2 = getEditor(editor.uid);
7384
+ if (!latest2) {
7385
+ return editor;
7386
+ }
7346
7387
  const newEditor4 = {
7347
- ...latest,
7388
+ ...latest2,
7348
7389
  focused: true,
7349
7390
  textInfos,
7350
7391
  differences
@@ -8058,7 +8099,7 @@ const type = (editor, text) => {
8058
8099
  return scheduleDocumentAndCursorsSelections(editor, changes);
8059
8100
  };
8060
8101
 
8061
- const Slash$1 = '/';
8102
+ const Slash = '/';
8062
8103
 
8063
8104
  const CurlyOpen = '{';
8064
8105
  const CurlyClose = '}';
@@ -8173,7 +8214,7 @@ const typeWithAutoClosing = async (editor, text) => {
8173
8214
  }
8174
8215
  break;
8175
8216
  // case AutoClosing.ClosingAngleBracket: // TODO support auto closing when typing closing angle bracket of start tag
8176
- case Slash$1:
8217
+ case Slash:
8177
8218
  if (isAutoClosingTagsEnabled) {
8178
8219
  return typeWithAutoClosingTag(editor, text);
8179
8220
  }
@@ -9334,43 +9375,6 @@ const ensure = async (fontName, fontUrl) => {
9334
9375
  setLoaded(fontName);
9335
9376
  };
9336
9377
 
9337
- const Backspace = 1;
9338
- const Tab = 2;
9339
- const Enter = 3;
9340
- const Escape = 8;
9341
- const Space = 9;
9342
- const End = 255;
9343
- const Home = 12;
9344
- const LeftArrow = 13;
9345
- const UpArrow = 14;
9346
- const RightArrow = 15;
9347
- const DownArrow = 16;
9348
- const Delete = 18;
9349
- const KeyA = 29;
9350
- const KeyC = 31;
9351
- const KeyD = 32;
9352
- const KeyF = 34;
9353
- const KeyH = 36;
9354
- const KeyJ = 38;
9355
- const KeyK = 39;
9356
- const KeyL = 40;
9357
- const KeyO = 43;
9358
- const KeyV = 50;
9359
- const KeyX = 52;
9360
- const KeyZ = 54;
9361
- const F2 = 58;
9362
- const F3 = 59;
9363
- const F4 = 60;
9364
- const F12 = 68;
9365
- const Period = 87;
9366
- const Slash = 88;
9367
- const BracketLeft = 90;
9368
- const BracketRight = 92;
9369
-
9370
- const CtrlCmd = 1 << 11 >>> 0;
9371
- const Shift = 1 << 10 >>> 0;
9372
- const Alt = 1 << 9 >>> 0;
9373
-
9374
9378
  const getKeyBindings = () => {
9375
9379
  return [{
9376
9380
  key: Escape,
@@ -9413,59 +9417,59 @@ const getKeyBindings = () => {
9413
9417
  command: 'FindWidget.focusNext',
9414
9418
  when: FocusFindWidget
9415
9419
  }, {
9416
- key: Shift | Tab,
9420
+ key: Shift | Tab$1,
9417
9421
  command: 'FindWidget.focusToggleReplace',
9418
9422
  when: FocusFindWidget
9419
9423
  }, {
9420
- key: Tab,
9424
+ key: Tab$1,
9421
9425
  command: 'FindWidget.focusReplace',
9422
9426
  when: FocusFindWidget
9423
9427
  }, {
9424
- key: Tab,
9428
+ key: Tab$1,
9425
9429
  command: 'FindWidget.focusPreviousMatchButton',
9426
9430
  when: FocusFindWidgetReplace
9427
9431
  }, {
9428
- key: Alt | CtrlCmd | Enter,
9432
+ key: Alt$1 | CtrlCmd | Enter,
9429
9433
  command: 'FindWidget.replaceAll',
9430
9434
  when: FocusFindWidgetReplace
9431
9435
  }, {
9432
- key: Tab,
9436
+ key: Tab$1,
9433
9437
  command: 'FindWidget.focusNextMatchButton',
9434
9438
  when: FocusFindWidgetPreviousMatchButton
9435
9439
  }, {
9436
- key: Shift | Tab,
9440
+ key: Shift | Tab$1,
9437
9441
  command: 'FindWidget.focusReplace',
9438
9442
  when: FocusFindWidgetPreviousMatchButton
9439
9443
  }, {
9440
- key: Shift | Tab,
9444
+ key: Shift | Tab$1,
9441
9445
  command: 'FindWidget.focusPreviousMatchButton',
9442
9446
  when: FocusFindWidgetNextMatchButton
9443
9447
  }, {
9444
- key: Tab,
9448
+ key: Tab$1,
9445
9449
  command: 'FindWidget.focusCloseButton',
9446
9450
  when: FocusFindWidgetNextMatchButton
9447
9451
  }, {
9448
- key: Shift | Tab,
9452
+ key: Shift | Tab$1,
9449
9453
  command: 'FindWidget.focusNextMatchButton',
9450
9454
  when: FocusFindWidgetCloseButton
9451
9455
  }, {
9452
- key: Tab,
9456
+ key: Tab$1,
9453
9457
  command: 'FindWidget.focusReplaceButton',
9454
9458
  when: FocusFindWidgetCloseButton
9455
9459
  }, {
9456
- key: Shift | Tab,
9460
+ key: Shift | Tab$1,
9457
9461
  command: 'FindWidget.focusFind',
9458
9462
  when: FocusFindWidgetReplace
9459
9463
  }, {
9460
- key: Tab,
9464
+ key: Tab$1,
9461
9465
  command: 'FindWidget.focusReplaceAllButton',
9462
9466
  when: FocusFindWidgetReplaceButton
9463
9467
  }, {
9464
- key: Shift | Tab,
9468
+ key: Shift | Tab$1,
9465
9469
  command: 'FindWidget.focusCloseButton',
9466
9470
  when: FocusFindWidgetReplaceButton
9467
9471
  }, {
9468
- key: Shift | Tab,
9472
+ key: Shift | Tab$1,
9469
9473
  command: 'FindWidget.focusReplaceButton',
9470
9474
  when: FocusFindWidgetReplaceAllButton
9471
9475
  }, {
@@ -9493,7 +9497,7 @@ const getKeyBindings = () => {
9493
9497
  command: 'EditorCompletion.focusFirst',
9494
9498
  when: FocusEditorCompletions
9495
9499
  }, {
9496
- key: CtrlCmd | Space,
9500
+ key: CtrlCmd | Space$1,
9497
9501
  command: 'EditorCompletion.toggleDetails',
9498
9502
  when: FocusEditorCompletions
9499
9503
  }, {
@@ -9505,11 +9509,11 @@ const getKeyBindings = () => {
9505
9509
  command: 'Editor.cursorWordLeft',
9506
9510
  when: FocusEditorText
9507
9511
  }, {
9508
- key: Alt | Backspace,
9512
+ key: Alt$1 | Backspace,
9509
9513
  command: 'Editor.deleteWordPartLeft',
9510
9514
  when: FocusEditorText
9511
9515
  }, {
9512
- key: Alt | Delete,
9516
+ key: Alt$1 | Delete,
9513
9517
  command: 'Editor.deleteWordPartRight',
9514
9518
  when: FocusEditorText
9515
9519
  }, {
@@ -9533,11 +9537,11 @@ const getKeyBindings = () => {
9533
9537
  command: 'Editor.showSourceActions3',
9534
9538
  when: FocusEditorText
9535
9539
  }, {
9536
- key: Tab,
9540
+ key: Tab$1,
9537
9541
  command: 'Editor.handleTab',
9538
9542
  when: FocusEditorText
9539
9543
  }, {
9540
- key: Shift | Tab,
9544
+ key: Shift | Tab$1,
9541
9545
  command: 'Editor.unindent',
9542
9546
  when: FocusEditorText
9543
9547
  }, {
@@ -9645,7 +9649,7 @@ const getKeyBindings = () => {
9645
9649
  command: 'Editor.moveLineUp',
9646
9650
  when: FocusEditorText
9647
9651
  }, {
9648
- key: CtrlCmd | Space,
9652
+ key: CtrlCmd | Space$1,
9649
9653
  command: 'Editor.openCompletion',
9650
9654
  when: FocusEditorText
9651
9655
  }, {
@@ -9669,7 +9673,7 @@ const getKeyBindings = () => {
9669
9673
  command: 'Editor.cursorEnd',
9670
9674
  when: FocusEditorText
9671
9675
  }, {
9672
- key: CtrlCmd | Slash,
9676
+ key: CtrlCmd | Slash$1,
9673
9677
  command: 'Editor.toggleComment',
9674
9678
  when: FocusEditorText
9675
9679
  }, {
@@ -9693,35 +9697,35 @@ const getKeyBindings = () => {
9693
9697
  command: 'Editor.paste',
9694
9698
  when: FocusEditorText
9695
9699
  }, {
9696
- key: Alt | LeftArrow,
9700
+ key: Alt$1 | LeftArrow,
9697
9701
  command: 'Editor.cursorWordPartLeft',
9698
9702
  when: FocusEditorText
9699
9703
  }, {
9700
- key: Alt | RightArrow,
9704
+ key: Alt$1 | RightArrow,
9701
9705
  command: 'Editor.cursorWordPartRight',
9702
9706
  when: FocusEditorText
9703
9707
  }, {
9704
- key: Alt | F3,
9708
+ key: Alt$1 | F3,
9705
9709
  command: 'Editor.selectAllOccurrences',
9706
9710
  when: FocusEditorText
9707
9711
  }, {
9708
- key: Alt | Shift | UpArrow,
9712
+ key: Alt$1 | Shift | UpArrow,
9709
9713
  command: 'Editor.addCursorAbove',
9710
9714
  when: FocusEditorText
9711
9715
  }, {
9712
- key: Alt | Shift | DownArrow,
9716
+ key: Alt$1 | Shift | DownArrow,
9713
9717
  command: 'Editor.addCursorBelow',
9714
9718
  when: FocusEditorText
9715
9719
  }, {
9716
- key: Alt | Shift | F12,
9720
+ key: Alt$1 | Shift | F12,
9717
9721
  command: 'Editor.findAllReferences',
9718
9722
  when: FocusEditorText
9719
9723
  }, {
9720
- key: Alt | Shift | KeyO,
9724
+ key: Alt$1 | Shift | KeyO,
9721
9725
  command: 'Editor.organizeImports',
9722
9726
  when: FocusEditorText
9723
9727
  }, {
9724
- key: CtrlCmd | Shift | Space,
9728
+ key: CtrlCmd | Shift | Space$1,
9725
9729
  command: 'Editor.selectionGrow',
9726
9730
  when: FocusEditor
9727
9731
  }];
@@ -10537,6 +10541,9 @@ const effects = [editorDiagnosticEffect];
10537
10541
  const wrapCommand = fn => async (editorUid, ...args) => {
10538
10542
  const oldInstance = get$4(editorUid);
10539
10543
  const newEditor = await fn(oldInstance.newState, ...args);
10544
+ if (oldInstance.newState === newEditor) {
10545
+ return newEditor;
10546
+ }
10540
10547
  for (const effect of effects) {
10541
10548
  if (effect.isActive(oldInstance.newState, newEditor)) {
10542
10549
  effect.apply(newEditor);
@@ -10586,6 +10593,7 @@ const commandMap = {
10586
10593
  'Editor.compositionEnd': compositionEnd,
10587
10594
  'Editor.compositionStart': compositionStart,
10588
10595
  'Editor.compositionUpdate': compositionUpdate,
10596
+ 'Editor.handleClickAtPosition': handleClickAtPosition,
10589
10597
  'Editor.applyDocumentEdits': applyDocumentEdits,
10590
10598
  'Editor.contextMenu': handleContextMenu,
10591
10599
  'Editor.copy': copy,
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "10.0.0",
3
+ "version": "10.1.0",
4
4
  "license": "MIT",
5
5
  "author": "Lvce Editor",
6
6
  "type": "module",
7
7
  "main": "dist/editorWorkerMain.js",
8
8
  "dependencies": {
9
- "@lvce-editor/constants": "^1.19.0"
9
+ "@lvce-editor/constants": "^1.23.0"
10
10
  }
11
11
  }