@lvce-editor/editor-worker 19.75.3 → 19.75.5

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.
package/dist/diff-sdk.js CHANGED
@@ -4869,7 +4869,12 @@ const updateTransformedDiagnostics = async (editor, changes) => {
4869
4869
  return addDiagnostics(editor, diagnostics);
4870
4870
  };
4871
4871
  const scheduleSelections = (editor, selectionEdits) => {
4872
- return setSelections$2(editor, selectionEdits);
4872
+ return {
4873
+ ...setSelections$2(editor, selectionEdits),
4874
+ ...(editor.snippetTabStops && {
4875
+ snippetTabStops: undefined
4876
+ })
4877
+ };
4873
4878
  };
4874
4879
  const updateLines = (editor, lines) => {
4875
4880
  const newEditor = {
@@ -4930,6 +4935,7 @@ const scheduleDocumentAndCursorsSelections = async (editor, changes, selectionCh
4930
4935
  modified: true,
4931
4936
  redoStack: [],
4932
4937
  selections: newSelections,
4938
+ snippetTabStops: changes.every(change => change.origin === EditorType || change.origin === EditorTypeWithAutoClosing) ? editor.snippetTabStops : undefined,
4933
4939
  undoStack
4934
4940
  };
4935
4941
  // Update link decorations after text changes
@@ -4992,7 +4998,8 @@ const scheduleDocumentAndCursorsSelectionIsUndo = async (editor, changes, select
4992
4998
  // undoStack: [...editor.undoStack.slice(0, -2)],
4993
4999
  invalidStartIndex,
4994
5000
  lines: newLines,
4995
- selections: newSelections
5001
+ selections: newSelections,
5002
+ snippetTabStops: undefined
4996
5003
  };
4997
5004
  const incrementalEdits = await getIncrementalEdits(editor, newEditor);
4998
5005
 
@@ -9787,18 +9794,20 @@ const cursorDocumentStart = editor => {
9787
9794
  return scheduleSelections(editor, newSelections);
9788
9795
  };
9789
9796
 
9790
- const moveSelectionDown = (lastRow, selections, i, selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn) => {
9791
- moveRangeToPosition$1(selections, i, Math.min(selectionEndRow + 1, lastRow), selectionEndColumn);
9797
+ const moveSelectionDown = (lastRow, lines, selections, i, selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn) => {
9798
+ const rowIndex = Math.min(selectionEndRow + 1, lastRow);
9799
+ const columnIndex = Math.min(selectionEndColumn, lines[rowIndex].length);
9800
+ moveRangeToPosition$1(selections, i, rowIndex, columnIndex);
9792
9801
  };
9793
- const getNewSelections$9 = (selections, lastRow) => {
9794
- return map(selections, moveSelectionDown.bind(null, lastRow));
9802
+ const getNewSelections$9 = (selections, lines) => {
9803
+ return map(selections, moveSelectionDown.bind(null, Math.max(0, lines.length - 1), lines));
9795
9804
  };
9796
9805
  const cursorDown = editor => {
9797
9806
  const {
9798
9807
  lines,
9799
9808
  selections
9800
9809
  } = editor;
9801
- const newSelections = getNewSelections$9(selections, Math.max(0, lines.length - 1));
9810
+ const newSelections = getNewSelections$9(selections, lines);
9802
9811
  return scheduleSelections(editor, newSelections);
9803
9812
  };
9804
9813
 
@@ -14211,24 +14220,38 @@ const getTabCompletion = async editor => {
14211
14220
  return completions;
14212
14221
  };
14213
14222
 
14223
+ const getSnippetLines = inserted => {
14224
+ return splitLines$2(inserted).map(line => {
14225
+ const tabStops = [];
14226
+ let text = '';
14227
+ for (let i = 0; i < line.length; i++) {
14228
+ if (line[i] === '$' && line[i + 1] >= '0' && line[i + 1] <= '9' && line[i - 1] !== '\\') {
14229
+ tabStops.push({
14230
+ index: Number(line[i + 1]),
14231
+ position: text.length
14232
+ });
14233
+ i++;
14234
+ } else {
14235
+ text += line[i];
14236
+ }
14237
+ }
14238
+ return {
14239
+ tabStops,
14240
+ text
14241
+ };
14242
+ });
14243
+ };
14214
14244
  const getSnippetChanges = (lines, selections, snippet) => {
14215
14245
  // TODO verify that deleted fits in the line
14216
- const insertedLines = splitLines$2(snippet.inserted);
14246
+ const parsedLines = getSnippetLines(snippet.inserted);
14247
+ const insertedLines = parsedLines.map(line => line.text);
14217
14248
  const changes = [];
14218
14249
  const selectionChanges = [];
14250
+ const tabStops = [];
14219
14251
  for (let i = 0; i < selections.length; i += 4) {
14220
14252
  const [selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn] = getSelectionPairs(selections, i);
14221
14253
  if (insertedLines.length > 1) {
14222
- let placeholderRow = -1;
14223
- let placeholderColumn = -1;
14224
- const insertedLinesWithoutPlaceholder = insertedLines.map((line, rowIndex) => {
14225
- const index = line.indexOf('$0');
14226
- if (index !== -1 && placeholderRow === -1) {
14227
- placeholderRow = rowIndex;
14228
- placeholderColumn = index;
14229
- }
14230
- return line.replace('$0', '');
14231
- });
14254
+ const insertedLinesWithoutPlaceholder = insertedLines;
14232
14255
  const line = getLine$1({
14233
14256
  lines
14234
14257
  }, selectionStartRow);
@@ -14249,32 +14272,45 @@ const getSnippetChanges = (lines, selections, snippet) => {
14249
14272
  }
14250
14273
  });
14251
14274
  const lastInsertedLine = insertedLines.at(-1);
14252
- if (placeholderRow === -1) {
14275
+ const stops = parsedLines.flatMap((line, rowIndex) => line.tabStops.map(stop => ({
14276
+ ...stop,
14277
+ rowIndex
14278
+ })));
14279
+ const initialStop = stops.find(stop => stop.index === 0) ?? stops.filter(stop => stop.index > 0).toSorted((a, b) => a.index - b.index)[0];
14280
+ if (initialStop) {
14281
+ const cursorRow = selectionStartRow + initialStop.rowIndex;
14282
+ const cursorColumn = initialStop.position + (initialStop.rowIndex === 0 ? selectionStartColumn - snippet.deleted : indent.length);
14283
+ selectionChanges.push(cursorRow, cursorColumn, cursorRow, cursorColumn);
14284
+ } else {
14253
14285
  selectionChanges.push(selectionEndRow + insertedLines.length - deleted.length,
14254
14286
  // @ts-ignore
14255
14287
  selectionEndColumn + lastInsertedLine.length, selectionEndRow + insertedLines.length - deleted.length,
14256
14288
  // @ts-ignore
14257
14289
  selectionEndColumn + lastInsertedLine.length);
14258
- } else {
14259
- const cursorRow = selectionStartRow + placeholderRow;
14260
- const cursorColumn = placeholderColumn + (placeholderRow === 0 ? selectionStartColumn - snippet.deleted : indent.length);
14261
- selectionChanges.push(cursorRow, cursorColumn, cursorRow, cursorColumn);
14290
+ }
14291
+ for (const stop of stops) {
14292
+ const columnIndex = stop.position + (stop.rowIndex === 0 ? selectionStartColumn - snippet.deleted : indent.length);
14293
+ tabStops.push({
14294
+ columnIndex,
14295
+ index: stop.index,
14296
+ rowIndex: selectionStartRow + stop.rowIndex
14297
+ });
14262
14298
  }
14263
14299
  } else {
14264
14300
  const line = insertedLines[0];
14265
- const placeholderIndex = line.indexOf('$0');
14266
- if (placeholderIndex === -1) {
14267
- const cursorColumnIndex = selectionStartColumn - snippet.deleted;
14268
- // @ts-ignore
14301
+ const stops = parsedLines[0].tabStops;
14302
+ const initialStop = stops.find(stop => stop.index === 0) ?? stops.filter(stop => stop.index > 0).toSorted((a, b) => a.index - b.index)[0];
14303
+ if (initialStop) {
14304
+ const inserted = line;
14305
+ const cursorColumnIndex = selectionStartColumn - snippet.deleted + initialStop.position;
14269
14306
  selectionChanges.push(selectionStartRow, cursorColumnIndex, selectionStartRow, cursorColumnIndex);
14270
- // @ts-ignore
14271
14307
  changes.push({
14272
14308
  deleted: [''],
14273
14309
  end: {
14274
14310
  columnIndex: selectionEndColumn,
14275
14311
  rowIndex: selectionEndRow
14276
14312
  },
14277
- inserted: insertedLines,
14313
+ inserted: [inserted],
14278
14314
  origin: EditorSnippet,
14279
14315
  start: {
14280
14316
  columnIndex: selectionStartColumn - snippet.deleted,
@@ -14282,16 +14318,17 @@ const getSnippetChanges = (lines, selections, snippet) => {
14282
14318
  }
14283
14319
  });
14284
14320
  } else {
14285
- const inserted = line.replace('$0', '');
14286
- const cursorColumnIndex = selectionStartColumn - snippet.deleted + placeholderIndex;
14321
+ const cursorColumnIndex = selectionStartColumn - snippet.deleted;
14322
+ // @ts-ignore
14287
14323
  selectionChanges.push(selectionStartRow, cursorColumnIndex, selectionStartRow, cursorColumnIndex);
14324
+ // @ts-ignore
14288
14325
  changes.push({
14289
14326
  deleted: [''],
14290
14327
  end: {
14291
14328
  columnIndex: selectionEndColumn,
14292
14329
  rowIndex: selectionEndRow
14293
14330
  },
14294
- inserted: [inserted],
14331
+ inserted: insertedLines,
14295
14332
  origin: EditorSnippet,
14296
14333
  start: {
14297
14334
  columnIndex: selectionStartColumn - snippet.deleted,
@@ -14299,18 +14336,26 @@ const getSnippetChanges = (lines, selections, snippet) => {
14299
14336
  }
14300
14337
  });
14301
14338
  }
14339
+ for (const stop of stops) {
14340
+ tabStops.push({
14341
+ columnIndex: selectionStartColumn - snippet.deleted + stop.position,
14342
+ index: stop.index,
14343
+ rowIndex: selectionStartRow
14344
+ });
14345
+ }
14302
14346
  }
14303
14347
  }
14304
14348
  return {
14305
14349
  changes,
14306
- selectionChanges: new Uint32Array(selectionChanges)
14350
+ selectionChanges: new Uint32Array(selectionChanges),
14351
+ tabStops
14307
14352
  };
14308
14353
  };
14309
14354
 
14310
14355
  // const getIndent =
14311
14356
  // TODO rename to insertSnippet
14312
14357
  // TODO handle snippet tabstops and cursors $0 -> becomes cursor
14313
- const editorSnippet = (editor, snippet) => {
14358
+ const editorSnippet = async (editor, snippet) => {
14314
14359
  // TODO verify that deleted fits in the line
14315
14360
  const {
14316
14361
  lines,
@@ -14318,9 +14363,27 @@ const editorSnippet = (editor, snippet) => {
14318
14363
  } = editor;
14319
14364
  const {
14320
14365
  changes,
14321
- selectionChanges
14366
+ selectionChanges,
14367
+ tabStops
14322
14368
  } = getSnippetChanges(lines, selections, snippet);
14323
- return scheduleDocumentAndCursorsSelections(editor, changes, selectionChanges);
14369
+ const newEditor = await scheduleDocumentAndCursorsSelections(editor, changes, selectionChanges);
14370
+ if (selections.length !== 4 || tabStops.length < 2) {
14371
+ return newEditor;
14372
+ }
14373
+ const initialStop = tabStops.find(stop => stop.index === 0) ?? tabStops.filter(stop => stop.index > 0).toSorted((a, b) => a.index - b.index)[0];
14374
+ const remainingStops = tabStops.filter(stop => stop !== initialStop && stop.index > 0).toSorted((a, b) => a.index - b.index).map(stop => ({
14375
+ offset: offsetAt(newEditor, stop.rowIndex, stop.columnIndex)
14376
+ }));
14377
+ if (remainingStops.length === 0) {
14378
+ return newEditor;
14379
+ }
14380
+ return {
14381
+ ...newEditor,
14382
+ snippetTabStops: {
14383
+ activeOffset: offsetAt(newEditor, initialStop.rowIndex, initialStop.columnIndex),
14384
+ stops: remainingStops
14385
+ }
14386
+ };
14324
14387
  };
14325
14388
 
14326
14389
  const getErrorMessage$1 = String;
@@ -14517,6 +14580,19 @@ const getBlockCommentEdits = (editor, blockComment) => {
14517
14580
  };
14518
14581
 
14519
14582
  const getLineComment = async editor => {
14583
+ try {
14584
+ const lineComment = await execute({
14585
+ args: [],
14586
+ editor,
14587
+ kind: 'comment',
14588
+ method: 'provideComment'
14589
+ });
14590
+ if (Array.isArray(lineComment) && lineComment[1] === '') {
14591
+ return lineComment[0];
14592
+ }
14593
+ } catch {
14594
+ // ignore
14595
+ }
14520
14596
  const languageConfiguration = await getLanguageConfiguration(editor);
14521
14597
  if (!languageConfiguration?.comments?.lineComment) {
14522
14598
  return undefined;
@@ -14827,7 +14903,7 @@ const typeWithAutoClosing = async (editor, text) => {
14827
14903
  switch (text) {
14828
14904
  // case AutoClosing.ClosingAngleBracket: // TODO support auto closing when typing closing angle bracket of start tag
14829
14905
  case Slash:
14830
- if (isAutoClosingTagsEnabled) {
14906
+ if (isAutoClosingTagsEnabled && isClosingTagSlash(editor)) {
14831
14907
  return typeWithAutoClosingTag(editor, text);
14832
14908
  }
14833
14909
  break;
@@ -14877,6 +14953,13 @@ const typeWithAutoClosing = async (editor, text) => {
14877
14953
  // TODO should editor type command know about editor completion? -> no
14878
14954
  // EditorCommandCompletion.openFromType(editor, text)
14879
14955
  };
14956
+ const isClosingTagSlash = editor => {
14957
+ const [startRow, startColumn, endRow, endColumn] = editor.selections;
14958
+ if (startRow !== endRow || startColumn !== endColumn || startColumn === 0) {
14959
+ return false;
14960
+ }
14961
+ return editor.lines[startRow][startColumn - 1] === '<';
14962
+ };
14880
14963
 
14881
14964
  const inverseChange = edit => {
14882
14965
  const insertedLines = edit.inserted;
@@ -16963,6 +17046,34 @@ const handleTab = async editor => {
16963
17046
  if (!isEverySelectionEmpty(editor.selections)) {
16964
17047
  return indentMore(editor);
16965
17048
  }
17049
+ if (editor.snippetTabStops) {
17050
+ const {
17051
+ activeOffset,
17052
+ stops
17053
+ } = editor.snippetTabStops;
17054
+ if (stops.length > 0 && editor.selections.length === 4) {
17055
+ const offset = offsetAt(editor, editor.selections[2], editor.selections[3]);
17056
+ const delta = offset - activeOffset;
17057
+ if (delta >= 0) {
17058
+ const [nextStop, ...remainingStops] = stops;
17059
+ const position = positionAt(editor, nextStop.offset + delta);
17060
+ const newEditor = scheduleSelections(editor, new Uint32Array([position.rowIndex, position.columnIndex, position.rowIndex, position.columnIndex]));
17061
+ return {
17062
+ ...newEditor,
17063
+ snippetTabStops: remainingStops.length > 0 ? {
17064
+ activeOffset: nextStop.offset + delta,
17065
+ stops: remainingStops.map(stop => ({
17066
+ offset: stop.offset + delta
17067
+ }))
17068
+ } : undefined
17069
+ };
17070
+ }
17071
+ }
17072
+ editor = {
17073
+ ...editor,
17074
+ snippetTabStops: undefined
17075
+ };
17076
+ }
16966
17077
  try {
16967
17078
  const result = await getTabCompletion(editor);
16968
17079
  if (!result) {
@@ -5282,7 +5282,12 @@ const updateTransformedDiagnostics = async (editor, changes) => {
5282
5282
  return addDiagnostics(editor, diagnostics);
5283
5283
  };
5284
5284
  const scheduleSelections = (editor, selectionEdits) => {
5285
- return setSelections$2(editor, selectionEdits);
5285
+ return {
5286
+ ...setSelections$2(editor, selectionEdits),
5287
+ ...(editor.snippetTabStops && {
5288
+ snippetTabStops: undefined
5289
+ })
5290
+ };
5286
5291
  };
5287
5292
  const updateLines = (editor, lines) => {
5288
5293
  const newEditor = {
@@ -5343,6 +5348,7 @@ const scheduleDocumentAndCursorsSelections = async (editor, changes, selectionCh
5343
5348
  modified: true,
5344
5349
  redoStack: [],
5345
5350
  selections: newSelections,
5351
+ snippetTabStops: changes.every(change => change.origin === EditorType || change.origin === EditorTypeWithAutoClosing) ? editor.snippetTabStops : undefined,
5346
5352
  undoStack
5347
5353
  };
5348
5354
  // Update link decorations after text changes
@@ -5405,7 +5411,8 @@ const scheduleDocumentAndCursorsSelectionIsUndo = async (editor, changes, select
5405
5411
  // undoStack: [...editor.undoStack.slice(0, -2)],
5406
5412
  invalidStartIndex,
5407
5413
  lines: newLines,
5408
- selections: newSelections
5414
+ selections: newSelections,
5415
+ snippetTabStops: undefined
5409
5416
  };
5410
5417
  const incrementalEdits = await getIncrementalEdits(editor, newEditor);
5411
5418
 
@@ -10191,18 +10198,20 @@ const cursorDocumentStart = editor => {
10191
10198
  return scheduleSelections(editor, newSelections);
10192
10199
  };
10193
10200
 
10194
- const moveSelectionDown = (lastRow, selections, i, selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn) => {
10195
- moveRangeToPosition$1(selections, i, Math.min(selectionEndRow + 1, lastRow), selectionEndColumn);
10201
+ const moveSelectionDown = (lastRow, lines, selections, i, selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn) => {
10202
+ const rowIndex = Math.min(selectionEndRow + 1, lastRow);
10203
+ const columnIndex = Math.min(selectionEndColumn, lines[rowIndex].length);
10204
+ moveRangeToPosition$1(selections, i, rowIndex, columnIndex);
10196
10205
  };
10197
- const getNewSelections$9 = (selections, lastRow) => {
10198
- return map(selections, moveSelectionDown.bind(null, lastRow));
10206
+ const getNewSelections$9 = (selections, lines) => {
10207
+ return map(selections, moveSelectionDown.bind(null, Math.max(0, lines.length - 1), lines));
10199
10208
  };
10200
10209
  const cursorDown = editor => {
10201
10210
  const {
10202
10211
  lines,
10203
10212
  selections
10204
10213
  } = editor;
10205
- const newSelections = getNewSelections$9(selections, Math.max(0, lines.length - 1));
10214
+ const newSelections = getNewSelections$9(selections, lines);
10206
10215
  return scheduleSelections(editor, newSelections);
10207
10216
  };
10208
10217
 
@@ -14615,24 +14624,38 @@ const getTabCompletion = async editor => {
14615
14624
  return completions;
14616
14625
  };
14617
14626
 
14627
+ const getSnippetLines = inserted => {
14628
+ return splitLines(inserted).map(line => {
14629
+ const tabStops = [];
14630
+ let text = '';
14631
+ for (let i = 0; i < line.length; i++) {
14632
+ if (line[i] === '$' && line[i + 1] >= '0' && line[i + 1] <= '9' && line[i - 1] !== '\\') {
14633
+ tabStops.push({
14634
+ index: Number(line[i + 1]),
14635
+ position: text.length
14636
+ });
14637
+ i++;
14638
+ } else {
14639
+ text += line[i];
14640
+ }
14641
+ }
14642
+ return {
14643
+ tabStops,
14644
+ text
14645
+ };
14646
+ });
14647
+ };
14618
14648
  const getSnippetChanges = (lines, selections, snippet) => {
14619
14649
  // TODO verify that deleted fits in the line
14620
- const insertedLines = splitLines(snippet.inserted);
14650
+ const parsedLines = getSnippetLines(snippet.inserted);
14651
+ const insertedLines = parsedLines.map(line => line.text);
14621
14652
  const changes = [];
14622
14653
  const selectionChanges = [];
14654
+ const tabStops = [];
14623
14655
  for (let i = 0; i < selections.length; i += 4) {
14624
14656
  const [selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn] = getSelectionPairs(selections, i);
14625
14657
  if (insertedLines.length > 1) {
14626
- let placeholderRow = -1;
14627
- let placeholderColumn = -1;
14628
- const insertedLinesWithoutPlaceholder = insertedLines.map((line, rowIndex) => {
14629
- const index = line.indexOf('$0');
14630
- if (index !== -1 && placeholderRow === -1) {
14631
- placeholderRow = rowIndex;
14632
- placeholderColumn = index;
14633
- }
14634
- return line.replace('$0', '');
14635
- });
14658
+ const insertedLinesWithoutPlaceholder = insertedLines;
14636
14659
  const line = getLine$1({
14637
14660
  lines
14638
14661
  }, selectionStartRow);
@@ -14653,32 +14676,45 @@ const getSnippetChanges = (lines, selections, snippet) => {
14653
14676
  }
14654
14677
  });
14655
14678
  const lastInsertedLine = insertedLines.at(-1);
14656
- if (placeholderRow === -1) {
14679
+ const stops = parsedLines.flatMap((line, rowIndex) => line.tabStops.map(stop => ({
14680
+ ...stop,
14681
+ rowIndex
14682
+ })));
14683
+ const initialStop = stops.find(stop => stop.index === 0) ?? stops.filter(stop => stop.index > 0).toSorted((a, b) => a.index - b.index)[0];
14684
+ if (initialStop) {
14685
+ const cursorRow = selectionStartRow + initialStop.rowIndex;
14686
+ const cursorColumn = initialStop.position + (initialStop.rowIndex === 0 ? selectionStartColumn - snippet.deleted : indent.length);
14687
+ selectionChanges.push(cursorRow, cursorColumn, cursorRow, cursorColumn);
14688
+ } else {
14657
14689
  selectionChanges.push(selectionEndRow + insertedLines.length - deleted.length,
14658
14690
  // @ts-ignore
14659
14691
  selectionEndColumn + lastInsertedLine.length, selectionEndRow + insertedLines.length - deleted.length,
14660
14692
  // @ts-ignore
14661
14693
  selectionEndColumn + lastInsertedLine.length);
14662
- } else {
14663
- const cursorRow = selectionStartRow + placeholderRow;
14664
- const cursorColumn = placeholderColumn + (placeholderRow === 0 ? selectionStartColumn - snippet.deleted : indent.length);
14665
- selectionChanges.push(cursorRow, cursorColumn, cursorRow, cursorColumn);
14694
+ }
14695
+ for (const stop of stops) {
14696
+ const columnIndex = stop.position + (stop.rowIndex === 0 ? selectionStartColumn - snippet.deleted : indent.length);
14697
+ tabStops.push({
14698
+ columnIndex,
14699
+ index: stop.index,
14700
+ rowIndex: selectionStartRow + stop.rowIndex
14701
+ });
14666
14702
  }
14667
14703
  } else {
14668
14704
  const line = insertedLines[0];
14669
- const placeholderIndex = line.indexOf('$0');
14670
- if (placeholderIndex === -1) {
14671
- const cursorColumnIndex = selectionStartColumn - snippet.deleted;
14672
- // @ts-ignore
14705
+ const stops = parsedLines[0].tabStops;
14706
+ const initialStop = stops.find(stop => stop.index === 0) ?? stops.filter(stop => stop.index > 0).toSorted((a, b) => a.index - b.index)[0];
14707
+ if (initialStop) {
14708
+ const inserted = line;
14709
+ const cursorColumnIndex = selectionStartColumn - snippet.deleted + initialStop.position;
14673
14710
  selectionChanges.push(selectionStartRow, cursorColumnIndex, selectionStartRow, cursorColumnIndex);
14674
- // @ts-ignore
14675
14711
  changes.push({
14676
14712
  deleted: [''],
14677
14713
  end: {
14678
14714
  columnIndex: selectionEndColumn,
14679
14715
  rowIndex: selectionEndRow
14680
14716
  },
14681
- inserted: insertedLines,
14717
+ inserted: [inserted],
14682
14718
  origin: EditorSnippet,
14683
14719
  start: {
14684
14720
  columnIndex: selectionStartColumn - snippet.deleted,
@@ -14686,16 +14722,17 @@ const getSnippetChanges = (lines, selections, snippet) => {
14686
14722
  }
14687
14723
  });
14688
14724
  } else {
14689
- const inserted = line.replace('$0', '');
14690
- const cursorColumnIndex = selectionStartColumn - snippet.deleted + placeholderIndex;
14725
+ const cursorColumnIndex = selectionStartColumn - snippet.deleted;
14726
+ // @ts-ignore
14691
14727
  selectionChanges.push(selectionStartRow, cursorColumnIndex, selectionStartRow, cursorColumnIndex);
14728
+ // @ts-ignore
14692
14729
  changes.push({
14693
14730
  deleted: [''],
14694
14731
  end: {
14695
14732
  columnIndex: selectionEndColumn,
14696
14733
  rowIndex: selectionEndRow
14697
14734
  },
14698
- inserted: [inserted],
14735
+ inserted: insertedLines,
14699
14736
  origin: EditorSnippet,
14700
14737
  start: {
14701
14738
  columnIndex: selectionStartColumn - snippet.deleted,
@@ -14703,18 +14740,26 @@ const getSnippetChanges = (lines, selections, snippet) => {
14703
14740
  }
14704
14741
  });
14705
14742
  }
14743
+ for (const stop of stops) {
14744
+ tabStops.push({
14745
+ columnIndex: selectionStartColumn - snippet.deleted + stop.position,
14746
+ index: stop.index,
14747
+ rowIndex: selectionStartRow
14748
+ });
14749
+ }
14706
14750
  }
14707
14751
  }
14708
14752
  return {
14709
14753
  changes,
14710
- selectionChanges: new Uint32Array(selectionChanges)
14754
+ selectionChanges: new Uint32Array(selectionChanges),
14755
+ tabStops
14711
14756
  };
14712
14757
  };
14713
14758
 
14714
14759
  // const getIndent =
14715
14760
  // TODO rename to insertSnippet
14716
14761
  // TODO handle snippet tabstops and cursors $0 -> becomes cursor
14717
- const editorSnippet = (editor, snippet) => {
14762
+ const editorSnippet = async (editor, snippet) => {
14718
14763
  // TODO verify that deleted fits in the line
14719
14764
  const {
14720
14765
  lines,
@@ -14722,9 +14767,27 @@ const editorSnippet = (editor, snippet) => {
14722
14767
  } = editor;
14723
14768
  const {
14724
14769
  changes,
14725
- selectionChanges
14770
+ selectionChanges,
14771
+ tabStops
14726
14772
  } = getSnippetChanges(lines, selections, snippet);
14727
- return scheduleDocumentAndCursorsSelections(editor, changes, selectionChanges);
14773
+ const newEditor = await scheduleDocumentAndCursorsSelections(editor, changes, selectionChanges);
14774
+ if (selections.length !== 4 || tabStops.length < 2) {
14775
+ return newEditor;
14776
+ }
14777
+ const initialStop = tabStops.find(stop => stop.index === 0) ?? tabStops.filter(stop => stop.index > 0).toSorted((a, b) => a.index - b.index)[0];
14778
+ const remainingStops = tabStops.filter(stop => stop !== initialStop && stop.index > 0).toSorted((a, b) => a.index - b.index).map(stop => ({
14779
+ offset: offsetAt(newEditor, stop.rowIndex, stop.columnIndex)
14780
+ }));
14781
+ if (remainingStops.length === 0) {
14782
+ return newEditor;
14783
+ }
14784
+ return {
14785
+ ...newEditor,
14786
+ snippetTabStops: {
14787
+ activeOffset: offsetAt(newEditor, initialStop.rowIndex, initialStop.columnIndex),
14788
+ stops: remainingStops
14789
+ }
14790
+ };
14728
14791
  };
14729
14792
 
14730
14793
  const getErrorMessage$1 = String;
@@ -14921,6 +14984,19 @@ const getBlockCommentEdits = (editor, blockComment) => {
14921
14984
  };
14922
14985
 
14923
14986
  const getLineComment = async editor => {
14987
+ try {
14988
+ const lineComment = await execute({
14989
+ args: [],
14990
+ editor,
14991
+ kind: 'comment',
14992
+ method: 'provideComment'
14993
+ });
14994
+ if (Array.isArray(lineComment) && lineComment[1] === '') {
14995
+ return lineComment[0];
14996
+ }
14997
+ } catch {
14998
+ // ignore
14999
+ }
14924
15000
  const languageConfiguration = await getLanguageConfiguration(editor);
14925
15001
  if (!languageConfiguration?.comments?.lineComment) {
14926
15002
  return undefined;
@@ -15231,7 +15307,7 @@ const typeWithAutoClosing = async (editor, text) => {
15231
15307
  switch (text) {
15232
15308
  // case AutoClosing.ClosingAngleBracket: // TODO support auto closing when typing closing angle bracket of start tag
15233
15309
  case Slash:
15234
- if (isAutoClosingTagsEnabled) {
15310
+ if (isAutoClosingTagsEnabled && isClosingTagSlash(editor)) {
15235
15311
  return typeWithAutoClosingTag(editor, text);
15236
15312
  }
15237
15313
  break;
@@ -15281,6 +15357,13 @@ const typeWithAutoClosing = async (editor, text) => {
15281
15357
  // TODO should editor type command know about editor completion? -> no
15282
15358
  // EditorCommandCompletion.openFromType(editor, text)
15283
15359
  };
15360
+ const isClosingTagSlash = editor => {
15361
+ const [startRow, startColumn, endRow, endColumn] = editor.selections;
15362
+ if (startRow !== endRow || startColumn !== endColumn || startColumn === 0) {
15363
+ return false;
15364
+ }
15365
+ return editor.lines[startRow][startColumn - 1] === '<';
15366
+ };
15284
15367
 
15285
15368
  const inverseChange = edit => {
15286
15369
  const insertedLines = edit.inserted;
@@ -17367,6 +17450,34 @@ const handleTab = async editor => {
17367
17450
  if (!isEverySelectionEmpty(editor.selections)) {
17368
17451
  return indentMore(editor);
17369
17452
  }
17453
+ if (editor.snippetTabStops) {
17454
+ const {
17455
+ activeOffset,
17456
+ stops
17457
+ } = editor.snippetTabStops;
17458
+ if (stops.length > 0 && editor.selections.length === 4) {
17459
+ const offset = offsetAt(editor, editor.selections[2], editor.selections[3]);
17460
+ const delta = offset - activeOffset;
17461
+ if (delta >= 0) {
17462
+ const [nextStop, ...remainingStops] = stops;
17463
+ const position = positionAt(editor, nextStop.offset + delta);
17464
+ const newEditor = scheduleSelections(editor, new Uint32Array([position.rowIndex, position.columnIndex, position.rowIndex, position.columnIndex]));
17465
+ return {
17466
+ ...newEditor,
17467
+ snippetTabStops: remainingStops.length > 0 ? {
17468
+ activeOffset: nextStop.offset + delta,
17469
+ stops: remainingStops.map(stop => ({
17470
+ offset: stop.offset + delta
17471
+ }))
17472
+ } : undefined
17473
+ };
17474
+ }
17475
+ }
17476
+ editor = {
17477
+ ...editor,
17478
+ snippetTabStops: undefined
17479
+ };
17480
+ }
17370
17481
  try {
17371
17482
  const result = await getTabCompletion(editor);
17372
17483
  if (!result) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.75.3",
3
+ "version": "19.75.5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"