@lvce-editor/editor-worker 19.75.4 → 19.75.6

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.
@@ -119,6 +119,7 @@ export interface EditorState {
119
119
  readonly fontFamily: string;
120
120
  readonly fontSize: number;
121
121
  readonly fontWeight: number;
122
+ readonly forceText?: boolean;
122
123
  readonly formatOnSave?: boolean;
123
124
  readonly gutterDecorations: readonly EditorGutterDecoration[];
124
125
  readonly gutterWidth: number;
package/dist/diff-sdk.js CHANGED
@@ -3815,8 +3815,9 @@ const invoke$b = async (method, ...args) => {
3815
3815
  const invoke$a = async (applicationId, method, ...args) => {
3816
3816
  return applicationId === undefined ? RendererWorker.invoke(method, ...args) : RendererWorker.invoke('Application.execute', applicationId, method, ...args);
3817
3817
  };
3818
- const readFile$1 = async (applicationId, uri) => {
3819
- return applicationId === undefined ? invoke$b('FileSystem.readFile', uri) : invoke$b('ApplicationFileSystem.execute', applicationId, 'readFile', uri);
3818
+ const readFile$1 = async (applicationId, uri, encoding) => {
3819
+ const args = encoding === undefined ? [uri] : [uri, encoding];
3820
+ return applicationId === undefined ? invoke$b('FileSystem.readFile', ...args) : invoke$b('ApplicationFileSystem.execute', applicationId, 'readFile', ...args);
3820
3821
  };
3821
3822
 
3822
3823
  const notifyTabModifiedStatusChange = async (uri, modified, applicationId) => {
@@ -4869,7 +4870,12 @@ const updateTransformedDiagnostics = async (editor, changes) => {
4869
4870
  return addDiagnostics(editor, diagnostics);
4870
4871
  };
4871
4872
  const scheduleSelections = (editor, selectionEdits) => {
4872
- return setSelections$2(editor, selectionEdits);
4873
+ return {
4874
+ ...setSelections$2(editor, selectionEdits),
4875
+ ...(editor.snippetTabStops && {
4876
+ snippetTabStops: undefined
4877
+ })
4878
+ };
4873
4879
  };
4874
4880
  const updateLines = (editor, lines) => {
4875
4881
  const newEditor = {
@@ -4930,6 +4936,7 @@ const scheduleDocumentAndCursorsSelections = async (editor, changes, selectionCh
4930
4936
  modified: true,
4931
4937
  redoStack: [],
4932
4938
  selections: newSelections,
4939
+ snippetTabStops: changes.every(change => change.origin === EditorType || change.origin === EditorTypeWithAutoClosing) ? editor.snippetTabStops : undefined,
4933
4940
  undoStack
4934
4941
  };
4935
4942
  // Update link decorations after text changes
@@ -4992,7 +4999,8 @@ const scheduleDocumentAndCursorsSelectionIsUndo = async (editor, changes, select
4992
4999
  // undoStack: [...editor.undoStack.slice(0, -2)],
4993
5000
  invalidStartIndex,
4994
5001
  lines: newLines,
4995
- selections: newSelections
5002
+ selections: newSelections,
5003
+ snippetTabStops: undefined
4996
5004
  };
4997
5005
  const incrementalEdits = await getIncrementalEdits(editor, newEditor);
4998
5006
 
@@ -6001,7 +6009,7 @@ const FocusFindWidgetToggleReplace = 42;
6001
6009
  const SourceActions = 38;
6002
6010
  const FocusCodeGenerator = 52;
6003
6011
 
6004
- const createEditor2 = (id, uri, x, y, width, height, platform, assetDir, _languageId, _tokenizePath, _useCache, applicationId, editorFileCacheEnabled = false) => {
6012
+ const createEditor2 = (id, uri, x, y, width, height, platform, assetDir, _languageId, _tokenizePath, _useCache, applicationId, editorFileCacheEnabled = false, forceText = false) => {
6005
6013
  number(id);
6006
6014
  const editor = {
6007
6015
  ...(applicationId !== undefined && {
@@ -6041,6 +6049,7 @@ const createEditor2 = (id, uri, x, y, width, height, platform, assetDir, _langua
6041
6049
  fontFamily: '',
6042
6050
  fontSize: 0,
6043
6051
  fontWeight: 0,
6052
+ forceText,
6044
6053
  gutterDecorations: [],
6045
6054
  gutterWidth: 0,
6046
6055
  handleOffset: 0,
@@ -14213,24 +14222,38 @@ const getTabCompletion = async editor => {
14213
14222
  return completions;
14214
14223
  };
14215
14224
 
14225
+ const getSnippetLines = inserted => {
14226
+ return splitLines$2(inserted).map(line => {
14227
+ const tabStops = [];
14228
+ let text = '';
14229
+ for (let i = 0; i < line.length; i++) {
14230
+ if (line[i] === '$' && line[i + 1] >= '0' && line[i + 1] <= '9' && line[i - 1] !== '\\') {
14231
+ tabStops.push({
14232
+ index: Number(line[i + 1]),
14233
+ position: text.length
14234
+ });
14235
+ i++;
14236
+ } else {
14237
+ text += line[i];
14238
+ }
14239
+ }
14240
+ return {
14241
+ tabStops,
14242
+ text
14243
+ };
14244
+ });
14245
+ };
14216
14246
  const getSnippetChanges = (lines, selections, snippet) => {
14217
14247
  // TODO verify that deleted fits in the line
14218
- const insertedLines = splitLines$2(snippet.inserted);
14248
+ const parsedLines = getSnippetLines(snippet.inserted);
14249
+ const insertedLines = parsedLines.map(line => line.text);
14219
14250
  const changes = [];
14220
14251
  const selectionChanges = [];
14252
+ const tabStops = [];
14221
14253
  for (let i = 0; i < selections.length; i += 4) {
14222
14254
  const [selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn] = getSelectionPairs(selections, i);
14223
14255
  if (insertedLines.length > 1) {
14224
- let placeholderRow = -1;
14225
- let placeholderColumn = -1;
14226
- const insertedLinesWithoutPlaceholder = insertedLines.map((line, rowIndex) => {
14227
- const index = line.indexOf('$0');
14228
- if (index !== -1 && placeholderRow === -1) {
14229
- placeholderRow = rowIndex;
14230
- placeholderColumn = index;
14231
- }
14232
- return line.replace('$0', '');
14233
- });
14256
+ const insertedLinesWithoutPlaceholder = insertedLines;
14234
14257
  const line = getLine$1({
14235
14258
  lines
14236
14259
  }, selectionStartRow);
@@ -14251,32 +14274,45 @@ const getSnippetChanges = (lines, selections, snippet) => {
14251
14274
  }
14252
14275
  });
14253
14276
  const lastInsertedLine = insertedLines.at(-1);
14254
- if (placeholderRow === -1) {
14277
+ const stops = parsedLines.flatMap((line, rowIndex) => line.tabStops.map(stop => ({
14278
+ ...stop,
14279
+ rowIndex
14280
+ })));
14281
+ const initialStop = stops.find(stop => stop.index === 0) ?? stops.filter(stop => stop.index > 0).toSorted((a, b) => a.index - b.index)[0];
14282
+ if (initialStop) {
14283
+ const cursorRow = selectionStartRow + initialStop.rowIndex;
14284
+ const cursorColumn = initialStop.position + (initialStop.rowIndex === 0 ? selectionStartColumn - snippet.deleted : indent.length);
14285
+ selectionChanges.push(cursorRow, cursorColumn, cursorRow, cursorColumn);
14286
+ } else {
14255
14287
  selectionChanges.push(selectionEndRow + insertedLines.length - deleted.length,
14256
14288
  // @ts-ignore
14257
14289
  selectionEndColumn + lastInsertedLine.length, selectionEndRow + insertedLines.length - deleted.length,
14258
14290
  // @ts-ignore
14259
14291
  selectionEndColumn + lastInsertedLine.length);
14260
- } else {
14261
- const cursorRow = selectionStartRow + placeholderRow;
14262
- const cursorColumn = placeholderColumn + (placeholderRow === 0 ? selectionStartColumn - snippet.deleted : indent.length);
14263
- selectionChanges.push(cursorRow, cursorColumn, cursorRow, cursorColumn);
14292
+ }
14293
+ for (const stop of stops) {
14294
+ const columnIndex = stop.position + (stop.rowIndex === 0 ? selectionStartColumn - snippet.deleted : indent.length);
14295
+ tabStops.push({
14296
+ columnIndex,
14297
+ index: stop.index,
14298
+ rowIndex: selectionStartRow + stop.rowIndex
14299
+ });
14264
14300
  }
14265
14301
  } else {
14266
14302
  const line = insertedLines[0];
14267
- const placeholderIndex = line.indexOf('$0');
14268
- if (placeholderIndex === -1) {
14269
- const cursorColumnIndex = selectionStartColumn - snippet.deleted;
14270
- // @ts-ignore
14303
+ const stops = parsedLines[0].tabStops;
14304
+ const initialStop = stops.find(stop => stop.index === 0) ?? stops.filter(stop => stop.index > 0).toSorted((a, b) => a.index - b.index)[0];
14305
+ if (initialStop) {
14306
+ const inserted = line;
14307
+ const cursorColumnIndex = selectionStartColumn - snippet.deleted + initialStop.position;
14271
14308
  selectionChanges.push(selectionStartRow, cursorColumnIndex, selectionStartRow, cursorColumnIndex);
14272
- // @ts-ignore
14273
14309
  changes.push({
14274
14310
  deleted: [''],
14275
14311
  end: {
14276
14312
  columnIndex: selectionEndColumn,
14277
14313
  rowIndex: selectionEndRow
14278
14314
  },
14279
- inserted: insertedLines,
14315
+ inserted: [inserted],
14280
14316
  origin: EditorSnippet,
14281
14317
  start: {
14282
14318
  columnIndex: selectionStartColumn - snippet.deleted,
@@ -14284,16 +14320,17 @@ const getSnippetChanges = (lines, selections, snippet) => {
14284
14320
  }
14285
14321
  });
14286
14322
  } else {
14287
- const inserted = line.replace('$0', '');
14288
- const cursorColumnIndex = selectionStartColumn - snippet.deleted + placeholderIndex;
14323
+ const cursorColumnIndex = selectionStartColumn - snippet.deleted;
14324
+ // @ts-ignore
14289
14325
  selectionChanges.push(selectionStartRow, cursorColumnIndex, selectionStartRow, cursorColumnIndex);
14326
+ // @ts-ignore
14290
14327
  changes.push({
14291
14328
  deleted: [''],
14292
14329
  end: {
14293
14330
  columnIndex: selectionEndColumn,
14294
14331
  rowIndex: selectionEndRow
14295
14332
  },
14296
- inserted: [inserted],
14333
+ inserted: insertedLines,
14297
14334
  origin: EditorSnippet,
14298
14335
  start: {
14299
14336
  columnIndex: selectionStartColumn - snippet.deleted,
@@ -14301,18 +14338,26 @@ const getSnippetChanges = (lines, selections, snippet) => {
14301
14338
  }
14302
14339
  });
14303
14340
  }
14341
+ for (const stop of stops) {
14342
+ tabStops.push({
14343
+ columnIndex: selectionStartColumn - snippet.deleted + stop.position,
14344
+ index: stop.index,
14345
+ rowIndex: selectionStartRow
14346
+ });
14347
+ }
14304
14348
  }
14305
14349
  }
14306
14350
  return {
14307
14351
  changes,
14308
- selectionChanges: new Uint32Array(selectionChanges)
14352
+ selectionChanges: new Uint32Array(selectionChanges),
14353
+ tabStops
14309
14354
  };
14310
14355
  };
14311
14356
 
14312
14357
  // const getIndent =
14313
14358
  // TODO rename to insertSnippet
14314
14359
  // TODO handle snippet tabstops and cursors $0 -> becomes cursor
14315
- const editorSnippet = (editor, snippet) => {
14360
+ const editorSnippet = async (editor, snippet) => {
14316
14361
  // TODO verify that deleted fits in the line
14317
14362
  const {
14318
14363
  lines,
@@ -14320,9 +14365,27 @@ const editorSnippet = (editor, snippet) => {
14320
14365
  } = editor;
14321
14366
  const {
14322
14367
  changes,
14323
- selectionChanges
14368
+ selectionChanges,
14369
+ tabStops
14324
14370
  } = getSnippetChanges(lines, selections, snippet);
14325
- return scheduleDocumentAndCursorsSelections(editor, changes, selectionChanges);
14371
+ const newEditor = await scheduleDocumentAndCursorsSelections(editor, changes, selectionChanges);
14372
+ if (selections.length !== 4 || tabStops.length < 2) {
14373
+ return newEditor;
14374
+ }
14375
+ const initialStop = tabStops.find(stop => stop.index === 0) ?? tabStops.filter(stop => stop.index > 0).toSorted((a, b) => a.index - b.index)[0];
14376
+ const remainingStops = tabStops.filter(stop => stop !== initialStop && stop.index > 0).toSorted((a, b) => a.index - b.index).map(stop => ({
14377
+ offset: offsetAt(newEditor, stop.rowIndex, stop.columnIndex)
14378
+ }));
14379
+ if (remainingStops.length === 0) {
14380
+ return newEditor;
14381
+ }
14382
+ return {
14383
+ ...newEditor,
14384
+ snippetTabStops: {
14385
+ activeOffset: offsetAt(newEditor, initialStop.rowIndex, initialStop.columnIndex),
14386
+ stops: remainingStops
14387
+ }
14388
+ };
14326
14389
  };
14327
14390
 
14328
14391
  const getErrorMessage$1 = String;
@@ -14519,6 +14582,20 @@ const getBlockCommentEdits = (editor, blockComment) => {
14519
14582
  };
14520
14583
 
14521
14584
  const getLineComment = async editor => {
14585
+ try {
14586
+ const offset = getOffsetAtCursor$1(editor);
14587
+ const lineComment = await execute({
14588
+ args: [offset],
14589
+ editor,
14590
+ kind: 'comment',
14591
+ method: 'provideComment'
14592
+ });
14593
+ if (Array.isArray(lineComment) && lineComment[1] === '') {
14594
+ return lineComment[0];
14595
+ }
14596
+ } catch {
14597
+ // ignore
14598
+ }
14522
14599
  const languageConfiguration = await getLanguageConfiguration(editor);
14523
14600
  if (!languageConfiguration?.comments?.lineComment) {
14524
14601
  return undefined;
@@ -16972,6 +17049,34 @@ const handleTab = async editor => {
16972
17049
  if (!isEverySelectionEmpty(editor.selections)) {
16973
17050
  return indentMore(editor);
16974
17051
  }
17052
+ if (editor.snippetTabStops) {
17053
+ const {
17054
+ activeOffset,
17055
+ stops
17056
+ } = editor.snippetTabStops;
17057
+ if (stops.length > 0 && editor.selections.length === 4) {
17058
+ const offset = offsetAt(editor, editor.selections[2], editor.selections[3]);
17059
+ const delta = offset - activeOffset;
17060
+ if (delta >= 0) {
17061
+ const [nextStop, ...remainingStops] = stops;
17062
+ const position = positionAt(editor, nextStop.offset + delta);
17063
+ const newEditor = scheduleSelections(editor, new Uint32Array([position.rowIndex, position.columnIndex, position.rowIndex, position.columnIndex]));
17064
+ return {
17065
+ ...newEditor,
17066
+ snippetTabStops: remainingStops.length > 0 ? {
17067
+ activeOffset: nextStop.offset + delta,
17068
+ stops: remainingStops.map(stop => ({
17069
+ offset: stop.offset + delta
17070
+ }))
17071
+ } : undefined
17072
+ };
17073
+ }
17074
+ }
17075
+ editor = {
17076
+ ...editor,
17077
+ snippetTabStops: undefined
17078
+ };
17079
+ }
16975
17080
  try {
16976
17081
  const result = await getTabCompletion(editor);
16977
17082
  if (!result) {
@@ -17205,9 +17310,12 @@ const isExcludedFromFileCache = uri => {
17205
17310
  const removeCachedEditorFile = (applicationId, uri) => {
17206
17311
  void invoke$a(undefined, 'CacheStorage.removeEditorFileCache', applicationId || '', uri).catch(() => {});
17207
17312
  };
17208
- const readFileWithCache = async (applicationId, uri, forceReload, useCache) => {
17313
+ const readFileWithCache = async (applicationId, uri, forceReload, useCache, forceText) => {
17209
17314
  if (!useCache) {
17210
- return readFile$1(applicationId, uri);
17315
+ return readFile$1(applicationId, uri, forceText ? 'binary' : undefined);
17316
+ }
17317
+ if (forceText) {
17318
+ return readFile$1(applicationId, uri, 'binary');
17211
17319
  }
17212
17320
  if (forceReload) {
17213
17321
  removeCachedEditorFile(applicationId, uri);
@@ -17245,9 +17353,12 @@ const readFileWithCache = async (applicationId, uri, forceReload, useCache) => {
17245
17353
  }
17246
17354
  return content;
17247
17355
  };
17248
- const readFile = (applicationId, uri, forceReload, useCache) => {
17356
+ const readFile = (applicationId, uri, forceReload, useCache, forceText) => {
17357
+ if (forceText) {
17358
+ return readFileWithCache(applicationId, uri, forceReload, useCache, forceText);
17359
+ }
17249
17360
  if (forceReload) {
17250
- return readFileWithCache(applicationId, uri, forceReload, useCache);
17361
+ return readFileWithCache(applicationId, uri, forceReload, useCache, forceText);
17251
17362
  }
17252
17363
  let applicationReads = pendingFileReads.get(applicationId);
17253
17364
  if (!applicationReads) {
@@ -17270,7 +17381,7 @@ const readFile = (applicationId, uri, forceReload, useCache) => {
17270
17381
  };
17271
17382
  fileRead = (async () => {
17272
17383
  try {
17273
- return await readFileWithCache(applicationId, uri, forceReload, useCache);
17384
+ return await readFileWithCache(applicationId, uri, forceReload, useCache, forceText);
17274
17385
  } finally {
17275
17386
  removePendingRead();
17276
17387
  }
@@ -17434,7 +17545,7 @@ const loadContent = async (state, savedState, largeFile = false, focus = true, f
17434
17545
  content = snapshot.lines.join('\n');
17435
17546
  endOfLine = snapshot.endOfLine === 'crlf' ? 'crlf' : 'lf';
17436
17547
  } else if (!existingEditor) {
17437
- content = await readFile(state.applicationId, uri, forceReload, state.editorFileCacheEnabled === true);
17548
+ content = await readFile(state.applicationId, uri, forceReload, state.editorFileCacheEnabled === true, state.forceText === true);
17438
17549
  endOfLine = getEndOfLine(content);
17439
17550
  content = normalizeLineEndings(content);
17440
17551
  }
@@ -4228,8 +4228,9 @@ const invoke$b = async (method, ...args) => {
4228
4228
  const invoke$a = async (applicationId, method, ...args) => {
4229
4229
  return applicationId === undefined ? invoke$e(method, ...args) : invoke$e('Application.execute', applicationId, method, ...args);
4230
4230
  };
4231
- const readFile$1 = async (applicationId, uri) => {
4232
- return applicationId === undefined ? invoke$b('FileSystem.readFile', uri) : invoke$b('ApplicationFileSystem.execute', applicationId, 'readFile', uri);
4231
+ const readFile$1 = async (applicationId, uri, encoding) => {
4232
+ const args = encoding === undefined ? [uri] : [uri, encoding];
4233
+ return applicationId === undefined ? invoke$b('FileSystem.readFile', ...args) : invoke$b('ApplicationFileSystem.execute', applicationId, 'readFile', ...args);
4233
4234
  };
4234
4235
 
4235
4236
  const notifyTabModifiedStatusChange = async (uri, modified, applicationId) => {
@@ -5282,7 +5283,12 @@ const updateTransformedDiagnostics = async (editor, changes) => {
5282
5283
  return addDiagnostics(editor, diagnostics);
5283
5284
  };
5284
5285
  const scheduleSelections = (editor, selectionEdits) => {
5285
- return setSelections$2(editor, selectionEdits);
5286
+ return {
5287
+ ...setSelections$2(editor, selectionEdits),
5288
+ ...(editor.snippetTabStops && {
5289
+ snippetTabStops: undefined
5290
+ })
5291
+ };
5286
5292
  };
5287
5293
  const updateLines = (editor, lines) => {
5288
5294
  const newEditor = {
@@ -5343,6 +5349,7 @@ const scheduleDocumentAndCursorsSelections = async (editor, changes, selectionCh
5343
5349
  modified: true,
5344
5350
  redoStack: [],
5345
5351
  selections: newSelections,
5352
+ snippetTabStops: changes.every(change => change.origin === EditorType || change.origin === EditorTypeWithAutoClosing) ? editor.snippetTabStops : undefined,
5346
5353
  undoStack
5347
5354
  };
5348
5355
  // Update link decorations after text changes
@@ -5405,7 +5412,8 @@ const scheduleDocumentAndCursorsSelectionIsUndo = async (editor, changes, select
5405
5412
  // undoStack: [...editor.undoStack.slice(0, -2)],
5406
5413
  invalidStartIndex,
5407
5414
  lines: newLines,
5408
- selections: newSelections
5415
+ selections: newSelections,
5416
+ snippetTabStops: undefined
5409
5417
  };
5410
5418
  const incrementalEdits = await getIncrementalEdits(editor, newEditor);
5411
5419
 
@@ -6414,7 +6422,7 @@ const FocusFindWidgetToggleReplace = 42;
6414
6422
  const SourceActions = 38;
6415
6423
  const FocusCodeGenerator = 52;
6416
6424
 
6417
- const createEditor2 = (id, uri, x, y, width, height, platform, assetDir, _languageId, _tokenizePath, _useCache, applicationId, editorFileCacheEnabled = false) => {
6425
+ const createEditor2 = (id, uri, x, y, width, height, platform, assetDir, _languageId, _tokenizePath, _useCache, applicationId, editorFileCacheEnabled = false, forceText = false) => {
6418
6426
  number(id);
6419
6427
  const editor = {
6420
6428
  ...(applicationId !== undefined && {
@@ -6454,6 +6462,7 @@ const createEditor2 = (id, uri, x, y, width, height, platform, assetDir, _langua
6454
6462
  fontFamily: '',
6455
6463
  fontSize: 0,
6456
6464
  fontWeight: 0,
6465
+ forceText,
6457
6466
  gutterDecorations: [],
6458
6467
  gutterWidth: 0,
6459
6468
  handleOffset: 0,
@@ -14617,24 +14626,38 @@ const getTabCompletion = async editor => {
14617
14626
  return completions;
14618
14627
  };
14619
14628
 
14629
+ const getSnippetLines = inserted => {
14630
+ return splitLines(inserted).map(line => {
14631
+ const tabStops = [];
14632
+ let text = '';
14633
+ for (let i = 0; i < line.length; i++) {
14634
+ if (line[i] === '$' && line[i + 1] >= '0' && line[i + 1] <= '9' && line[i - 1] !== '\\') {
14635
+ tabStops.push({
14636
+ index: Number(line[i + 1]),
14637
+ position: text.length
14638
+ });
14639
+ i++;
14640
+ } else {
14641
+ text += line[i];
14642
+ }
14643
+ }
14644
+ return {
14645
+ tabStops,
14646
+ text
14647
+ };
14648
+ });
14649
+ };
14620
14650
  const getSnippetChanges = (lines, selections, snippet) => {
14621
14651
  // TODO verify that deleted fits in the line
14622
- const insertedLines = splitLines(snippet.inserted);
14652
+ const parsedLines = getSnippetLines(snippet.inserted);
14653
+ const insertedLines = parsedLines.map(line => line.text);
14623
14654
  const changes = [];
14624
14655
  const selectionChanges = [];
14656
+ const tabStops = [];
14625
14657
  for (let i = 0; i < selections.length; i += 4) {
14626
14658
  const [selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn] = getSelectionPairs(selections, i);
14627
14659
  if (insertedLines.length > 1) {
14628
- let placeholderRow = -1;
14629
- let placeholderColumn = -1;
14630
- const insertedLinesWithoutPlaceholder = insertedLines.map((line, rowIndex) => {
14631
- const index = line.indexOf('$0');
14632
- if (index !== -1 && placeholderRow === -1) {
14633
- placeholderRow = rowIndex;
14634
- placeholderColumn = index;
14635
- }
14636
- return line.replace('$0', '');
14637
- });
14660
+ const insertedLinesWithoutPlaceholder = insertedLines;
14638
14661
  const line = getLine$1({
14639
14662
  lines
14640
14663
  }, selectionStartRow);
@@ -14655,32 +14678,45 @@ const getSnippetChanges = (lines, selections, snippet) => {
14655
14678
  }
14656
14679
  });
14657
14680
  const lastInsertedLine = insertedLines.at(-1);
14658
- if (placeholderRow === -1) {
14681
+ const stops = parsedLines.flatMap((line, rowIndex) => line.tabStops.map(stop => ({
14682
+ ...stop,
14683
+ rowIndex
14684
+ })));
14685
+ const initialStop = stops.find(stop => stop.index === 0) ?? stops.filter(stop => stop.index > 0).toSorted((a, b) => a.index - b.index)[0];
14686
+ if (initialStop) {
14687
+ const cursorRow = selectionStartRow + initialStop.rowIndex;
14688
+ const cursorColumn = initialStop.position + (initialStop.rowIndex === 0 ? selectionStartColumn - snippet.deleted : indent.length);
14689
+ selectionChanges.push(cursorRow, cursorColumn, cursorRow, cursorColumn);
14690
+ } else {
14659
14691
  selectionChanges.push(selectionEndRow + insertedLines.length - deleted.length,
14660
14692
  // @ts-ignore
14661
14693
  selectionEndColumn + lastInsertedLine.length, selectionEndRow + insertedLines.length - deleted.length,
14662
14694
  // @ts-ignore
14663
14695
  selectionEndColumn + lastInsertedLine.length);
14664
- } else {
14665
- const cursorRow = selectionStartRow + placeholderRow;
14666
- const cursorColumn = placeholderColumn + (placeholderRow === 0 ? selectionStartColumn - snippet.deleted : indent.length);
14667
- selectionChanges.push(cursorRow, cursorColumn, cursorRow, cursorColumn);
14696
+ }
14697
+ for (const stop of stops) {
14698
+ const columnIndex = stop.position + (stop.rowIndex === 0 ? selectionStartColumn - snippet.deleted : indent.length);
14699
+ tabStops.push({
14700
+ columnIndex,
14701
+ index: stop.index,
14702
+ rowIndex: selectionStartRow + stop.rowIndex
14703
+ });
14668
14704
  }
14669
14705
  } else {
14670
14706
  const line = insertedLines[0];
14671
- const placeholderIndex = line.indexOf('$0');
14672
- if (placeholderIndex === -1) {
14673
- const cursorColumnIndex = selectionStartColumn - snippet.deleted;
14674
- // @ts-ignore
14707
+ const stops = parsedLines[0].tabStops;
14708
+ const initialStop = stops.find(stop => stop.index === 0) ?? stops.filter(stop => stop.index > 0).toSorted((a, b) => a.index - b.index)[0];
14709
+ if (initialStop) {
14710
+ const inserted = line;
14711
+ const cursorColumnIndex = selectionStartColumn - snippet.deleted + initialStop.position;
14675
14712
  selectionChanges.push(selectionStartRow, cursorColumnIndex, selectionStartRow, cursorColumnIndex);
14676
- // @ts-ignore
14677
14713
  changes.push({
14678
14714
  deleted: [''],
14679
14715
  end: {
14680
14716
  columnIndex: selectionEndColumn,
14681
14717
  rowIndex: selectionEndRow
14682
14718
  },
14683
- inserted: insertedLines,
14719
+ inserted: [inserted],
14684
14720
  origin: EditorSnippet,
14685
14721
  start: {
14686
14722
  columnIndex: selectionStartColumn - snippet.deleted,
@@ -14688,16 +14724,17 @@ const getSnippetChanges = (lines, selections, snippet) => {
14688
14724
  }
14689
14725
  });
14690
14726
  } else {
14691
- const inserted = line.replace('$0', '');
14692
- const cursorColumnIndex = selectionStartColumn - snippet.deleted + placeholderIndex;
14727
+ const cursorColumnIndex = selectionStartColumn - snippet.deleted;
14728
+ // @ts-ignore
14693
14729
  selectionChanges.push(selectionStartRow, cursorColumnIndex, selectionStartRow, cursorColumnIndex);
14730
+ // @ts-ignore
14694
14731
  changes.push({
14695
14732
  deleted: [''],
14696
14733
  end: {
14697
14734
  columnIndex: selectionEndColumn,
14698
14735
  rowIndex: selectionEndRow
14699
14736
  },
14700
- inserted: [inserted],
14737
+ inserted: insertedLines,
14701
14738
  origin: EditorSnippet,
14702
14739
  start: {
14703
14740
  columnIndex: selectionStartColumn - snippet.deleted,
@@ -14705,18 +14742,26 @@ const getSnippetChanges = (lines, selections, snippet) => {
14705
14742
  }
14706
14743
  });
14707
14744
  }
14745
+ for (const stop of stops) {
14746
+ tabStops.push({
14747
+ columnIndex: selectionStartColumn - snippet.deleted + stop.position,
14748
+ index: stop.index,
14749
+ rowIndex: selectionStartRow
14750
+ });
14751
+ }
14708
14752
  }
14709
14753
  }
14710
14754
  return {
14711
14755
  changes,
14712
- selectionChanges: new Uint32Array(selectionChanges)
14756
+ selectionChanges: new Uint32Array(selectionChanges),
14757
+ tabStops
14713
14758
  };
14714
14759
  };
14715
14760
 
14716
14761
  // const getIndent =
14717
14762
  // TODO rename to insertSnippet
14718
14763
  // TODO handle snippet tabstops and cursors $0 -> becomes cursor
14719
- const editorSnippet = (editor, snippet) => {
14764
+ const editorSnippet = async (editor, snippet) => {
14720
14765
  // TODO verify that deleted fits in the line
14721
14766
  const {
14722
14767
  lines,
@@ -14724,9 +14769,27 @@ const editorSnippet = (editor, snippet) => {
14724
14769
  } = editor;
14725
14770
  const {
14726
14771
  changes,
14727
- selectionChanges
14772
+ selectionChanges,
14773
+ tabStops
14728
14774
  } = getSnippetChanges(lines, selections, snippet);
14729
- return scheduleDocumentAndCursorsSelections(editor, changes, selectionChanges);
14775
+ const newEditor = await scheduleDocumentAndCursorsSelections(editor, changes, selectionChanges);
14776
+ if (selections.length !== 4 || tabStops.length < 2) {
14777
+ return newEditor;
14778
+ }
14779
+ const initialStop = tabStops.find(stop => stop.index === 0) ?? tabStops.filter(stop => stop.index > 0).toSorted((a, b) => a.index - b.index)[0];
14780
+ const remainingStops = tabStops.filter(stop => stop !== initialStop && stop.index > 0).toSorted((a, b) => a.index - b.index).map(stop => ({
14781
+ offset: offsetAt(newEditor, stop.rowIndex, stop.columnIndex)
14782
+ }));
14783
+ if (remainingStops.length === 0) {
14784
+ return newEditor;
14785
+ }
14786
+ return {
14787
+ ...newEditor,
14788
+ snippetTabStops: {
14789
+ activeOffset: offsetAt(newEditor, initialStop.rowIndex, initialStop.columnIndex),
14790
+ stops: remainingStops
14791
+ }
14792
+ };
14730
14793
  };
14731
14794
 
14732
14795
  const getErrorMessage$1 = String;
@@ -14923,6 +14986,20 @@ const getBlockCommentEdits = (editor, blockComment) => {
14923
14986
  };
14924
14987
 
14925
14988
  const getLineComment = async editor => {
14989
+ try {
14990
+ const offset = getOffsetAtCursor$1(editor);
14991
+ const lineComment = await execute({
14992
+ args: [offset],
14993
+ editor,
14994
+ kind: 'comment',
14995
+ method: 'provideComment'
14996
+ });
14997
+ if (Array.isArray(lineComment) && lineComment[1] === '') {
14998
+ return lineComment[0];
14999
+ }
15000
+ } catch {
15001
+ // ignore
15002
+ }
14926
15003
  const languageConfiguration = await getLanguageConfiguration(editor);
14927
15004
  if (!languageConfiguration?.comments?.lineComment) {
14928
15005
  return undefined;
@@ -17376,6 +17453,34 @@ const handleTab = async editor => {
17376
17453
  if (!isEverySelectionEmpty(editor.selections)) {
17377
17454
  return indentMore(editor);
17378
17455
  }
17456
+ if (editor.snippetTabStops) {
17457
+ const {
17458
+ activeOffset,
17459
+ stops
17460
+ } = editor.snippetTabStops;
17461
+ if (stops.length > 0 && editor.selections.length === 4) {
17462
+ const offset = offsetAt(editor, editor.selections[2], editor.selections[3]);
17463
+ const delta = offset - activeOffset;
17464
+ if (delta >= 0) {
17465
+ const [nextStop, ...remainingStops] = stops;
17466
+ const position = positionAt(editor, nextStop.offset + delta);
17467
+ const newEditor = scheduleSelections(editor, new Uint32Array([position.rowIndex, position.columnIndex, position.rowIndex, position.columnIndex]));
17468
+ return {
17469
+ ...newEditor,
17470
+ snippetTabStops: remainingStops.length > 0 ? {
17471
+ activeOffset: nextStop.offset + delta,
17472
+ stops: remainingStops.map(stop => ({
17473
+ offset: stop.offset + delta
17474
+ }))
17475
+ } : undefined
17476
+ };
17477
+ }
17478
+ }
17479
+ editor = {
17480
+ ...editor,
17481
+ snippetTabStops: undefined
17482
+ };
17483
+ }
17379
17484
  try {
17380
17485
  const result = await getTabCompletion(editor);
17381
17486
  if (!result) {
@@ -17609,9 +17714,12 @@ const isExcludedFromFileCache = uri => {
17609
17714
  const removeCachedEditorFile = (applicationId, uri) => {
17610
17715
  void invoke$a(undefined, 'CacheStorage.removeEditorFileCache', applicationId || '', uri).catch(() => {});
17611
17716
  };
17612
- const readFileWithCache = async (applicationId, uri, forceReload, useCache) => {
17717
+ const readFileWithCache = async (applicationId, uri, forceReload, useCache, forceText) => {
17613
17718
  if (!useCache) {
17614
- return readFile$1(applicationId, uri);
17719
+ return readFile$1(applicationId, uri, forceText ? 'binary' : undefined);
17720
+ }
17721
+ if (forceText) {
17722
+ return readFile$1(applicationId, uri, 'binary');
17615
17723
  }
17616
17724
  if (forceReload) {
17617
17725
  removeCachedEditorFile(applicationId, uri);
@@ -17649,9 +17757,12 @@ const readFileWithCache = async (applicationId, uri, forceReload, useCache) => {
17649
17757
  }
17650
17758
  return content;
17651
17759
  };
17652
- const readFile = (applicationId, uri, forceReload, useCache) => {
17760
+ const readFile = (applicationId, uri, forceReload, useCache, forceText) => {
17761
+ if (forceText) {
17762
+ return readFileWithCache(applicationId, uri, forceReload, useCache, forceText);
17763
+ }
17653
17764
  if (forceReload) {
17654
- return readFileWithCache(applicationId, uri, forceReload, useCache);
17765
+ return readFileWithCache(applicationId, uri, forceReload, useCache, forceText);
17655
17766
  }
17656
17767
  let applicationReads = pendingFileReads.get(applicationId);
17657
17768
  if (!applicationReads) {
@@ -17674,7 +17785,7 @@ const readFile = (applicationId, uri, forceReload, useCache) => {
17674
17785
  };
17675
17786
  fileRead = (async () => {
17676
17787
  try {
17677
- return await readFileWithCache(applicationId, uri, forceReload, useCache);
17788
+ return await readFileWithCache(applicationId, uri, forceReload, useCache, forceText);
17678
17789
  } finally {
17679
17790
  removePendingRead();
17680
17791
  }
@@ -17838,7 +17949,7 @@ const loadContent = async (state, savedState, largeFile = false, focus = true, f
17838
17949
  content = snapshot.lines.join('\n');
17839
17950
  endOfLine = snapshot.endOfLine === 'crlf' ? 'crlf' : 'lf';
17840
17951
  } else if (!existingEditor) {
17841
- content = await readFile(state.applicationId, uri, forceReload, state.editorFileCacheEnabled === true);
17952
+ content = await readFile(state.applicationId, uri, forceReload, state.editorFileCacheEnabled === true, state.forceText === true);
17842
17953
  endOfLine = getEndOfLine(content);
17843
17954
  content = normalizeLineEndings(content);
17844
17955
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.75.4",
3
+ "version": "19.75.6",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"