@lvce-editor/editor-worker 19.61.4 → 19.62.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.
@@ -0,0 +1,64 @@
1
+ import { o as offsetAt } from './editorWorkerMain.js';
2
+
3
+ const noColorRange = {
4
+ endOffset: -1,
5
+ startOffset: -1,
6
+ value: ''
7
+ };
8
+ const colorPattern = /#[\da-f]{3,8}\b|\b(?:hsla?|rgba?)\([^)]*\)/gi;
9
+ const getColorPickerRange = async editor => {
10
+ const {
11
+ lines,
12
+ selections
13
+ } = editor;
14
+ if (!selections || selections.length < 4) {
15
+ return noColorRange;
16
+ }
17
+ const selectionStartRow = selections[0];
18
+ const selectionEndRow = selections[2];
19
+ if (selectionStartRow !== selectionEndRow) {
20
+ return noColorRange;
21
+ }
22
+ const selectionStartColumn = selections[1];
23
+ const selectionEndColumn = selections[3];
24
+ const rowIndex = selectionEndRow;
25
+ const line = lines[rowIndex];
26
+ if (typeof line !== 'string') {
27
+ return noColorRange;
28
+ }
29
+ if (selectionStartColumn !== selectionEndColumn) {
30
+ const startColumn = Math.min(selectionStartColumn, selectionEndColumn);
31
+ const endColumn = Math.max(selectionStartColumn, selectionEndColumn);
32
+ return {
33
+ endOffset: offsetAt(editor, rowIndex, endColumn),
34
+ startOffset: offsetAt(editor, rowIndex, startColumn),
35
+ value: line.slice(startColumn, endColumn)
36
+ };
37
+ }
38
+ const columnIndex = selectionEndColumn;
39
+ for (const match of line.matchAll(colorPattern)) {
40
+ const startColumn = match.index;
41
+ const endColumn = startColumn + match[0].length;
42
+ if (columnIndex >= startColumn && columnIndex <= endColumn) {
43
+ return {
44
+ endOffset: offsetAt(editor, rowIndex, endColumn),
45
+ startOffset: offsetAt(editor, rowIndex, startColumn),
46
+ value: match[0]
47
+ };
48
+ }
49
+ }
50
+ const {
51
+ getNamedColorRange
52
+ } = await import('./GetNamedColorRange-LJAB8ndU.js');
53
+ const namedColorRange = getNamedColorRange(line, columnIndex);
54
+ if (!namedColorRange) {
55
+ return noColorRange;
56
+ }
57
+ return {
58
+ endOffset: offsetAt(editor, rowIndex, namedColorRange.end),
59
+ startOffset: offsetAt(editor, rowIndex, namedColorRange.start),
60
+ value: namedColorRange.value
61
+ };
62
+ };
63
+
64
+ export { getColorPickerRange };
@@ -0,0 +1,28 @@
1
+ const colorPattern = /\b[a-z]+\b/gi;
2
+ const getNamedColorRange = (line, columnIndex) => {
3
+ for (const match of line.matchAll(colorPattern)) {
4
+ const start = match.index;
5
+ const end = start + match[0].length;
6
+ if (columnIndex < start || columnIndex > end || line[start - 1] === '-' || line[end] === '-') {
7
+ continue;
8
+ }
9
+ const value = match[0];
10
+ if (value.toLowerCase() === 'currentcolor') {
11
+ return undefined;
12
+ }
13
+ const context = new OffscreenCanvas(1, 1).getContext('2d');
14
+ context.fillStyle = '#010203';
15
+ context.fillStyle = value;
16
+ if (context.fillStyle === '#010203') {
17
+ return undefined;
18
+ }
19
+ return {
20
+ end,
21
+ start,
22
+ value
23
+ };
24
+ }
25
+ return undefined;
26
+ };
27
+
28
+ export { getNamedColorRange };
@@ -1764,7 +1764,7 @@ const codeGeneratorAccept = state => {
1764
1764
 
1765
1765
  const editorStates = create$9();
1766
1766
  const {
1767
- dispose: dispose$4,
1767
+ dispose: dispose$5,
1768
1768
  getCommandIds,
1769
1769
  registerCommands,
1770
1770
  wrapGetter
@@ -2333,7 +2333,7 @@ const getInitialLineState = initialLineState => {
2333
2333
  return deepCopy(initialLineState);
2334
2334
  };
2335
2335
 
2336
- const state$e = {
2336
+ const state$d = {
2337
2337
  warned: []
2338
2338
  };
2339
2339
  const flattenTokensArray = tokens => {
@@ -2345,10 +2345,10 @@ const flattenTokensArray = tokens => {
2345
2345
  return flattened;
2346
2346
  };
2347
2347
  const warnDeprecatedArrayReturn = (languageId, fn) => {
2348
- if (state$e.warned.includes(fn)) {
2348
+ if (state$d.warned.includes(fn)) {
2349
2349
  return;
2350
2350
  }
2351
- state$e.warned.push(fn);
2351
+ state$d.warned.push(fn);
2352
2352
  console.warn(`tokenizers without hasArrayReturn=false are deprecated (language ${languageId})`);
2353
2353
  };
2354
2354
  const safeTokenizeLine = (languageId, tokenizeLine, line, lineStateAtStart, hasArrayReturn) => {
@@ -2409,14 +2409,14 @@ const TokenizePlainText = {
2409
2409
  tokenizeLine
2410
2410
  };
2411
2411
 
2412
- const state$d = {
2412
+ const state$c = {
2413
2413
  enabled: false
2414
2414
  };
2415
2415
  const setEnabled$1 = value => {
2416
- state$d.enabled = value;
2416
+ state$c.enabled = value;
2417
2417
  };
2418
2418
  const getEnabled$1 = () => {
2419
- return state$d.enabled;
2419
+ return state$c.enabled;
2420
2420
  };
2421
2421
 
2422
2422
  const {
@@ -2424,25 +2424,25 @@ const {
2424
2424
  set: set$6
2425
2425
  } = SyntaxHighlightingWorker;
2426
2426
 
2427
- const state$c = {
2427
+ const state$b = {
2428
2428
  pending: Object.create(null),
2429
2429
  tokenizePaths: Object.create(null),
2430
2430
  tokenizers: Object.create(null)
2431
2431
  };
2432
2432
  const has = languageId => {
2433
- return Object.hasOwn(state$c.tokenizers, languageId);
2433
+ return Object.hasOwn(state$b.tokenizers, languageId);
2434
2434
  };
2435
2435
  const set$5 = (languageId, tokenizer) => {
2436
- state$c.tokenizers[languageId] = tokenizer;
2436
+ state$b.tokenizers[languageId] = tokenizer;
2437
2437
  };
2438
2438
  const get$6 = languageId => {
2439
- return state$c.tokenizers[languageId];
2439
+ return state$b.tokenizers[languageId];
2440
2440
  };
2441
2441
  const setTokenizePath = (languageId, tokenizePath) => {
2442
- state$c.tokenizePaths[languageId] = tokenizePath;
2442
+ state$b.tokenizePaths[languageId] = tokenizePath;
2443
2443
  };
2444
2444
  const getTokenizePath$1 = languageId => {
2445
- return state$c.tokenizePaths[languageId] || '';
2445
+ return state$b.tokenizePaths[languageId] || '';
2446
2446
  };
2447
2447
  const setTokenizePaths = languages => {
2448
2448
  for (const language of languages) {
@@ -2452,7 +2452,7 @@ const setTokenizePaths = languages => {
2452
2452
  }
2453
2453
  };
2454
2454
  const isPending = languageId => {
2455
- return Object.hasOwn(state$c.pending, languageId);
2455
+ return Object.hasOwn(state$b.pending, languageId);
2456
2456
  };
2457
2457
 
2458
2458
  const tokenMaps = Object.create(null);
@@ -3280,14 +3280,14 @@ const getVisible$1 = async (editor, syncIncremental) => {
3280
3280
  };
3281
3281
  };
3282
3282
 
3283
- const state$b = {
3283
+ const state$a = {
3284
3284
  enabled: false
3285
3285
  };
3286
3286
  const setEnabled = value => {
3287
- state$b.enabled = value;
3287
+ state$a.enabled = value;
3288
3288
  };
3289
3289
  const getEnabled = () => {
3290
- return state$b.enabled;
3290
+ return state$a.enabled;
3291
3291
  };
3292
3292
 
3293
3293
  // TODO this should be in a separate scrolling module
@@ -3573,7 +3573,7 @@ const start = delivery => {
3573
3573
  delivery.running = run$1(delivery);
3574
3574
  return delivery.running;
3575
3575
  };
3576
- const dispose$3 = rpcId => {
3576
+ const dispose$4 = rpcId => {
3577
3577
  const delivery = deliveries.get(rpcId);
3578
3578
  if (delivery) {
3579
3579
  delivery.disposed = true;
@@ -3583,7 +3583,7 @@ const dispose$3 = rpcId => {
3583
3583
  const send$2 = (rpcId, rpc, status) => {
3584
3584
  let delivery = deliveries.get(rpcId);
3585
3585
  if (!delivery || delivery.rpc !== rpc) {
3586
- dispose$3(rpcId);
3586
+ dispose$4(rpcId);
3587
3587
  delivery = {
3588
3588
  baseline: undefined,
3589
3589
  disposed: false,
@@ -3601,7 +3601,7 @@ const send$2 = (rpcId, rpc, status) => {
3601
3601
  return delivery.running || start(delivery);
3602
3602
  };
3603
3603
 
3604
- const state$a = Object.create(null);
3604
+ const state$9 = Object.create(null);
3605
3605
 
3606
3606
  /**
3607
3607
  * Register a listener for a specific event type
@@ -3611,13 +3611,13 @@ const state$a = Object.create(null);
3611
3611
  const registerListener$1 = (listenerType, rpcId) => {
3612
3612
  number(listenerType);
3613
3613
  number(rpcId);
3614
- if (!Object.hasOwn(state$a, listenerType)) {
3615
- state$a[listenerType] = [];
3614
+ if (!Object.hasOwn(state$9, listenerType)) {
3615
+ state$9[listenerType] = [];
3616
3616
  }
3617
3617
 
3618
3618
  // Avoid duplicate registrations
3619
- if (!state$a[listenerType].includes(rpcId)) {
3620
- state$a[listenerType].push(rpcId);
3619
+ if (!state$9[listenerType].includes(rpcId)) {
3620
+ state$9[listenerType].push(rpcId);
3621
3621
  }
3622
3622
  };
3623
3623
 
@@ -3630,12 +3630,12 @@ const unregisterListener$1 = (listenerType, rpcId) => {
3630
3630
  number(listenerType);
3631
3631
  number(rpcId);
3632
3632
  if (listenerType === EditorSelection$1) {
3633
- dispose$3(rpcId);
3633
+ dispose$4(rpcId);
3634
3634
  }
3635
- if (Object.hasOwn(state$a, listenerType)) {
3636
- const index = state$a[listenerType].indexOf(rpcId);
3635
+ if (Object.hasOwn(state$9, listenerType)) {
3636
+ const index = state$9[listenerType].indexOf(rpcId);
3637
3637
  if (index !== -1) {
3638
- state$a[listenerType].splice(index, 1);
3638
+ state$9[listenerType].splice(index, 1);
3639
3639
  }
3640
3640
  }
3641
3641
  };
@@ -3647,7 +3647,7 @@ const unregisterListener$1 = (listenerType, rpcId) => {
3647
3647
  */
3648
3648
  const getListeners = listenerType => {
3649
3649
  number(listenerType);
3650
- return state$a[listenerType] || [];
3650
+ return state$9[listenerType] || [];
3651
3651
  };
3652
3652
 
3653
3653
  /**
@@ -4211,6 +4211,14 @@ const scheduleDocumentAndCursorsSelections = async (editor, changes, selectionCh
4211
4211
  const newLines = applyEdits(editor, changes);
4212
4212
  const partialNewEditor = updateLines(editor, newLines);
4213
4213
  const newSelections = selectionChanges || applyEdit$1(partialNewEditor, changes);
4214
+ const selectionHistory = {
4215
+ after: newSelections,
4216
+ before: editor.selections
4217
+ };
4218
+ Object.defineProperty(changes, 'selectionHistory', {
4219
+ configurable: true,
4220
+ value: selectionHistory
4221
+ });
4214
4222
  // TODO should separate rendering from business logic somehow
4215
4223
  // currently hard to test because need to mock editor height, top, left,
4216
4224
  // invalidStartIndex, lineCache, etc. just for testing editorType
@@ -4281,7 +4289,7 @@ const scheduleDocumentAndCursorsSelections = async (editor, changes, selectionCh
4281
4289
  };
4282
4290
  };
4283
4291
  // @ts-ignore
4284
- const scheduleDocumentAndCursorsSelectionIsUndo = async (editor, changes) => {
4292
+ const scheduleDocumentAndCursorsSelectionIsUndo = async (editor, changes, selectionChanges = undefined) => {
4285
4293
  object(editor);
4286
4294
  array(changes);
4287
4295
  if (changes.length === 0) {
@@ -4289,7 +4297,7 @@ const scheduleDocumentAndCursorsSelectionIsUndo = async (editor, changes) => {
4289
4297
  }
4290
4298
  const newLines = applyEdits(editor, changes);
4291
4299
  const partialNewEditor = updateLines(editor, newLines);
4292
- const newSelections = applyEdit$1(partialNewEditor, changes);
4300
+ const newSelections = selectionChanges || applyEdit$1(partialNewEditor, changes);
4293
4301
  const invalidStartIndex = Math.min(editor.invalidStartIndex, changes[0].start.rowIndex);
4294
4302
  const newEditor = {
4295
4303
  ...partialNewEditor,
@@ -5085,15 +5093,15 @@ const launchColorPickerWorker = async () => {
5085
5093
  return launchWorker(name, url, undefined, getColorPickerWorkerCommandMap());
5086
5094
  };
5087
5095
 
5088
- const state$9 = {};
5089
- const getOrCreate$3 = () => {
5090
- if (!state$9.workerPromise) {
5091
- state$9.workerPromise = launchColorPickerWorker();
5096
+ const state$8 = {};
5097
+ const getOrCreate$2 = () => {
5098
+ if (!state$8.workerPromise) {
5099
+ state$8.workerPromise = launchColorPickerWorker();
5092
5100
  }
5093
- return state$9.workerPromise;
5101
+ return state$8.workerPromise;
5094
5102
  };
5095
5103
  const invoke$7 = async (method, ...params) => {
5096
- const worker = await getOrCreate$3();
5104
+ const worker = await getOrCreate$2();
5097
5105
  return await worker.invoke(method, ...params);
5098
5106
  };
5099
5107
 
@@ -5749,7 +5757,7 @@ const diff2 = uid => {
5749
5757
 
5750
5758
  const autoSaveDelay = 1000;
5751
5759
  const pendingSaves = new Map();
5752
- const state$8 = {
5760
+ const state$7 = {
5753
5761
  nextToken: 0
5754
5762
  };
5755
5763
  const run = async (uid, token, save) => {
@@ -5759,8 +5767,8 @@ const run = async (uid, token, save) => {
5759
5767
  await save(token);
5760
5768
  };
5761
5769
  const schedule = (uid, save) => {
5762
- dispose$2(uid);
5763
- const token = ++state$8.nextToken;
5770
+ dispose$3(uid);
5771
+ const token = ++state$7.nextToken;
5764
5772
  const timeout = setTimeout(run, autoSaveDelay, uid, token, save);
5765
5773
  pendingSaves.set(uid, {
5766
5774
  timeout,
@@ -5774,9 +5782,9 @@ const consume = (uid, token) => {
5774
5782
  if (!isLatest(uid, token)) {
5775
5783
  return;
5776
5784
  }
5777
- dispose$2(uid);
5785
+ dispose$3(uid);
5778
5786
  };
5779
- const dispose$2 = uid => {
5787
+ const dispose$3 = uid => {
5780
5788
  const pendingSave = pendingSaves.get(uid);
5781
5789
  if (!pendingSave) {
5782
5790
  return;
@@ -5851,6 +5859,34 @@ const notifyEditorStatusCleared = async () => {
5851
5859
  await Promise.all(getListeners(EditorSelection$1).map(rpcId => sendToListener(rpcId, undefined)));
5852
5860
  };
5853
5861
 
5862
+ const launchRenameWorker = async () => {
5863
+ const name = 'Rename Worker';
5864
+ const url = 'renameWorkerMain.js';
5865
+ const rpc = await launchWorker(name, url);
5866
+ await rpc.invoke('Rename.initialize');
5867
+ return rpc;
5868
+ };
5869
+
5870
+ let workerPromise;
5871
+ const invoke$6 = async (method, ...params) => {
5872
+ // eslint-disable-next-line unicorn/no-top-level-assignment-in-function
5873
+ workerPromise ||= launchRenameWorker();
5874
+ const worker = await workerPromise;
5875
+ return await worker.invoke(method, ...params);
5876
+ };
5877
+ const dispose$2 = async () => {
5878
+ if (getKeys$2().length > 1) {
5879
+ return;
5880
+ }
5881
+ const promise = workerPromise;
5882
+ // eslint-disable-next-line unicorn/no-top-level-assignment-in-function
5883
+ workerPromise = undefined;
5884
+ try {
5885
+ // eslint-disable-next-line unicorn/prefer-await
5886
+ await promise?.then(worker => worker.dispose(), () => {});
5887
+ } catch {}
5888
+ };
5889
+
5854
5890
  const addWidget$1 = widget => {
5855
5891
  const module = get$7(widget.id);
5856
5892
  if (!module) {
@@ -5942,8 +5978,9 @@ const disposeEditor = async editorUid => {
5942
5978
  widgets: []
5943
5979
  });
5944
5980
  dispose$1(editorUid);
5945
- dispose$2(editorUid);
5946
- dispose$4(editorUid);
5981
+ dispose$3(editorUid);
5982
+ dispose$5(editorUid);
5983
+ await dispose$2();
5947
5984
  if (getKeys$2().length === 0) {
5948
5985
  await notifyEditorStatusCleared();
5949
5986
  }
@@ -6217,7 +6254,7 @@ const isFormattingError = error => {
6217
6254
  return error && error instanceof Error && error.message.startsWith(expectedErrorMessage$1);
6218
6255
  };
6219
6256
 
6220
- const state$7 = {
6257
+ const state$6 = {
6221
6258
  configured: false,
6222
6259
  lastId: -1,
6223
6260
  nextId: 0
@@ -6225,23 +6262,23 @@ const state$7 = {
6225
6262
  const configure = (start, end) => {
6226
6263
  const {
6227
6264
  configured
6228
- } = state$7;
6265
+ } = state$6;
6229
6266
  if (configured) {
6230
6267
  throw new Error('Component id range is already configured');
6231
6268
  }
6232
6269
  if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end) || start <= 0 || end < start) {
6233
6270
  throw new Error('Invalid component id range');
6234
6271
  }
6235
- state$7.nextId = start;
6236
- state$7.lastId = end;
6237
- state$7.configured = true;
6272
+ state$6.nextId = start;
6273
+ state$6.lastId = end;
6274
+ state$6.configured = true;
6238
6275
  };
6239
6276
  const create$8 = () => {
6240
6277
  const {
6241
6278
  configured,
6242
6279
  lastId,
6243
6280
  nextId
6244
- } = state$7;
6281
+ } = state$6;
6245
6282
  if (!configured) {
6246
6283
  // Compatibility with renderer versions that do not assign worker id ranges.
6247
6284
  return Math.random();
@@ -6249,7 +6286,7 @@ const create$8 = () => {
6249
6286
  if (nextId > lastId) {
6250
6287
  throw new Error('Component id range exhausted');
6251
6288
  }
6252
- return state$7.nextId++;
6289
+ return state$6.nextId++;
6253
6290
  };
6254
6291
 
6255
6292
  const Message = 9;
@@ -6784,7 +6821,7 @@ const cancelSelection = editor => {
6784
6821
  return scheduleSelections(editor, newSelections);
6785
6822
  };
6786
6823
 
6787
- const colorPattern$1 = /#[\dA-Fa-f]+/g;
6824
+ const colorPattern = /#[\dA-Fa-f]+/g;
6788
6825
  const numberPattern = /(?<![\w.#])[+-]?(?:(?:\d+(?:\.\d*)?)|(?:\.\d+))(?:[eE][+-]?\d+)?(?![\d.])/g;
6789
6826
  const validColorLengths = new Set([4, 5, 7, 9]);
6790
6827
  const isColor = value => {
@@ -6867,7 +6904,7 @@ const findMatchAt = (line, columnIndex, pattern, predicate) => {
6867
6904
  return undefined;
6868
6905
  };
6869
6906
  const findValueAt = (line, columnIndex) => {
6870
- return findMatchAt(line, columnIndex, colorPattern$1, isColor) ?? findMatchAt(line, columnIndex, numberPattern, isNumber);
6907
+ return findMatchAt(line, columnIndex, colorPattern, isColor) ?? findMatchAt(line, columnIndex, numberPattern, isNumber);
6871
6908
  };
6872
6909
  const getSelectionTarget = (editor, index) => {
6873
6910
  const selectionStartRow = editor.selections[index];
@@ -7090,26 +7127,6 @@ const closeFind$1 = editor => {
7090
7127
  };
7091
7128
  };
7092
7129
 
7093
- const launchRenameWorker = async () => {
7094
- const name = 'Rename Worker';
7095
- const url = 'renameWorkerMain.js';
7096
- const rpc = await launchWorker(name, url);
7097
- await rpc.invoke('Rename.initialize');
7098
- return rpc;
7099
- };
7100
-
7101
- const state$6 = {};
7102
- const getOrCreate$2 = () => {
7103
- if (!state$6.workerPromise) {
7104
- state$6.workerPromise = launchRenameWorker();
7105
- }
7106
- return state$6.workerPromise;
7107
- };
7108
- const invoke$6 = async (method, ...params) => {
7109
- const worker = await getOrCreate$2();
7110
- return await worker.invoke(method, ...params);
7111
- };
7112
-
7113
7130
  // TODO duplicate code
7114
7131
  const isRenameWidget = widget => {
7115
7132
  return widget.id === Rename$1;
@@ -7256,63 +7273,16 @@ const getColorPickerBounds = editor => {
7256
7273
  };
7257
7274
  };
7258
7275
 
7259
- const noColorRange = {
7260
- endOffset: -1,
7261
- startOffset: -1,
7262
- value: ''
7263
- };
7264
- const colorPattern = /#[\da-f]{3,8}\b|\b(?:hsla?|rgba?)\([^)]*\)/gi;
7265
- const getColorPickerRange = editor => {
7266
- const {
7267
- lines,
7268
- selections
7269
- } = editor;
7270
- if (!selections || selections.length < 4) {
7271
- return noColorRange;
7272
- }
7273
- const selectionStartRow = selections[0];
7274
- const selectionEndRow = selections[2];
7275
- if (selectionStartRow !== selectionEndRow) {
7276
- return noColorRange;
7277
- }
7278
- const selectionStartColumn = selections[1];
7279
- const selectionEndColumn = selections[3];
7280
- const rowIndex = selectionEndRow;
7281
- const line = lines[rowIndex];
7282
- if (typeof line !== 'string') {
7283
- return noColorRange;
7284
- }
7285
- if (selectionStartColumn !== selectionEndColumn) {
7286
- const startColumn = Math.min(selectionStartColumn, selectionEndColumn);
7287
- const endColumn = Math.max(selectionStartColumn, selectionEndColumn);
7288
- return {
7289
- endOffset: offsetAt(editor, rowIndex, endColumn),
7290
- startOffset: offsetAt(editor, rowIndex, startColumn),
7291
- value: line.slice(startColumn, endColumn)
7292
- };
7293
- }
7294
- const columnIndex = selectionEndColumn;
7295
- for (const match of line.matchAll(colorPattern)) {
7296
- const startColumn = match.index;
7297
- const endColumn = startColumn + match[0].length;
7298
- if (columnIndex >= startColumn && columnIndex <= endColumn) {
7299
- return {
7300
- endOffset: offsetAt(editor, rowIndex, endColumn),
7301
- startOffset: offsetAt(editor, rowIndex, startColumn),
7302
- value: match[0]
7303
- };
7304
- }
7305
- }
7306
- return noColorRange;
7307
- };
7308
-
7309
7276
  const newStateGenerator$5 = (state, parentUid) => {
7310
7277
  return loadContent$3(state, parentUid);
7311
7278
  };
7312
7279
  const openColorPicker = async editor => {
7313
7280
  const fullFocus = true;
7314
7281
  const bounds = getColorPickerBounds(editor);
7315
- const range = getColorPickerRange(editor);
7282
+ const {
7283
+ getColorPickerRange
7284
+ } = await import('./GetColorPickerRange-B84IlfRJ.js');
7285
+ const range = await getColorPickerRange(editor);
7316
7286
  const createWidget = () => create$6(bounds, range, editor.undoStack.length);
7317
7287
  return addWidgetToEditor(ColorPicker$2, ColorPicker, editor, createWidget, newStateGenerator$5, fullFocus);
7318
7288
  };
@@ -7445,40 +7415,69 @@ const copy$1 = async editor => {
7445
7415
  return editor;
7446
7416
  };
7447
7417
 
7448
- // TODO handle multiline selection
7449
-
7418
+ const getCopyLineOperations = selections => {
7419
+ const operations = [];
7420
+ for (let i = 0; i < selections.length; i += 4) {
7421
+ const [startRowIndex,, selectionEndRowIndex, endColumnIndex] = getSelectionPairs(selections, i);
7422
+ const endRowIndex = startRowIndex < selectionEndRowIndex && endColumnIndex === 0 ? selectionEndRowIndex - 1 : selectionEndRowIndex;
7423
+ operations.push({
7424
+ endRowIndex,
7425
+ startRowIndex
7426
+ });
7427
+ }
7428
+ operations.sort((a, b) => a.startRowIndex - b.startRowIndex || a.endRowIndex - b.endRowIndex);
7429
+ const mergedOperations = [];
7430
+ for (const operation of operations) {
7431
+ const previous = mergedOperations.at(-1);
7432
+ if (previous && previous.endRowIndex >= operation.startRowIndex) {
7433
+ mergedOperations[mergedOperations.length - 1] = {
7434
+ ...previous,
7435
+ endRowIndex: Math.max(previous.endRowIndex, operation.endRowIndex)
7436
+ };
7437
+ } else {
7438
+ mergedOperations.push(operation);
7439
+ }
7440
+ }
7441
+ return mergedOperations;
7442
+ };
7450
7443
  const copyLineDown = editor => {
7451
7444
  const {
7452
7445
  selections
7453
7446
  } = editor;
7454
- const rows = [];
7455
- for (let i = 0; i < selections.length; i += 4) {
7456
- const rowIndex = selections[i];
7457
- number(rowIndex);
7458
- rows.push(rowIndex);
7459
- }
7460
- const uniqueRows = [...new Set(rows)].toSorted((a, b) => a - b);
7461
- const changes = uniqueRows.map(rowIndex => {
7462
- const position = {
7463
- columnIndex: 0,
7464
- rowIndex
7465
- };
7447
+ const operations = getCopyLineOperations(selections);
7448
+ const changes = operations.map(({
7449
+ endRowIndex,
7450
+ startRowIndex
7451
+ }) => {
7452
+ const selectedLines = editor.lines.slice(startRowIndex, endRowIndex + 1);
7466
7453
  return {
7467
- deleted: [''],
7468
- end: position,
7469
- inserted: [getLine$1(editor, rowIndex), ''],
7470
- start: position
7454
+ deleted: selectedLines,
7455
+ end: {
7456
+ columnIndex: editor.lines[endRowIndex].length,
7457
+ rowIndex: endRowIndex
7458
+ },
7459
+ inserted: [...selectedLines, ...selectedLines],
7460
+ start: {
7461
+ columnIndex: 0,
7462
+ rowIndex: startRowIndex
7463
+ }
7471
7464
  };
7472
7465
  });
7473
- const rowOffsets = new Map(uniqueRows.map((row, index) => [row, index + 1]));
7466
+ const getRowOffset = rowIndex => {
7467
+ let offset = 0;
7468
+ for (const operation of operations) {
7469
+ if (operation.startRowIndex <= rowIndex) {
7470
+ offset += operation.endRowIndex - operation.startRowIndex + 1;
7471
+ }
7472
+ }
7473
+ return offset;
7474
+ };
7474
7475
  const selectionChanges = new Uint32Array(selections.length);
7475
7476
  for (let i = 0; i < selections.length; i += 4) {
7476
- const rowIndex = selections[i] + rowOffsets.get(selections[i]);
7477
- const columnIndex = selections[i + 1];
7478
- selectionChanges[i] = rowIndex;
7479
- selectionChanges[i + 1] = columnIndex;
7480
- selectionChanges[i + 2] = rowIndex;
7481
- selectionChanges[i + 3] = columnIndex;
7477
+ selectionChanges[i] = selections[i] + getRowOffset(selections[i]);
7478
+ selectionChanges[i + 1] = selections[i + 1];
7479
+ selectionChanges[i + 2] = selections[i + 2] + getRowOffset(selections[i + 2]);
7480
+ selectionChanges[i + 3] = selections[i + 3];
7482
7481
  }
7483
7482
  return scheduleDocumentAndCursorsSelections(editor, changes, selectionChanges);
7484
7483
  };
@@ -10760,6 +10759,7 @@ const createFn = (key, name, widgetId) => {
10760
10759
  const latestChildIndex = latestAfterInvoke.widgets.findIndex(isWidget);
10761
10760
  if (latestChildIndex === -1) {
10762
10761
  set$8(editor.uid, editor, latestAfterInvoke);
10762
+ await dispose$2();
10763
10763
  return latestAfterInvoke;
10764
10764
  }
10765
10765
  const diff = await invoke(`${name}.diff2`, uid);
@@ -11055,8 +11055,15 @@ const openRename = async editor => {
11055
11055
  return editor;
11056
11056
  }
11057
11057
  const fullFocus = true;
11058
- const editorWithRenameWidget = await addWidgetToEditor(Rename$1, FocusEditorRename$1, editor, create$1, newStateGenerator$1, fullFocus);
11058
+ let editorWithRenameWidget;
11059
+ try {
11060
+ editorWithRenameWidget = await addWidgetToEditor(Rename$1, FocusEditorRename$1, editor, create$1, newStateGenerator$1, fullFocus);
11061
+ } catch (error) {
11062
+ await dispose$2();
11063
+ throw error;
11064
+ }
11059
11065
  if (editorWithRenameWidget === editor) {
11066
+ await dispose$2();
11060
11067
  return editor;
11061
11068
  }
11062
11069
  const wordBefore = getWordBefore(editor, rowIndex, columnIndex);
@@ -11106,12 +11113,13 @@ const redo = state => {
11106
11113
  return state;
11107
11114
  }
11108
11115
  const last = redoStack.at(-1);
11116
+ const selectionChanges = last.selectionHistory?.after;
11109
11117
  const newState = {
11110
11118
  ...state,
11111
11119
  redoStack: redoStack.slice(0, -1),
11112
11120
  undoStack: [...state.undoStack, last]
11113
11121
  };
11114
- return scheduleDocumentAndCursorsSelectionIsUndo(newState, last);
11122
+ return scheduleDocumentAndCursorsSelectionIsUndo(newState, last, selectionChanges);
11115
11123
  };
11116
11124
 
11117
11125
  // @ts-ignore
@@ -12627,12 +12635,14 @@ const typeWithAutoClosing = async (editor, text) => {
12627
12635
  };
12628
12636
 
12629
12637
  const inverseChange = edit => {
12630
- const endColumnIndex = edit.end.columnIndex - edit.deleted[0].length + edit.inserted[0].length;
12638
+ const insertedLines = edit.inserted;
12639
+ const endRowIndex = edit.start.rowIndex + insertedLines.length - 1;
12640
+ const endColumnIndex = insertedLines.length === 1 ? edit.start.columnIndex + insertedLines[0].length : insertedLines.at(-1).length;
12631
12641
  return {
12632
- deleted: edit.inserted,
12642
+ deleted: insertedLines,
12633
12643
  end: {
12634
12644
  columnIndex: endColumnIndex,
12635
- rowIndex: edit.end.rowIndex
12645
+ rowIndex: endRowIndex
12636
12646
  },
12637
12647
  inserted: edit.deleted,
12638
12648
  start: edit.start
@@ -12648,12 +12658,13 @@ const undo = state => {
12648
12658
  }
12649
12659
  const last = undoStack.at(-1);
12650
12660
  const inverseChanges = last.toReversed().map(inverseChange);
12661
+ const selectionChanges = last.selectionHistory?.before;
12651
12662
  const newState = {
12652
12663
  ...state,
12653
12664
  redoStack: [...(state.redoStack || []), last],
12654
12665
  undoStack: undoStack.slice(0, -1)
12655
12666
  };
12656
- return scheduleDocumentAndCursorsSelectionIsUndo(newState, inverseChanges);
12667
+ return scheduleDocumentAndCursorsSelectionIsUndo(newState, inverseChanges, selectionChanges);
12657
12668
  };
12658
12669
 
12659
12670
  const unfold = editor => {
@@ -16610,6 +16621,7 @@ const wrapCommand = (fn, preservesTypingCoalescing = false) => async (uid, ...ar
16610
16621
  }
16611
16622
  const newEditorWithDerivedState = await updateDerivedState(state, newEditor);
16612
16623
  set$8(uid, state, newEditorWithDerivedState);
16624
+ await dispose$2();
16613
16625
  if (editorDiagnosticEffect.isActive(state, newEditorWithDerivedState)) {
16614
16626
  void editorDiagnosticEffect.apply(newEditorWithDerivedState);
16615
16627
  }
@@ -16646,7 +16658,7 @@ const wrapCommand = (fn, preservesTypingCoalescing = false) => async (uid, ...ar
16646
16658
  if (lines !== finalEditor.lines && !isUntitledFile(finalEditor.uri)) {
16647
16659
  schedule(uid, token => saveAfterDelay(uid, token));
16648
16660
  } else if (modified && !finalEditor.modified) {
16649
- dispose$2(uid);
16661
+ dispose$3(uid);
16650
16662
  }
16651
16663
  return finalEditor;
16652
16664
  });
@@ -17401,3 +17413,5 @@ const main = async () => {
17401
17413
  };
17402
17414
 
17403
17415
  main();
17416
+
17417
+ export { offsetAt as o };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.61.4",
3
+ "version": "19.62.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"