@lvce-editor/editor-worker 4.13.0 → 5.0.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.
@@ -531,11 +531,8 @@ const measureTextWidth = (text, fontWeight, fontSize, fontFamily, letterSpacing,
531
531
  const letterSpacingString = getLetterSpacingString(letterSpacing);
532
532
  const fontString = getFontString(fontWeight, fontSize, fontFamily);
533
533
  const ctx = getContext();
534
- // @ts-ignore
535
534
  ctx.letterSpacing = letterSpacingString;
536
- // @ts-ignore
537
535
  ctx.font = fontString;
538
- // @ts-ignore
539
536
  const metrics = ctx.measureText(text);
540
537
  const width = metrics.width;
541
538
  return width;
@@ -1415,7 +1412,7 @@ const preparePrettyError = error => {
1415
1412
  const logError$1 = error => {
1416
1413
  // handled in renderer worker
1417
1414
  };
1418
- const handleMessage = event => {
1415
+ const handleMessage = async event => {
1419
1416
  return handleJsonRpcMessage(event.target, event.data, execute$1, resolve, preparePrettyError, logError$1, requiresSocket);
1420
1417
  };
1421
1418
 
@@ -1468,7 +1465,7 @@ const set$4 = ipc => {
1468
1465
  state$8.ipc = ipc;
1469
1466
  };
1470
1467
 
1471
- const invoke$4 = (method, ...params) => {
1468
+ const invoke$4 = async (method, ...params) => {
1472
1469
  const ipc = get$4();
1473
1470
  return invoke$5(ipc, method, ...params);
1474
1471
  };
@@ -1711,7 +1708,7 @@ const createRpc = method => {
1711
1708
  handleIpc(ipc);
1712
1709
  _ipc = ipc;
1713
1710
  };
1714
- const invoke = (method, ...params) => {
1711
+ const invoke = async (method, ...params) => {
1715
1712
  return invoke$5(_ipc, method, ...params);
1716
1713
  };
1717
1714
  return {
@@ -2205,7 +2202,7 @@ const editorShowMessage = async (editor, rowIndex, columnIndex, message, isError
2205
2202
  * @returns
2206
2203
  */
2207
2204
  // @ts-ignore
2208
- const showErrorMessage = (editor, rowIndex, columnIndex, message) => {
2205
+ const showErrorMessage = async (editor, rowIndex, columnIndex, message) => {
2209
2206
  return editorShowMessage(editor, rowIndex, columnIndex, message, /* isError */true);
2210
2207
  };
2211
2208
 
@@ -2268,8 +2265,7 @@ const cancelSelection = editor => {
2268
2265
  };
2269
2266
 
2270
2267
  const getIndex = (widgets, id) => {
2271
- for (let i = 0; i < widgets.length; i++) {
2272
- const widget = widgets[i];
2268
+ for (const [i, widget] of widgets.entries()) {
2273
2269
  if (widget.id === id) {
2274
2270
  return i;
2275
2271
  }
@@ -2324,7 +2320,8 @@ const closeFind = editor => {
2324
2320
  const newWidgets = removeEditorWidget(widgets, Find);
2325
2321
  return {
2326
2322
  ...editor,
2327
- widgets: newWidgets
2323
+ widgets: newWidgets,
2324
+ focused: true
2328
2325
  };
2329
2326
  };
2330
2327
 
@@ -2405,12 +2402,8 @@ const addWidgetToEditor = async (widgetId, focusKey, editor, factory, newStateGe
2405
2402
  };
2406
2403
  const newWidgets = [...widgets, latestWidget];
2407
2404
  // TODO avoid side effect, apply focus shift during render
2408
- if (fullFocus) {
2409
- await setFocus(focusKey);
2410
- } else {
2411
- await setAdditionalFocus(focusKey);
2412
- }
2413
- const newFocus = fullFocus ? false : true;
2405
+ await (fullFocus ? setFocus(focusKey) : setAdditionalFocus(focusKey));
2406
+ const newFocus = !fullFocus;
2414
2407
  const newEditor = {
2415
2408
  ...editor,
2416
2409
  widgets: newWidgets,
@@ -3021,7 +3014,7 @@ const cutSelectedText = async editor => {
3021
3014
  return scheduleDocumentAndCursorsSelections(editor, changes, selectionChanges);
3022
3015
  };
3023
3016
 
3024
- const cut = editor => {
3017
+ const cut = async editor => {
3025
3018
  const {
3026
3019
  selections
3027
3020
  } = editor;
@@ -3487,13 +3480,9 @@ const getErrorMessage$3 = error => {
3487
3480
 
3488
3481
  // @ts-ignore
3489
3482
  const isNoProviderFoundError$1 = error => {
3490
- return error &&
3491
- // @ts-ignore
3492
- error.message &&
3493
- // @ts-ignore
3494
- error.message.startsWith('Failed to execute definition provider: No definition provider found');
3483
+ return error?.message?.startsWith('Failed to execute definition provider: No definition provider found');
3495
3484
  };
3496
- const goToDefinition = editor => {
3485
+ const goToDefinition = async editor => {
3497
3486
  return goTo({
3498
3487
  editor,
3499
3488
  getLocation: getLocation$1,
@@ -3536,13 +3525,9 @@ const getErrorMessage$2 = error => {
3536
3525
  return `${error}`;
3537
3526
  };
3538
3527
  const isNoProviderFoundError = error => {
3539
- return error &&
3540
- // @ts-ignore
3541
- error.message &&
3542
- // @ts-ignore
3543
- error.message.startsWith('Failed to execute type definition provider: No type definition provider found');
3528
+ return error?.message?.startsWith('Failed to execute type definition provider: No type definition provider found');
3544
3529
  };
3545
- const goToTypeDefinition = (editor, explicit = true) => {
3530
+ const goToTypeDefinition = async (editor, explicit = true) => {
3546
3531
  return goTo({
3547
3532
  editor,
3548
3533
  getLocation,
@@ -4097,6 +4082,29 @@ const handleScrollBarPointerDown = (state, eventY) => {
4097
4082
  };
4098
4083
  };
4099
4084
 
4085
+ // const LONG_TOUCH_THRESHOLD = 150
4086
+
4087
+ // @ts-ignore
4088
+ const handleTouchEnd = (editor, touchEvent) => {
4089
+ // if (touchEvent.changedTouches.length === 0) {
4090
+ // return
4091
+ // }
4092
+ // const firstTouch = touchEvent.changedTouches[0]
4093
+ // const position = EditorPosition.at(editor, firstTouch.x, firstTouch.y)
4094
+ // @ts-ignore
4095
+ // if (EditorMoveSelection.state.position.rowIndex === position.rowIndex && EditorMoveSelection.state.position.columnIndex === position.columnIndex) {
4096
+ // // @ts-ignore
4097
+ // if (Date.now() - EditorHandleTouchStart.state.date > LONG_TOUCH_THRESHOLD) {
4098
+ // EditorSelectWord.selectWord(editor, position.rowIndex, position.columnIndex)
4099
+ // } else {
4100
+ // // @ts-ignore
4101
+ // EditorCursorSet.cursorSet(editor, position)
4102
+ // }
4103
+ // } else {
4104
+ // console.log('different position')
4105
+ // }
4106
+ };
4107
+
4100
4108
  const state$2 = {
4101
4109
  touchOffsetY: 0,
4102
4110
  deltaY: 0
@@ -4115,89 +4123,6 @@ const handleTouchStart = (editor, touchEvent) => {
4115
4123
  // state.date = Date.now()
4116
4124
  };
4117
4125
 
4118
- const LessThan = -1;
4119
- const Equal = 0;
4120
- const GreaterThan = 1;
4121
-
4122
- // @ts-ignore
4123
-
4124
- // @ts-ignore
4125
- const compare = (positionA, positionB) => {
4126
- if (positionA.rowIndex > positionB.rowIndex) {
4127
- return GreaterThan;
4128
- }
4129
- if (positionA.rowIndex === positionB.rowIndex) {
4130
- if (positionA.columnIndex > positionB.columnIndex) {
4131
- return GreaterThan;
4132
- }
4133
- if (positionA.columnIndex < positionB.columnIndex) {
4134
- return LessThan;
4135
- }
4136
- return Equal;
4137
- }
4138
- return LessThan;
4139
- };
4140
-
4141
- // @ts-ignore
4142
- const editorMoveSelectionBackwards = (anchor, position) => {
4143
- return new Uint32Array([anchor.rowIndex, anchor.columnIndex, position.rowIndex, position.columnIndex]);
4144
- };
4145
-
4146
- // @ts-ignore
4147
- const editorMoveSelectionEqual = (anchor, position) => {
4148
- return new Uint32Array([position.rowIndex, position.columnIndex, position.rowIndex, position.columnIndex]);
4149
- };
4150
-
4151
- // @ts-ignore
4152
- const editorMoveSelectionForwards = (anchor, position) => {
4153
- return new Uint32Array([anchor.rowIndex, anchor.columnIndex, position.rowIndex, position.columnIndex]);
4154
- };
4155
-
4156
- // @ts-ignore
4157
- const getNewSelections$5 = (anchor, position) => {
4158
- switch (compare(position, anchor)) {
4159
- case LessThan:
4160
- return editorMoveSelectionBackwards(anchor, position);
4161
- case Equal:
4162
- return editorMoveSelectionEqual(anchor, position);
4163
- case GreaterThan:
4164
- return editorMoveSelectionForwards(anchor, position);
4165
- default:
4166
- throw new Error('unexpected comparison result');
4167
- }
4168
- };
4169
-
4170
- // @ts-ignore
4171
- const editorMoveSelection = (editor, position) => {
4172
- const anchor = getPosition$1();
4173
- const newSelections = getNewSelections$5(anchor, position);
4174
- // TODO if selection equals previous selection -> do nothing
4175
- return scheduleSelections(editor, newSelections);
4176
- };
4177
-
4178
- const LONG_TOUCH_THRESHOLD = 150;
4179
-
4180
- // @ts-ignore
4181
- const handleTouchEnd = (editor, touchEvent) => {
4182
- if (touchEvent.changedTouches.length === 0) {
4183
- return;
4184
- }
4185
- const firstTouch = touchEvent.changedTouches[0];
4186
- const position = at(editor, firstTouch.x, firstTouch.y);
4187
- // @ts-ignore
4188
- if (undefined.position.rowIndex === position.rowIndex && undefined.position.columnIndex === position.columnIndex) {
4189
- // @ts-ignore
4190
- if (Date.now() - state$2.date > LONG_TOUCH_THRESHOLD) {
4191
- selectWord(editor, position.rowIndex, position.columnIndex);
4192
- } else {
4193
- // @ts-ignore
4194
- cursorSet(editor, position);
4195
- }
4196
- } else {
4197
- console.log('different position');
4198
- }
4199
- };
4200
-
4201
4126
  // @ts-ignore
4202
4127
  const setDeltaY$1 = (editor, deltaY) => {
4203
4128
  return setDeltaY$2(editor, deltaY);
@@ -4309,7 +4234,7 @@ const indentMore = editor => {
4309
4234
  return scheduleDocumentAndCursorsSelections(editor, changes);
4310
4235
  };
4311
4236
 
4312
- const getLanguageConfiguration = editor => {
4237
+ const getLanguageConfiguration = async editor => {
4313
4238
  return invoke$3('Languages.getLanguageConfiguration', {
4314
4239
  uri: editor.uri,
4315
4240
  languageId: editor.languageId
@@ -4317,7 +4242,7 @@ const getLanguageConfiguration = editor => {
4317
4242
  };
4318
4243
 
4319
4244
  const getIncreaseIndentRegex = languageConfiguration => {
4320
- if (languageConfiguration && languageConfiguration.indentationRules && languageConfiguration.indentationRules.increaseIndentPattern && typeof languageConfiguration.indentationRules.increaseIndentPattern === 'string') {
4245
+ if (languageConfiguration?.indentationRules?.increaseIndentPattern && typeof languageConfiguration.indentationRules.increaseIndentPattern === 'string') {
4321
4246
  const regex = new RegExp(languageConfiguration.indentationRules.increaseIndentPattern);
4322
4247
  return regex;
4323
4248
  }
@@ -4405,39 +4330,96 @@ const insertLineBreak = async editor => {
4405
4330
  return scheduleDocumentAndCursorsSelections(editor, changes, selectionChanges);
4406
4331
  };
4407
4332
 
4333
+ const moveRectangleSelection = (editor, position) => {
4334
+ // @ts-ignore
4335
+ // const anchor = EditorMoveSelection.state.position
4336
+ // const startRowIndex = anchor.rowIndex
4337
+ // const startColumnIndex = anchor.columnIndex
4338
+ // const endRowIndex = position.rowIndex
4339
+ // const endColumnIndex = position.columnIndex
4340
+ // const selectionEdits: any[] = []
4341
+ // for (let i = startRowIndex; i <= endRowIndex; i++) {
4342
+ // selectionEdits.push({
4343
+ // start: {
4344
+ // rowIndex: i,
4345
+ // columnIndex: startColumnIndex,
4346
+ // },
4347
+ // end: {
4348
+ // rowIndex: i,
4349
+ // columnIndex: endColumnIndex,
4350
+ // },
4351
+ // })
4352
+ // }
4353
+ // // @ts-ignore
4354
+ // const cursorEdits = [selectionEdits.at(-1).end]
4355
+ // // @ts-ignore
4356
+ // Editor.scheduleCursorsAndSelections(editor, cursorEdits, selectionEdits)
4357
+ return editor;
4358
+ };
4359
+
4408
4360
  // @ts-ignore
4361
+ const moveRectangleSelectionPx = (editor, x, y) => {
4362
+ at(editor, x, y);
4363
+ };
4364
+
4365
+ const LessThan = -1;
4366
+ const Equal = 0;
4367
+ const GreaterThan = 1;
4409
4368
 
4410
4369
  // @ts-ignore
4411
- const moveRectangleSelection = (editor, position) => {
4412
- // @ts-ignore
4413
- const anchor = undefined.position;
4414
- const startRowIndex = anchor.rowIndex;
4415
- const startColumnIndex = anchor.columnIndex;
4416
- const endRowIndex = position.rowIndex;
4417
- const endColumnIndex = position.columnIndex;
4418
- const selectionEdits = [];
4419
- for (let i = startRowIndex; i <= endRowIndex; i++) {
4420
- selectionEdits.push({
4421
- start: {
4422
- rowIndex: i,
4423
- columnIndex: startColumnIndex
4424
- },
4425
- end: {
4426
- rowIndex: i,
4427
- columnIndex: endColumnIndex
4428
- }
4429
- });
4370
+
4371
+ // @ts-ignore
4372
+ const compare = (positionA, positionB) => {
4373
+ if (positionA.rowIndex > positionB.rowIndex) {
4374
+ return GreaterThan;
4430
4375
  }
4431
- // @ts-ignore
4432
- const cursorEdits = [selectionEdits.at(-1).end];
4433
- // @ts-ignore
4434
- undefined(editor, cursorEdits, selectionEdits);
4376
+ if (positionA.rowIndex === positionB.rowIndex) {
4377
+ if (positionA.columnIndex > positionB.columnIndex) {
4378
+ return GreaterThan;
4379
+ }
4380
+ if (positionA.columnIndex < positionB.columnIndex) {
4381
+ return LessThan;
4382
+ }
4383
+ return Equal;
4384
+ }
4385
+ return LessThan;
4435
4386
  };
4436
4387
 
4437
4388
  // @ts-ignore
4438
- const moveRectangleSelectionPx = (editor, x, y) => {
4439
- const position = at(editor, x, y);
4440
- moveRectangleSelection(editor, position);
4389
+ const editorMoveSelectionBackwards = (anchor, position) => {
4390
+ return new Uint32Array([anchor.rowIndex, anchor.columnIndex, position.rowIndex, position.columnIndex]);
4391
+ };
4392
+
4393
+ // @ts-ignore
4394
+ const editorMoveSelectionEqual = (anchor, position) => {
4395
+ return new Uint32Array([position.rowIndex, position.columnIndex, position.rowIndex, position.columnIndex]);
4396
+ };
4397
+
4398
+ // @ts-ignore
4399
+ const editorMoveSelectionForwards = (anchor, position) => {
4400
+ return new Uint32Array([anchor.rowIndex, anchor.columnIndex, position.rowIndex, position.columnIndex]);
4401
+ };
4402
+
4403
+ // @ts-ignore
4404
+ const getNewSelections$5 = (anchor, position) => {
4405
+ switch (compare(position, anchor)) {
4406
+ case LessThan:
4407
+ return editorMoveSelectionBackwards(anchor, position);
4408
+ case Equal:
4409
+ return editorMoveSelectionEqual(anchor, position);
4410
+ case GreaterThan:
4411
+ return editorMoveSelectionForwards(anchor, position);
4412
+ default:
4413
+ throw new Error('unexpected comparison result');
4414
+ }
4415
+ };
4416
+
4417
+ // @ts-ignore
4418
+ const editorMoveSelection = (editor, position) => {
4419
+ const anchor = getPosition$1();
4420
+ const newSelections = getNewSelections$5(anchor, position);
4421
+ // TODO if selection equals previous selection -> do nothing
4422
+ return scheduleSelections(editor, newSelections);
4441
4423
  };
4442
4424
 
4443
4425
  const requestAnimationFrame = fn => {
@@ -4594,7 +4576,7 @@ const execute = async ({
4594
4576
  const combineResults$2 = results => {
4595
4577
  return results[0] ?? [];
4596
4578
  };
4597
- const executeCompletionProvider = (editor, offset) => {
4579
+ const executeCompletionProvider = async (editor, offset) => {
4598
4580
  return execute({
4599
4581
  editor,
4600
4582
  event: OnCompletion,
@@ -4608,7 +4590,7 @@ const executeCompletionProvider = (editor, offset) => {
4608
4590
  const combineResultsResolve = items => {
4609
4591
  return items[0] ?? undefined;
4610
4592
  };
4611
- const executeResolveCompletionItem = (editor, offset, name, completionItem) => {
4593
+ const executeResolveCompletionItem = async (editor, offset, name, completionItem) => {
4612
4594
  return execute({
4613
4595
  editor,
4614
4596
  event: OnCompletion,
@@ -5135,7 +5117,7 @@ const getSearchRegex = searchString => {
5135
5117
 
5136
5118
  const findRegexMatches = (lines, regex) => {
5137
5119
  if (!regex.global) {
5138
- throw new Error(`regex must be global`);
5120
+ throw new Error('regex must be global');
5139
5121
  }
5140
5122
  const {
5141
5123
  length
@@ -6357,7 +6339,6 @@ const loadTokenizer = async (languageId, tokenizePath) => {
6357
6339
  } catch (error) {
6358
6340
  // TODO better error handling
6359
6341
  console.error(error);
6360
- return;
6361
6342
  }
6362
6343
  };
6363
6344
  const getTokenizer = languageId => {
@@ -6479,7 +6460,7 @@ const create$3 = () => {
6479
6460
  return widget;
6480
6461
  };
6481
6462
 
6482
- const executeHoverProvider = (editor, offset) => {
6463
+ const executeHoverProvider = async (editor, offset) => {
6483
6464
  object(editor);
6484
6465
  number$1(offset);
6485
6466
  return execute({
@@ -6511,7 +6492,7 @@ const invoke = async (method, ...args) => {
6511
6492
  return invoke$5(_ipc, method, ...args);
6512
6493
  };
6513
6494
 
6514
- const measureTextBlockHeight = (text, fontFamily, fontSize, lineHeight, width) => {
6495
+ const measureTextBlockHeight = async (text, fontFamily, fontSize, lineHeight, width) => {
6515
6496
  return invoke('MeasureTextBlockHeight.measureTextBlockHeight', text, fontSize, fontFamily, lineHeight, width);
6516
6497
  };
6517
6498
 
@@ -6562,7 +6543,7 @@ const warnDeprecatedArrayReturn = (languageId, fn) => {
6562
6543
  const safeTokenizeLine = (languageId, tokenizeLine, line, lineStateAtStart, hasArrayReturn) => {
6563
6544
  try {
6564
6545
  const lineState = tokenizeLine(line, lineStateAtStart);
6565
- if (!lineState || !lineState.tokens || !lineState.state) {
6546
+ if (!lineState?.tokens || !lineState.state) {
6566
6547
  throw new Error('invalid tokenization result');
6567
6548
  }
6568
6549
  if (!hasArrayReturn) {
@@ -6713,7 +6694,7 @@ const loadHoverContent = async state => {
6713
6694
  };
6714
6695
  };
6715
6696
 
6716
- const newStateGenerator$1 = state => {
6697
+ const newStateGenerator$1 = async state => {
6717
6698
  return loadHoverContent(state);
6718
6699
  };
6719
6700
  const showHover2 = async editor => {
@@ -6799,7 +6780,7 @@ const create$2 = () => {
6799
6780
  };
6800
6781
 
6801
6782
  const showSourceActions = async editor => {
6802
- const newStateGenerator = state => {
6783
+ const newStateGenerator = async state => {
6803
6784
  return loadSourceActions(editor, state);
6804
6785
  };
6805
6786
  return addWidgetToEditor(SourceAction, SourceActions, editor, create$2, newStateGenerator);
@@ -6867,7 +6848,7 @@ const sortLinesAscending = editor => {
6867
6848
  const combineResults$1 = results => {
6868
6849
  return results[0];
6869
6850
  };
6870
- const executeTabCompletionProvider = (editor, offset) => {
6851
+ const executeTabCompletionProvider = async (editor, offset) => {
6871
6852
  return execute({
6872
6853
  editor,
6873
6854
  event: OnTabCompletion,
@@ -7004,7 +6985,7 @@ const tabCompletion = async editor => {
7004
6985
 
7005
6986
  const getBlockComment = async editor => {
7006
6987
  const languageConfiguration = await getLanguageConfiguration(editor);
7007
- if (!languageConfiguration || !languageConfiguration.comments || !languageConfiguration.comments.blockComment) {
6988
+ if (!languageConfiguration?.comments?.blockComment) {
7008
6989
  return undefined;
7009
6990
  }
7010
6991
  return languageConfiguration.comments.blockComment;
@@ -7212,7 +7193,7 @@ const toggleBlockComment = async editor => {
7212
7193
 
7213
7194
  const getLineComment = async editor => {
7214
7195
  const languageConfiguration = await getLanguageConfiguration(editor);
7215
- if (!languageConfiguration || !languageConfiguration.comments || !languageConfiguration.comments.lineComment) {
7196
+ if (!languageConfiguration?.comments?.lineComment) {
7216
7197
  return undefined;
7217
7198
  }
7218
7199
  return languageConfiguration.comments.lineComment;
@@ -7476,96 +7457,98 @@ const undo = state => {
7476
7457
  };
7477
7458
 
7478
7459
  // @ts-ignore
7479
- const INDENT = ' ';
7460
+
7461
+ // const INDENT = ' '
7480
7462
 
7481
7463
  // @ts-ignore
7482
7464
  const editorUnindent = editor => {
7483
- if (hasSelection(editor)) {
7484
- const documentEdits = [];
7485
- const cursorEdits = [];
7486
- const selectionEdits = [];
7487
- // @ts-ignore
7488
- const canUnindentSelection = selection => {
7489
- for (let i = selection.start.rowIndex; i <= selection.end.rowIndex; i++) {
7490
- if (editor.lines[i].startsWith(INDENT)) {
7491
- return true;
7492
- }
7493
- }
7494
- return false;
7495
- };
7496
- // TODO replace check with flag that indicates whether change occurred
7497
- // -> only iterate once over selection lines
7498
-
7499
- if (!editor.selections.some(canUnindentSelection)) {
7500
- return;
7501
- }
7502
- // @ts-ignore
7503
- const indentLineMaybe = rowIndex => {
7504
- if (editor.lines[rowIndex].startsWith(INDENT)) {
7505
- documentEdits.push({
7506
- type: /* singleLineEdit */1,
7507
- rowIndex,
7508
- columnIndex: INDENT.length,
7509
- deleted: INDENT.length,
7510
- inserted: ''
7511
- });
7512
- }
7513
- };
7514
- let previousRowIndex = -1;
7515
- for (const selection of editor.selections) {
7516
- let startRowIndex = selection.start.rowIndex;
7517
- const endRowIndex = selection.end.rowIndex;
7518
- if (startRowIndex === previousRowIndex) {
7519
- startRowIndex++;
7520
- }
7521
- for (let i = startRowIndex; i <= endRowIndex; i++) {
7522
- indentLineMaybe(i);
7523
- }
7524
- let start = selection.start;
7525
- let end = selection.end;
7526
- if (editor.lines[start.rowIndex].startsWith(INDENT)) {
7527
- start = {
7528
- rowIndex: start.rowIndex,
7529
- columnIndex: Math.max(start.columnIndex - INDENT.length, 0)
7530
- };
7531
- }
7532
- if (editor.lines[end.rowIndex].startsWith(INDENT)) {
7533
- end = {
7534
- rowIndex: end.rowIndex,
7535
- columnIndex: Math.max(end.columnIndex - INDENT.length, 0)
7536
- };
7537
- }
7538
- cursorEdits.push(end);
7539
- selectionEdits.push({
7540
- start,
7541
- end
7542
- });
7543
- previousRowIndex = endRowIndex;
7544
- }
7545
- // @ts-ignore
7546
- undefined(editor, documentEdits, cursorEdits, selectionEdits);
7547
- return;
7548
- }
7549
- const documentEdits = [];
7550
- const cursorEdits = [];
7551
- if (!editor.lines[editor.cursor.rowIndex].startsWith(INDENT)) {
7552
- return;
7553
- }
7554
- // @ts-ignore
7555
- documentEdits.push({
7556
- type: /* singleLineEdit */1,
7557
- rowIndex: editor.cursor.rowIndex,
7558
- inserted: '',
7559
- columnIndex: 2,
7560
- deleted: 2
7561
- });
7562
- // @ts-ignore
7563
- cursorEdits.push({
7564
- rowIndex: editor.cursor.rowIndex,
7565
- columnIndex: editor.cursor.columnIndex - 2
7566
- });
7567
- // @ts-ignore
7568
- undefined(editor, documentEdits, cursorEdits);
7465
+ // if (Editor.hasSelection(editor)) {
7466
+ // const documentEdits: any[] = []
7467
+ // const cursorEdits: any[] = []
7468
+ // const selectionEdits: any[] = []
7469
+ // // @ts-ignore
7470
+ // const canUnindentSelection = (selection) => {
7471
+ // for (let i = selection.start.rowIndex; i <= selection.end.rowIndex; i++) {
7472
+ // if (editor.lines[i].startsWith(INDENT)) {
7473
+ // return true
7474
+ // }
7475
+ // }
7476
+ // return false
7477
+ // }
7478
+ // // TODO replace check with flag that indicates whether change occurred
7479
+ // // -> only iterate once over selection lines
7480
+
7481
+ // if (!editor.selections.some(canUnindentSelection)) {
7482
+ // return
7483
+ // }
7484
+ // // @ts-ignore
7485
+ // const indentLineMaybe = (rowIndex) => {
7486
+ // if (editor.lines[rowIndex].startsWith(INDENT)) {
7487
+ // documentEdits.push({
7488
+ // type: /* singleLineEdit */ 1,
7489
+ // rowIndex,
7490
+ // columnIndex: INDENT.length,
7491
+ // deleted: INDENT.length,
7492
+ // inserted: '',
7493
+ // })
7494
+ // }
7495
+ // }
7496
+ // let previousRowIndex = -1
7497
+ // for (const selection of editor.selections) {
7498
+ // let startRowIndex = selection.start.rowIndex
7499
+ // const endRowIndex = selection.end.rowIndex
7500
+ // if (startRowIndex === previousRowIndex) {
7501
+ // startRowIndex++
7502
+ // }
7503
+ // for (let i = startRowIndex; i <= endRowIndex; i++) {
7504
+ // indentLineMaybe(i)
7505
+ // }
7506
+ // let start = selection.start
7507
+ // let end = selection.end
7508
+ // if (editor.lines[start.rowIndex].startsWith(INDENT)) {
7509
+ // start = {
7510
+ // rowIndex: start.rowIndex,
7511
+ // columnIndex: Math.max(start.columnIndex - INDENT.length, 0),
7512
+ // }
7513
+ // }
7514
+ // if (editor.lines[end.rowIndex].startsWith(INDENT)) {
7515
+ // end = {
7516
+ // rowIndex: end.rowIndex,
7517
+ // columnIndex: Math.max(end.columnIndex - INDENT.length, 0),
7518
+ // }
7519
+ // }
7520
+ // cursorEdits.push(end)
7521
+ // selectionEdits.push({
7522
+ // start,
7523
+ // end,
7524
+ // })
7525
+ // previousRowIndex = endRowIndex
7526
+ // }
7527
+ // // @ts-ignore
7528
+ // Editor.scheduleDocumentAndCursorsAndSelections(editor, documentEdits, cursorEdits, selectionEdits)
7529
+ // return
7530
+ // }
7531
+ // const documentEdits = []
7532
+ // const cursorEdits = []
7533
+ // if (!editor.lines[editor.cursor.rowIndex].startsWith(INDENT)) {
7534
+ // return
7535
+ // }
7536
+ // // @ts-ignore
7537
+ // documentEdits.push({
7538
+ // type: /* singleLineEdit */ 1,
7539
+ // rowIndex: editor.cursor.rowIndex,
7540
+ // inserted: '',
7541
+ // columnIndex: 2,
7542
+ // deleted: 2,
7543
+ // })
7544
+ // // @ts-ignore
7545
+ // cursorEdits.push({
7546
+ // rowIndex: editor.cursor.rowIndex,
7547
+ // columnIndex: editor.cursor.columnIndex - 2,
7548
+ // })
7549
+ // // @ts-ignore
7550
+ // Editor.scheduleDocumentAndCursors(editor, documentEdits, cursorEdits)
7551
+ return editor;
7569
7552
  };
7570
7553
  // const editor = {
7571
7554
  // textDocument: {
@@ -7863,6 +7846,7 @@ const handleSashPointerUp = (state, eventX, eventY) => {
7863
7846
  };
7864
7847
 
7865
7848
  const CodeGeneratorInput = 'CodeGeneratorInput';
7849
+ const CodeGeneratorMessage = 'CodeGeneratorMessage';
7866
7850
  const CodeGeneratorWidget = 'CodeGeneratorWidget';
7867
7851
  const ColoredMaskIcon = 'ColoredMaskIcon';
7868
7852
  const ColorPicker = 'ColorPicker';
@@ -7872,7 +7856,6 @@ const ColorPickerLight = 'ColorPickerLight';
7872
7856
  const ColorPickerRectangle = 'ColorPickerRectangle';
7873
7857
  const ColorPickerSlider = 'ColorPickerSlider';
7874
7858
  const ColorPickerSliderThumb = 'ColorPickerSliderThumb';
7875
- const CodeGeneratorMessage = 'CodeGeneratorMessage';
7876
7859
  const CompletionDetailCloseButton = 'CompletionDetailCloseButton';
7877
7860
  const CompletionDetailContent = 'CompletionDetailContent';
7878
7861
  const Diagnostic = 'Diagnostic';
@@ -7903,10 +7886,12 @@ const IconClose = 'IconClose';
7903
7886
  const InputBox = 'InputBox';
7904
7887
  const Label = 'Label';
7905
7888
  const MaskIcon = 'MaskIcon';
7889
+ const MaskIconSymbolFile = 'MaskIconSymbolFile';
7906
7890
  const MultilineInputBox = 'MultilineInputBox';
7907
7891
  const SearchField = 'SearchField';
7908
7892
  const SearchFieldButtons = 'SearchFieldButtons';
7909
7893
  const SourceActionHeading = 'SourceActionHeading';
7894
+ const SourceActionIcon = 'SourceActionIcon';
7910
7895
  const SourceActionItem = 'SourceActionItem';
7911
7896
  const SourceActionItemFocused = 'SourceActionItemFocused';
7912
7897
  const Viewlet = 'Viewlet';
@@ -8067,7 +8052,7 @@ const renderHover = (oldState, newState) => {
8067
8052
  const combineResults = results => {
8068
8053
  return results[0] ?? [];
8069
8054
  };
8070
- const executeRenameProvider = (editor, offset, newName) => {
8055
+ const executeRenameProvider = async (editor, offset, newName) => {
8071
8056
  return execute({
8072
8057
  editor,
8073
8058
  event: OnRename,
@@ -8084,7 +8069,7 @@ const getRenameState = editor => {
8084
8069
  };
8085
8070
 
8086
8071
  const getRenameChanges = (editor, result) => {
8087
- if (!result || !result.edits) {
8072
+ if (!result?.edits) {
8088
8073
  return [];
8089
8074
  }
8090
8075
  const changes = [];
@@ -8329,25 +8314,28 @@ const intialize = async (syntaxHighlightingEnabled, syncIncremental) => {
8329
8314
  // TODO multiple cursors -> vscode removes multiple cursors
8330
8315
  // TODO with selection -> vscode moves whole selection
8331
8316
  const moveLineDown = editor => {
8332
- const rowIndex = editor.cursor.rowIndex;
8333
- if (rowIndex === editor.lines.length - 1) {
8334
- return;
8335
- }
8336
- const documentEdits = [{
8337
- type: /* splice */2,
8338
- rowIndex: rowIndex,
8339
- count: 2,
8340
- newLines: [getLine(editor.textDocument, rowIndex + 1), getLine(editor.textDocument, rowIndex)]
8341
- }];
8342
- // @ts-ignore
8343
- const cursorEdits = undefined(editor, (editor, cursor) => {
8344
- return {
8345
- rowIndex: cursor.rowIndex + 1,
8346
- columnIndex: cursor.columnIndex
8347
- };
8348
- });
8317
+ // const rowIndex = editor.cursor.rowIndex
8318
+ // if (rowIndex === editor.lines.length - 1) {
8319
+ // return
8320
+ // }
8321
+ // const documentEdits = [
8322
+ // {
8323
+ // type: /* splice */ 2,
8324
+ // rowIndex: rowIndex,
8325
+ // count: 2,
8326
+ // newLines: [TextDocument.getLine(editor.textDocument, rowIndex + 1), TextDocument.getLine(editor.textDocument, rowIndex)],
8327
+ // },
8328
+ // ]
8329
+ // // @ts-ignore
8330
+ // const cursorEdits = Editor.moveCursors(editor, (editor, cursor) => {
8331
+ // return {
8332
+ // rowIndex: cursor.rowIndex + 1,
8333
+ // columnIndex: cursor.columnIndex,
8334
+ // }
8335
+ // })
8349
8336
  // @ts-ignore
8350
- undefined(editor, documentEdits, cursorEdits);
8337
+ // Editor.scheduleDocumentAndCursors(editor, documentEdits, cursorEdits)
8338
+ return editor;
8351
8339
  };
8352
8340
 
8353
8341
  const create = () => {
@@ -8395,26 +8383,29 @@ const openCodeGenerator = async editor => {
8395
8383
 
8396
8384
  // TODO handle multiple cursors
8397
8385
  const moveLineUp = editor => {
8398
- const rowIndex = editor.cursor.rowIndex;
8399
- if (rowIndex === 0) {
8400
- return;
8401
- }
8402
- const documentEdits = [{
8403
- type: /* splice */2,
8404
- rowIndex: rowIndex - 1,
8405
- count: 2,
8406
- newLines: [getLine(editor.textDocument, rowIndex), getLine(editor.textDocument, rowIndex - 1)]
8407
- }];
8408
- // @ts-ignore
8409
- const cursorEdits = undefined(editor, (editor, cursor) => {
8410
- return {
8411
- // TODO handle bottom 0
8412
- rowIndex: cursor.rowIndex - 1,
8413
- columnIndex: cursor.columnIndex
8414
- };
8415
- });
8416
- // @ts-ignore
8417
- undefined(editor, documentEdits, cursorEdits);
8386
+ // const rowIndex = editor.cursor.rowIndex
8387
+ // if (rowIndex === 0) {
8388
+ // return
8389
+ // }
8390
+ // const documentEdits = [
8391
+ // {
8392
+ // type: /* splice */ 2,
8393
+ // rowIndex: rowIndex - 1,
8394
+ // count: 2,
8395
+ // newLines: [TextDocument.getLine(editor.textDocument, rowIndex), TextDocument.getLine(editor.textDocument, rowIndex - 1)],
8396
+ // },
8397
+ // ]
8398
+ // // @ts-ignore
8399
+ // const cursorEdits = Editor.moveCursors(editor, (editor, cursor) => {
8400
+ // return {
8401
+ // // TODO handle bottom 0
8402
+ // rowIndex: cursor.rowIndex - 1,
8403
+ // columnIndex: cursor.columnIndex,
8404
+ // }
8405
+ // })
8406
+ // // @ts-ignore
8407
+ // Editor.scheduleDocumentAndCursors(editor, documentEdits, cursorEdits)
8408
+ return editor;
8418
8409
  };
8419
8410
 
8420
8411
  const Link$1 = 'Link';
@@ -8627,7 +8618,7 @@ const getTokensViewport = (editor, startLineIndex, endLineIndex) => {
8627
8618
  const sentLines = Object.create(null);
8628
8619
 
8629
8620
  // TODO only send changed lines to renderer process instead of all lines in viewport
8630
- const getTokensViewport2 = (editor, startLineIndex, endLineIndex, syncIncremental) => {
8621
+ const getTokensViewport2 = async (editor, startLineIndex, endLineIndex, syncIncremental) => {
8631
8622
  if (getEnabled$1()) {
8632
8623
  if (syncIncremental) {
8633
8624
  const {
@@ -8828,7 +8819,7 @@ const getLineInfo = (line, tokenResults, embeddedResults, decorations, TokenMap,
8828
8819
  } = getOffsets(deltaX, width, averageCharWidth);
8829
8820
  if (embeddedResults.length > 0 && tokenResults.embeddedResultIndex !== undefined) {
8830
8821
  const embeddedResult = embeddedResults[tokenResults.embeddedResultIndex];
8831
- if (embeddedResult && embeddedResult.isFull) {
8822
+ if (embeddedResult?.isFull) {
8832
8823
  return getLineInfoEmbeddedFull(embeddedResults, tokenResults, line, normalize, tabSize, width, deltaX, averageCharWidth, minOffset, maxOffset);
8833
8824
  }
8834
8825
  }
@@ -9039,14 +9030,14 @@ const addWidget$1 = widget => {
9039
9030
  const renderWidget = widget => {
9040
9031
  const module = get$7(widget.id);
9041
9032
  if (!module) {
9042
- throw new Error(`unsupported widget`);
9033
+ throw new Error('unsupported widget');
9043
9034
  }
9044
9035
  return module.render(widget);
9045
9036
  };
9046
9037
  const removeWidget$1 = widget => {
9047
9038
  const module = get$7(widget.id);
9048
9039
  if (!module) {
9049
- throw new Error(`unsupported widget`);
9040
+ throw new Error('unsupported widget');
9050
9041
  }
9051
9042
  return module.remove(widget);
9052
9043
  };
@@ -9243,7 +9234,8 @@ const closeCodeGenerator = editor => {
9243
9234
  const newWidgets = removeEditorWidget(widgets, CodeGenerator);
9244
9235
  return {
9245
9236
  ...editor,
9246
- widgets: newWidgets
9237
+ widgets: newWidgets,
9238
+ focused: true
9247
9239
  };
9248
9240
  };
9249
9241
 
@@ -9325,7 +9317,13 @@ const wrapCommands = commands => {
9325
9317
  }
9326
9318
  };
9327
9319
 
9320
+ const codeGeneratorAccept = state => {
9321
+ // TODO close code generator widget
9322
+ return state;
9323
+ };
9324
+
9328
9325
  const commandMap = {
9326
+ 'CodeGenerator.accept': codeGeneratorAccept,
9329
9327
  'ColorPicker.handleSliderPointerDown': handleSliderPointerDown,
9330
9328
  'ColorPicker.handleSliderPointerMove': handleSliderPointerMove,
9331
9329
  'ColorPicker.loadContent': loadContent$3,
@@ -10808,23 +10806,41 @@ const getFindWidgetButtonsEnabled = (matchCount, value) => {
10808
10806
  const getFindWidgetFocusSelector = focus => {
10809
10807
  switch (focus) {
10810
10808
  case FindWidget:
10811
- return `[name="${SearchValue}"]`;
10809
+ {
10810
+ return `[name="${SearchValue}"]`;
10811
+ }
10812
10812
  case FocusFindWidgetReplace:
10813
- return `[name="${ReplaceValue}"]`;
10813
+ {
10814
+ return `[name="${ReplaceValue}"]`;
10815
+ }
10814
10816
  case FocusFindWidgetReplaceAllButton:
10815
- return `[name="${ReplaceAll}"]`;
10817
+ {
10818
+ return `[name="${ReplaceAll}"]`;
10819
+ }
10816
10820
  case FocusFindWidgetCloseButton:
10817
- return `[name="${Close}"]`;
10821
+ {
10822
+ return `[name="${Close}"]`;
10823
+ }
10818
10824
  case FocusFindWidgetToggleReplace:
10819
- return `[name="${ToggleReplace}"]`;
10825
+ {
10826
+ return `[name="${ToggleReplace}"]`;
10827
+ }
10820
10828
  case FocusFindWidgetNextMatchButton:
10821
- return `[name="${FocusNext}"]`;
10829
+ {
10830
+ return `[name="${FocusNext}"]`;
10831
+ }
10822
10832
  case FocusFindWidgetPreviousMatchButton:
10823
- return `[name="${FocusPrevious}"]`;
10833
+ {
10834
+ return `[name="${FocusPrevious}"]`;
10835
+ }
10824
10836
  case FocusFindWidgetReplaceButton:
10825
- return `[name="${Replace}"]`;
10837
+ {
10838
+ return `[name="${Replace}"]`;
10839
+ }
10826
10840
  default:
10827
- return '';
10841
+ {
10842
+ return '';
10843
+ }
10828
10844
  }
10829
10845
  };
10830
10846
 
@@ -11249,7 +11265,7 @@ const getSourceActionListItemVirtualDom = sourceAction => {
11249
11265
  childCount: 2
11250
11266
  }, {
11251
11267
  type: Div,
11252
- className: 'SourceActionIcon MaskIcon MaskIconSymbolFile'
11268
+ className: mergeClassNames(SourceActionIcon, MaskIcon, MaskIconSymbolFile)
11253
11269
  }, text(name)];
11254
11270
  };
11255
11271
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "4.13.0",
3
+ "version": "5.0.0",
4
4
  "description": "",
5
5
  "main": "dist/editorWorkerMain.js",
6
6
  "type": "module",