@lvce-editor/editor-worker 19.46.0 → 19.47.1

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.
@@ -1151,7 +1151,7 @@ const createMockRpc = ({
1151
1151
  };
1152
1152
 
1153
1153
  const rpcs = Object.create(null);
1154
- const set$g = (id, rpc) => {
1154
+ const set$h = (id, rpc) => {
1155
1155
  rpcs[id] = rpc;
1156
1156
  };
1157
1157
  const get$9 = id => {
@@ -1184,7 +1184,7 @@ const create$a = rpcId => {
1184
1184
  const mockRpc = createMockRpc({
1185
1185
  commandMap
1186
1186
  });
1187
- set$g(rpcId, mockRpc);
1187
+ set$h(rpcId, mockRpc);
1188
1188
  // @ts-ignore
1189
1189
  mockRpc[Symbol.dispose] = () => {
1190
1190
  remove$8(rpcId);
@@ -1193,7 +1193,7 @@ const create$a = rpcId => {
1193
1193
  return mockRpc;
1194
1194
  },
1195
1195
  set(rpc) {
1196
- set$g(rpcId, rpc);
1196
+ set$h(rpcId, rpc);
1197
1197
  }
1198
1198
  };
1199
1199
  };
@@ -1439,6 +1439,7 @@ const Electron = 2;
1439
1439
  const CompletionWorker = 301;
1440
1440
  const DebugWorker = 55;
1441
1441
  const DialogWorker = 7014;
1442
+ const DragAndDropWorker = 3404;
1442
1443
  const EditorWorker = 99;
1443
1444
  const ErrorWorker = 3308;
1444
1445
  const ExtensionManagementWorker = 9006;
@@ -1454,10 +1455,15 @@ const SetPatches = 'Viewlet.setPatches';
1454
1455
 
1455
1456
  const FocusEditorText$1 = 12;
1456
1457
 
1458
+ const {
1459
+ invoke: invoke$g,
1460
+ set: set$g
1461
+ } = create$a(DialogWorker);
1462
+
1457
1463
  const {
1458
1464
  invoke: invoke$f,
1459
1465
  set: set$f
1460
- } = create$a(DialogWorker);
1466
+ } = create$a(DragAndDropWorker);
1461
1467
 
1462
1468
  const {
1463
1469
  invoke: invoke$e,
@@ -1485,7 +1491,7 @@ const createLazyRpc = rpcId => {
1485
1491
  throw new Error('Lazy RPC launch was superseded');
1486
1492
  }
1487
1493
  activeRpc = rpc;
1488
- set$g(rpcId, rpc);
1494
+ set$h(rpcId, rpc);
1489
1495
  return rpc;
1490
1496
  };
1491
1497
  const ensureRpc = async () => {
@@ -1570,6 +1576,10 @@ const showContextMenu2 = async (uid, menuId, x, y, args) => {
1570
1576
  number(y);
1571
1577
  await invoke$a('ContextMenu.show2', uid, menuId, x, y, args);
1572
1578
  };
1579
+ const sendMessagePortToDragAndDropWorker = async port => {
1580
+ const command = 'DragAndDrop.handleMessagePort';
1581
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToDragAndDropWorker', port, command);
1582
+ };
1573
1583
  const sendMessagePortToOpenerWorker = async (port, rpcId) => {
1574
1584
  const command = 'HandleMessagePort.handleMessagePort';
1575
1585
  await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToOpenerWorker', port, command, rpcId);
@@ -1940,6 +1950,7 @@ const EditorPasteText = 'editorPasteText';
1940
1950
  const EditorSnippet = 'editorSnippet';
1941
1951
  const EditorType = 'editorType';
1942
1952
  const EditorTypeWithAutoClosing = 'editorTypeWithAutoClosing';
1953
+ const EditorTextDrag = 'editorTextDrag';
1943
1954
  const Format = 'format';
1944
1955
  const IndentLess = 'indentLess';
1945
1956
  const IndentMore = 'indentMore';
@@ -3363,6 +3374,7 @@ const HAS_SCHEME_PATTERN = /^(?:https?|ftp|ftps|file):\/\//;
3363
3374
 
3364
3375
  // Regex to check if URL starts with www.
3365
3376
  const HAS_WWW_PATTERN = /^www\./;
3377
+ const TEMPLATE_EXPRESSION_START = '${';
3366
3378
  const TRAILING_SENTENCE_PUNCTUATION = '.,;:!?';
3367
3379
  const OPENING_DELIMITER_MAP = {
3368
3380
  ')': '(',
@@ -3412,8 +3424,8 @@ const detectLinks = text => {
3412
3424
  const links = [];
3413
3425
  for (const match of matches) {
3414
3426
  const url = trimTrailingPunctuation(match[0]);
3415
- // Only consider as link if it has a scheme or starts with www.
3416
- if (HAS_SCHEME_PATTERN.test(url) || HAS_WWW_PATTERN.test(url)) {
3427
+ // Only consider static links with a scheme or www prefix.
3428
+ if (!url.includes(TEMPLATE_EXPRESSION_START) && (HAS_SCHEME_PATTERN.test(url) || HAS_WWW_PATTERN.test(url))) {
3417
3429
  links.push({
3418
3430
  length: url.length,
3419
3431
  start: match.index ?? 0
@@ -5009,6 +5021,7 @@ const createEditor2 = (id, uri, x, y, width, height, platform, assetDir) => {
5009
5021
  diagnosticsEnabled: false,
5010
5022
  differences: [],
5011
5023
  documentSymbols: [],
5024
+ dragAndDropEnabled: true,
5012
5025
  embeds: [],
5013
5026
  endOfLine: 'lf',
5014
5027
  endOfLineDecorations: [],
@@ -5077,6 +5090,11 @@ const createEditor2 = (id, uri, x, y, width, height, platform, assetDir) => {
5077
5090
  selectionInfos: [],
5078
5091
  selections: new Uint32Array(),
5079
5092
  tabSize: 0,
5093
+ textDragDropPosition: {
5094
+ columnIndex: 0,
5095
+ rowIndex: 0
5096
+ },
5097
+ textDragId: 0,
5080
5098
  textInfos: [],
5081
5099
  tokenizerId: 0,
5082
5100
  uid: id,
@@ -5107,6 +5125,7 @@ const emptyEditor = {
5107
5125
  diagnostics: [],
5108
5126
  differences: [],
5109
5127
  documentSymbols: [],
5128
+ dragAndDropEnabled: true,
5110
5129
  embeds: [],
5111
5130
  endOfLine: 'lf',
5112
5131
  endOfLineDecorations: [],
@@ -5143,6 +5162,11 @@ const emptyEditor = {
5143
5162
  },
5144
5163
  selectionInfos: [],
5145
5164
  selections: new Uint32Array(),
5165
+ textDragDropPosition: {
5166
+ columnIndex: 0,
5167
+ rowIndex: 0
5168
+ },
5169
+ textDragId: 0,
5146
5170
  textInfos: [],
5147
5171
  tokenizerId: 0,
5148
5172
  undoStack: [],
@@ -5297,6 +5321,7 @@ const createEditor = async ({
5297
5321
  diagnostics: [],
5298
5322
  diagnosticsEnabled,
5299
5323
  differences: [],
5324
+ dragAndDropEnabled: true,
5300
5325
  endOfLine: getEndOfLine(content),
5301
5326
  endOfLineDecorations: [],
5302
5327
  finalDeltaY: 0,
@@ -5354,6 +5379,11 @@ const createEditor = async ({
5354
5379
  selectionInfos: [],
5355
5380
  selections: new Uint32Array(),
5356
5381
  tabSize,
5382
+ textDragDropPosition: {
5383
+ columnIndex: 0,
5384
+ rowIndex: 0
5385
+ },
5386
+ textDragId: 0,
5357
5387
  textInfos: [],
5358
5388
  tokenizerId: 0,
5359
5389
  uid: id,
@@ -6216,7 +6246,7 @@ const isPermissionDeniedError = error => {
6216
6246
  };
6217
6247
  const showSaveErrorDialog = async error => {
6218
6248
  if (isPermissionDeniedError(error)) {
6219
- await invoke$f('ElectronDialog.showMessageBox', {
6249
+ await invoke$g('ElectronDialog.showMessageBox', {
6220
6250
  buttons: ['OK'],
6221
6251
  defaultId: 0,
6222
6252
  message: "You don't have permission to save changes to this file.",
@@ -6225,7 +6255,7 @@ const showSaveErrorDialog = async error => {
6225
6255
  });
6226
6256
  return;
6227
6257
  }
6228
- await invoke$f('ElectronDialog.showMessageBox', {
6258
+ await invoke$g('ElectronDialog.showMessageBox', {
6229
6259
  buttons: ['OK'],
6230
6260
  defaultId: 0,
6231
6261
  detail: error.message,
@@ -8682,13 +8712,50 @@ const handleSecondaryMouseDown = async (state, x, y) => {
8682
8712
  }
8683
8713
  return handleClickAtPosition(state, 0, position.rowIndex, position.columnIndex);
8684
8714
  };
8685
- const handleMouseDown = async (state, button, altKey, ctrlKey, x, y, detail) => {
8715
+ const startTextDrag = async (state, x, y) => {
8716
+ const position = await at(state, x, y);
8717
+ const selectionIndex = state.primarySelectionIndex || 0;
8718
+ const [startRowIndex, startColumnIndex, endRowIndex, endColumnIndex] = getSelectionPairs(state.selections, selectionIndex);
8719
+ const startOffset = offsetAt(state, startRowIndex, startColumnIndex);
8720
+ const endOffset = offsetAt(state, endRowIndex, endColumnIndex);
8721
+ const pointerOffset = offsetAt(state, position.rowIndex, position.columnIndex);
8722
+ if (startOffset === endOffset || pointerOffset < startOffset || pointerOffset >= endOffset) {
8723
+ return undefined;
8724
+ }
8725
+ try {
8726
+ if (state.textDragId) {
8727
+ await invoke$f('DragAndDrop.discardTextDrag', state.textDragId);
8728
+ }
8729
+ const text = getText$1(state).slice(startOffset, endOffset);
8730
+ const textDragId = await invoke$f('DragAndDrop.createTextDrag', {
8731
+ endOffset,
8732
+ sourceUri: state.uri,
8733
+ startOffset,
8734
+ text
8735
+ });
8736
+ return {
8737
+ ...state,
8738
+ isSelecting: false,
8739
+ textDragDropPosition: position,
8740
+ textDragId
8741
+ };
8742
+ } catch {
8743
+ return undefined;
8744
+ }
8745
+ };
8746
+ const handleMouseDown = async (state, button, altKey, ctrlKey, x, y, detail, shiftKey = false) => {
8686
8747
  if (button === SecondaryButton) {
8687
8748
  return handleSecondaryMouseDown(state, x, y);
8688
8749
  }
8689
8750
  if (button !== PrimaryButton) {
8690
8751
  return state;
8691
8752
  }
8753
+ if (shiftKey && state.dragAndDropEnabled && detail === Single) {
8754
+ const dragState = await startTextDrag(state, x, y);
8755
+ if (dragState) {
8756
+ return dragState;
8757
+ }
8758
+ }
8692
8759
  const modifier = getModifier(altKey, ctrlKey);
8693
8760
  let newState;
8694
8761
  switch (detail) {
@@ -9220,7 +9287,14 @@ const editorHandleNativeSelectionChange = (editor, range) => {
9220
9287
  };
9221
9288
 
9222
9289
  // @ts-ignore
9223
- const handlePointerCaptureLost = editor => {
9290
+ const handlePointerCaptureLost = async editor => {
9291
+ if (editor.textDragId) {
9292
+ try {
9293
+ await invoke$f('DragAndDrop.discardTextDrag', editor.textDragId);
9294
+ } catch {
9295
+ // The pointer state still needs to be reset if the worker is unavailable.
9296
+ }
9297
+ }
9224
9298
  return {
9225
9299
  ...editor,
9226
9300
  hasListener: false,
@@ -9228,7 +9302,12 @@ const handlePointerCaptureLost = editor => {
9228
9302
  selectionAutoMovePosition: {
9229
9303
  columnIndex: 0,
9230
9304
  rowIndex: 0
9231
- }
9305
+ },
9306
+ textDragDropPosition: {
9307
+ columnIndex: 0,
9308
+ rowIndex: 0
9309
+ },
9310
+ textDragId: 0
9232
9311
  };
9233
9312
  };
9234
9313
 
@@ -9425,6 +9504,13 @@ const moveSelectionPx = async (editor, x, y) => {
9425
9504
  };
9426
9505
 
9427
9506
  const handlePointerMove = async (editor, x, y, altKey) => {
9507
+ if (editor.textDragId) {
9508
+ const textDragDropPosition = await at(editor, x, y);
9509
+ return {
9510
+ ...editor,
9511
+ textDragDropPosition
9512
+ };
9513
+ }
9428
9514
  if (!editor.isSelecting) {
9429
9515
  return editor;
9430
9516
  }
@@ -9434,16 +9520,84 @@ const handlePointerMove = async (editor, x, y, altKey) => {
9434
9520
  return moveSelectionPx(editor, x, y);
9435
9521
  };
9436
9522
 
9437
- const handlePointerUp = editor => {
9523
+ const getSelection = (lines, startOffset, endOffset) => {
9524
+ const start = positionAt({
9525
+ lines
9526
+ }, startOffset);
9527
+ const end = positionAt({
9528
+ lines
9529
+ }, endOffset);
9530
+ return new Uint32Array([start.rowIndex, start.columnIndex, end.rowIndex, end.columnIndex]);
9531
+ };
9532
+ const getTextDragEdit = (editor, data, target, origin) => {
9533
+ const documentText = getText$1(editor);
9534
+ const targetOffset = offsetAt(editor, target.rowIndex, target.columnIndex);
9535
+ const {
9536
+ endOffset,
9537
+ startOffset,
9538
+ text
9539
+ } = data;
9540
+ if (startOffset < 0 || startOffset >= endOffset || endOffset > documentText.length || documentText.slice(startOffset, endOffset) !== text || targetOffset >= startOffset && targetOffset <= endOffset) {
9541
+ return undefined;
9542
+ }
9543
+ const regionStartOffset = Math.min(startOffset, targetOffset);
9544
+ const regionEndOffset = Math.max(endOffset, targetOffset);
9545
+ const replacement = targetOffset < startOffset ? text + documentText.slice(targetOffset, startOffset) : documentText.slice(endOffset, targetOffset) + text;
9546
+ const newSelectionStartOffset = targetOffset < startOffset ? targetOffset : targetOffset - text.length;
9547
+ const newText = documentText.slice(0, regionStartOffset) + replacement + documentText.slice(regionEndOffset);
9548
+ const newLines = splitLines(newText);
9549
+ const start = positionAt(editor, regionStartOffset);
9550
+ const end = positionAt(editor, regionEndOffset);
9438
9551
  return {
9552
+ change: {
9553
+ deleted: splitLines(documentText.slice(regionStartOffset, regionEndOffset)),
9554
+ end,
9555
+ inserted: splitLines(replacement),
9556
+ origin,
9557
+ start
9558
+ },
9559
+ selections: getSelection(newLines, newSelectionStartOffset, newSelectionStartOffset + text.length)
9560
+ };
9561
+ };
9562
+
9563
+ const moveTextDrag = async (editor, data, target) => {
9564
+ if (data.sourceUri !== editor.uri) {
9565
+ return editor;
9566
+ }
9567
+ const result = getTextDragEdit(editor, data, target, EditorTextDrag);
9568
+ if (!result) {
9569
+ return editor;
9570
+ }
9571
+ return scheduleDocumentAndCursorsSelections(editor, [result.change], result.selections);
9572
+ };
9573
+
9574
+ const handlePointerUp = async editor => {
9575
+ const resetEditor = {
9439
9576
  ...editor,
9440
9577
  hasListener: false,
9441
9578
  isSelecting: false,
9442
9579
  selectionAutoMovePosition: {
9443
9580
  columnIndex: 0,
9444
9581
  rowIndex: 0
9445
- }
9582
+ },
9583
+ textDragDropPosition: {
9584
+ columnIndex: 0,
9585
+ rowIndex: 0
9586
+ },
9587
+ textDragId: 0
9446
9588
  };
9589
+ if (!editor.textDragId) {
9590
+ return resetEditor;
9591
+ }
9592
+ try {
9593
+ const data = await invoke$f('DragAndDrop.takeTextDrag', editor.textDragId);
9594
+ if (!data) {
9595
+ return resetEditor;
9596
+ }
9597
+ return moveTextDrag(resetEditor, data, editor.textDragDropPosition);
9598
+ } catch {
9599
+ return resetEditor;
9600
+ }
9447
9601
  };
9448
9602
 
9449
9603
  // @ts-ignore
@@ -10145,7 +10299,7 @@ const launch = async () => {
10145
10299
  return;
10146
10300
  }
10147
10301
  const rpc = await launchFindWidgetWorker();
10148
- set$g(rpcId, rpc);
10302
+ set$h(rpcId, rpc);
10149
10303
  };
10150
10304
  const invoke$3 = async (method, ...params) => {
10151
10305
  const rpc = get$9(rpcId);
@@ -13505,7 +13659,7 @@ const handleMessagePort = async (port, rpcId) => {
13505
13659
  messagePort: port
13506
13660
  });
13507
13661
  if (rpcId) {
13508
- set$g(rpcId, rpc);
13662
+ set$h(rpcId, rpc);
13509
13663
  }
13510
13664
  };
13511
13665
 
@@ -13539,6 +13693,10 @@ const kFontWeight = 'editor.fontWeight';
13539
13693
  const kHover = 'editor.hover';
13540
13694
  const kMinimapEnabled = 'editor.minimap.enabled';
13541
13695
  const kBreadcrumbsEnabled = 'breadcrumbs.enabled';
13696
+ const kDragAndDropEnabled = 'editor.dragAndDrop';
13697
+ const getDragAndDropEnabled = async () => {
13698
+ return (await get$3(kDragAndDropEnabled)) ?? true;
13699
+ };
13542
13700
  const isAutoClosingBracketsEnabled = async () => {
13543
13701
  return Boolean(await get$3(kAutoClosingBrackets));
13544
13702
  };
@@ -13595,11 +13753,12 @@ const getBreadcrumbsEnabled = async () => {
13595
13753
  };
13596
13754
 
13597
13755
  const getEditorPreferences = async () => {
13598
- const [diagnosticsEnabled$1, fontFamily, fontSize, fontWeight, hoverEnabled, isAutoClosingBracketsEnabled$1, isAutoClosingQuotesEnabled$1, isAutoClosingTagsEnabled$1, isQuickSuggestionsEnabled$1, lineNumbers, rowHeight, tabSize, letterSpacing, completionTriggerCharacters, minimapEnabled, breadcrumbsEnabled, insertSpaces] = await Promise.all([diagnosticsEnabled(), getFontFamily(), getFontSize(), getFontWeight(), getHoverEnabled(), isAutoClosingBracketsEnabled(), isAutoClosingQuotesEnabled(), isAutoClosingTagsEnabled(), isQuickSuggestionsEnabled(), getLineNumbers(), getRowHeight(), getTabSize(), getLetterSpacing(), getCompletionTriggerCharacters(), getMinimapEnabled(), getBreadcrumbsEnabled(), getInsertSpaces()]);
13756
+ const [diagnosticsEnabled$1, fontFamily, fontSize, fontWeight, hoverEnabled, isAutoClosingBracketsEnabled$1, isAutoClosingQuotesEnabled$1, isAutoClosingTagsEnabled$1, isQuickSuggestionsEnabled$1, lineNumbers, rowHeight, tabSize, letterSpacing, completionTriggerCharacters, minimapEnabled, breadcrumbsEnabled, insertSpaces, dragAndDropEnabled] = await Promise.all([diagnosticsEnabled(), getFontFamily(), getFontSize(), getFontWeight(), getHoverEnabled(), isAutoClosingBracketsEnabled(), isAutoClosingQuotesEnabled(), isAutoClosingTagsEnabled(), isQuickSuggestionsEnabled(), getLineNumbers(), getRowHeight(), getTabSize(), getLetterSpacing(), getCompletionTriggerCharacters(), getMinimapEnabled(), getBreadcrumbsEnabled(), getInsertSpaces(), getDragAndDropEnabled()]);
13599
13757
  return {
13600
13758
  breadcrumbsEnabled,
13601
13759
  completionTriggerCharacters,
13602
13760
  diagnosticsEnabled: diagnosticsEnabled$1,
13761
+ dragAndDropEnabled,
13603
13762
  fontFamily,
13604
13763
  fontSize,
13605
13764
  fontWeight,
@@ -13939,6 +14098,7 @@ const loadContent = async (state, savedState) => {
13939
14098
  breadcrumbsEnabled,
13940
14099
  completionTriggerCharacters,
13941
14100
  diagnosticsEnabled,
14101
+ dragAndDropEnabled,
13942
14102
  fontFamily,
13943
14103
  fontSize,
13944
14104
  fontWeight,
@@ -13970,6 +14130,7 @@ const loadContent = async (state, savedState) => {
13970
14130
  charWidth,
13971
14131
  completionTriggerCharacters,
13972
14132
  diagnosticsEnabled,
14133
+ dragAndDropEnabled,
13973
14134
  fontFamily,
13974
14135
  fontSize,
13975
14136
  fontWeight,
@@ -15421,7 +15582,7 @@ const renderEventListeners = () => {
15421
15582
  preventDefault: true
15422
15583
  }, {
15423
15584
  name: HandleMouseDown,
15424
- params: ['handleMouseDown', 'event.button', 'event.altKey', 'event.ctrlKey', ClientX, ClientY, 'event.detail']
15585
+ params: ['handleMouseDown', 'event.button', 'event.altKey', 'event.ctrlKey', ClientX, ClientY, 'event.detail', 'event.shiftKey']
15425
15586
  }, {
15426
15587
  name: HandlePointerDown,
15427
15588
  params: ['handlePointerDown', 'event.button', 'event.altKey', 'event.ctrlKey', ClientX, ClientY, 'event.detail', 'event.currentTarget.parentElement.parentElement.offsetLeft'],
@@ -16089,6 +16250,14 @@ for (const [key, value] of Object.entries(commandMap)) {
16089
16250
  }
16090
16251
  }
16091
16252
 
16253
+ const initializeDragAndDropWorker = async () => {
16254
+ const rpc = await create$d({
16255
+ commandMap: {},
16256
+ send: sendMessagePortToDragAndDropWorker
16257
+ });
16258
+ set$f(rpc);
16259
+ };
16260
+
16092
16261
  const initializeErrorWorker = async () => {
16093
16262
  const rpc = await create$d({
16094
16263
  commandMap: {},
@@ -16150,12 +16319,12 @@ const initializeTextMeasurementWorker = async () => {
16150
16319
 
16151
16320
  const listen = async () => {
16152
16321
  registerCommands(commandMap);
16153
- await Promise.all([initializeRendererWorker(), initializeErrorWorker(), initializeExtensionManagementWorker(), initializeTextMeasurementWorker(), initializeOpenerWorker()]);
16322
+ await Promise.all([initializeRendererWorker(), initializeDragAndDropWorker(), initializeErrorWorker(), initializeExtensionManagementWorker(), initializeTextMeasurementWorker(), initializeOpenerWorker()]);
16154
16323
  const dialogRpc = await create$d({
16155
16324
  commandMap: {},
16156
16325
  send: sendMessagePortToDialogWorker
16157
16326
  });
16158
- set$f(dialogRpc);
16327
+ set$g(dialogRpc);
16159
16328
  };
16160
16329
 
16161
16330
  const CodeGeneratorInput = 'CodeGeneratorInput';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.46.0",
3
+ "version": "19.47.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"