@lvce-editor/editor-worker 19.20.0 → 19.21.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.
@@ -4158,6 +4158,10 @@ const getLanguageByFileName = (languages, fileNameLower) => {
4158
4158
  }
4159
4159
  return '';
4160
4160
  };
4161
+ const getFileName = uri => {
4162
+ const slashIndex = Math.max(uri.lastIndexOf('/'), uri.lastIndexOf('\\'));
4163
+ return uri.slice(slashIndex + 1);
4164
+ };
4161
4165
  const getLanguageId$1 = (uri, languages) => {
4162
4166
  string(uri);
4163
4167
  // TODO this is inefficient for icon theme, as file extension is computed twice
@@ -4170,7 +4174,7 @@ const getLanguageId$1 = (uri, languages) => {
4170
4174
  if (candidate1) {
4171
4175
  return candidate1;
4172
4176
  }
4173
- const fileNameLower = uri.toLowerCase();
4177
+ const fileNameLower = getFileName(uri).toLowerCase();
4174
4178
  const secondExtensionIndex = getNthFileExtension(uri, extensionIndex - 1);
4175
4179
  const secondExtension = uri.slice(secondExtensionIndex);
4176
4180
  const candidate2 = getLanguageByExtension(languages, secondExtension);
@@ -5235,20 +5239,28 @@ const handleBlur$1 = async editor => {
5235
5239
 
5236
5240
  const replaceRange = (editor, ranges, replacement, origin) => {
5237
5241
  const changes = [];
5242
+ const columnDeltas = new Map();
5238
5243
  const rangesLength = ranges.length;
5239
5244
  for (let i = 0; i < rangesLength; i += 4) {
5240
5245
  const [selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn] = getSelectionPairs(ranges, i);
5246
+ const columnDelta = selectionStartRow === selectionEndRow ? columnDeltas.get(selectionStartRow) ?? 0 : 0;
5241
5247
  const start = {
5242
- columnIndex: selectionStartColumn,
5248
+ columnIndex: selectionStartColumn + columnDelta,
5243
5249
  rowIndex: selectionStartRow
5244
5250
  };
5245
5251
  const end = {
5246
- columnIndex: selectionEndColumn,
5252
+ columnIndex: selectionEndColumn + columnDelta,
5247
5253
  rowIndex: selectionEndRow
5248
5254
  };
5249
5255
  const selection = {
5250
- end,
5251
- start
5256
+ end: {
5257
+ columnIndex: selectionEndColumn,
5258
+ rowIndex: selectionEndRow
5259
+ },
5260
+ start: {
5261
+ columnIndex: selectionStartColumn,
5262
+ rowIndex: selectionStartRow
5263
+ }
5252
5264
  };
5253
5265
  changes.push({
5254
5266
  deleted: getSelectionText(editor, selection),
@@ -5257,6 +5269,14 @@ const replaceRange = (editor, ranges, replacement, origin) => {
5257
5269
  origin,
5258
5270
  start: start
5259
5271
  });
5272
+ if (selectionStartRow === selectionEndRow) {
5273
+ if (replacement.length <= 1) {
5274
+ const insertedLength = replacement[0]?.length ?? 0;
5275
+ columnDeltas.set(selectionStartRow, columnDelta + insertedLength - (selectionEndColumn - selectionStartColumn));
5276
+ } else {
5277
+ columnDeltas.set(selectionStartRow, replacement.at(-1).length - selectionEndColumn);
5278
+ }
5279
+ }
5260
5280
  }
5261
5281
  return changes;
5262
5282
  };
@@ -7573,6 +7593,15 @@ const handleTouchMove = (editor, touchEvent) => {
7573
7593
  setDeltaYFixedValue(editor, offsetY);
7574
7594
  };
7575
7595
 
7596
+ const handleUriChange = async (editor, newUri) => {
7597
+ const content = getText$1(editor);
7598
+ await invoke$6(TextDocumentSyncFull, newUri, editor.id, editor.languageId, content);
7599
+ return {
7600
+ ...editor,
7601
+ uri: newUri
7602
+ };
7603
+ };
7604
+
7576
7605
  // Keep wheel handling as a dedicated command entry point and delegate
7577
7606
  // the actual scroll state update to the shared setDelta logic.
7578
7607
  // @ts-ignore
@@ -8387,9 +8416,7 @@ const selectionGrow = async editor => {
8387
8416
 
8388
8417
  const getSelectionEditsSingleLineWord = (lines, selections) => {
8389
8418
  const lastSelectionIndex = selections.length - 4;
8390
- const rowIndex = selections[lastSelectionIndex];
8391
- const lastSelectionStartColumnIndex = selections[lastSelectionIndex + 1];
8392
- const lastSelectionEndColumnIndex = selections[lastSelectionIndex + 3];
8419
+ const [rowIndex, lastSelectionStartColumnIndex,, lastSelectionEndColumnIndex] = getSelectionPairs(selections, lastSelectionIndex);
8393
8420
  const line = lines[rowIndex];
8394
8421
  const word = line.slice(lastSelectionStartColumnIndex, lastSelectionEndColumnIndex);
8395
8422
  const columnIndexAfter = line.indexOf(word, lastSelectionEndColumnIndex);
@@ -12811,6 +12838,7 @@ const commandMap = {
12811
12838
  'Editor.handleTouchMove': wrapCommand(handleTouchMove),
12812
12839
  'Editor.handleTouchStart': wrapCommand(handleTouchStart),
12813
12840
  'Editor.handleTripleClick': wrapCommand(handleTripleClick),
12841
+ 'Editor.handleUriChange': wrapCommand(handleUriChange),
12814
12842
  'Editor.handleWheel': wrapCommand(handleWheel$2),
12815
12843
  'Editor.hotReload': hotReload,
12816
12844
  'Editor.indendLess': wrapCommand(indentLess),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.20.0",
3
+ "version": "19.21.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"