@lvce-editor/editor-worker 19.72.1 → 19.72.3

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.
@@ -4155,18 +4155,15 @@ const getX = async (line, column, fontWeight, fontSize, fontFamily, isMonospaceF
4155
4155
  number(averageCharWidth);
4156
4156
  number(difference);
4157
4157
  if (column === 0) {
4158
- return 0;
4158
+ return difference === 0 ? 0 : Math.min(width, difference);
4159
4159
  }
4160
4160
  // TODO support non-monospace font, emoji, tab character, zero width characters
4161
- if (column * averageCharWidth > width) {
4162
- return width;
4163
- }
4164
4161
  const normalize = shouldNormalizeText(line);
4165
4162
  const normalizedLine = normalizeText(line, normalize, tabSize);
4166
4163
  const tabCount = getTabCount(line.slice(0, column));
4167
- const partialText = normalizedLine.slice(0, column + tabCount);
4164
+ const partialText = normalizedLine.slice(0, column + tabCount * (tabSize - 1));
4168
4165
  const textWidth = await measureTextWidth(partialText, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, averageCharWidth);
4169
- return textWidth - halfCursorWidth + difference;
4166
+ return Math.min(width, textWidth - halfCursorWidth + difference);
4170
4167
  };
4171
4168
 
4172
4169
  const px = value => {
@@ -4278,7 +4275,6 @@ const getVisible = async editor => {
4278
4275
  charWidth,
4279
4276
  cursorWidth,
4280
4277
  deltaY,
4281
- differences,
4282
4278
  focused,
4283
4279
  foldingRanges = [],
4284
4280
  fontFamily,
@@ -4307,7 +4303,7 @@ const getVisible = async editor => {
4307
4303
  const startVisualRow = itemHeight ? Math.floor(deltaY / itemHeight) : getVisualRow(minLineY);
4308
4304
  const endVisualRow = startVisualRow + (visibleViewLineIndices?.length || actualVisibleLineIndices.length);
4309
4305
  const getRelativeRow = rowIndex => getVisualRow(rowIndex) - startVisualRow;
4310
- const getDifference = rowIndex => differences[actualVisibleLineIndices.indexOf(rowIndex)];
4306
+ const horizontalOffset = -(editor.deltaX ?? 0);
4311
4307
  for (let i = 0; i < selections.length; i += 4) {
4312
4308
  const [selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn, reversed] = getSelectionPairs(selections, i);
4313
4309
  const selectionStartVisualRow = getVisualRow(selectionStartRow);
@@ -4316,7 +4312,7 @@ const getVisible = async editor => {
4316
4312
  continue;
4317
4313
  }
4318
4314
  const relativeEndLineRow = getRelativeRow(selectionEndRow);
4319
- const endLineDifference = getDifference(selectionEndRow);
4315
+ const endLineDifference = horizontalOffset;
4320
4316
  const endLine = lines[selectionEndRow];
4321
4317
  const endLineEndX = await getX(endLine, selectionEndColumn, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, averageCharWidth, endLineDifference);
4322
4318
  const endLineY = relativeEndLineRow * rowHeight;
@@ -4326,7 +4322,7 @@ const getVisible = async editor => {
4326
4322
  }
4327
4323
  const startLineYRelative = getRelativeRow(selectionStartRow);
4328
4324
  const startLineY = startLineYRelative * rowHeight;
4329
- const startLineDifference = getDifference(selectionStartRow);
4325
+ const startLineDifference = horizontalOffset;
4330
4326
  if (selectionStartRow === selectionEndRow) {
4331
4327
  const startX = await getX(endLine, selectionStartColumn, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, averageCharWidth, startLineDifference);
4332
4328
  if (reversed) {
@@ -4353,7 +4349,7 @@ const getVisible = async editor => {
4353
4349
  const currentLine = lines[rowIndex];
4354
4350
  const relativeLine = getRelativeRow(rowIndex);
4355
4351
  const currentLineY = relativeLine * rowHeight;
4356
- const difference = getDifference(rowIndex);
4352
+ const difference = horizontalOffset;
4357
4353
  const selectionWidth = await getX(currentLine, currentLine.length, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, averageCharWidth, difference);
4358
4354
  visibleSelections.push(0, currentLineY, selectionWidth, rowHeight);
4359
4355
  }
@@ -5315,6 +5311,7 @@ const getVisibleDiagnostics = async (editor, diagnostics) => {
5315
5311
  const visibleDiagnostics = [];
5316
5312
  const {
5317
5313
  charWidth,
5314
+ deltaX = 0,
5318
5315
  deltaY,
5319
5316
  fontFamily,
5320
5317
  fontSize,
@@ -5325,8 +5322,7 @@ const getVisibleDiagnostics = async (editor, diagnostics) => {
5325
5322
  lines,
5326
5323
  rowHeight,
5327
5324
  tabSize,
5328
- viewLineIndices,
5329
- width
5325
+ viewLineIndices
5330
5326
  } = editor;
5331
5327
  const startVisualRow = itemHeight ? Math.floor(deltaY / itemHeight) : editor.minLineY || 0;
5332
5328
  for (const diagnostic of diagnostics) {
@@ -5335,10 +5331,10 @@ const getVisibleDiagnostics = async (editor, diagnostics) => {
5335
5331
  endColumnIndex,
5336
5332
  rowIndex
5337
5333
  } = diagnostic;
5338
- const endLineDifference = 0;
5334
+ const endLineDifference = -deltaX;
5339
5335
  const halfCursorWidth = 0;
5340
- const x = await getX(lines[rowIndex], columnIndex, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, charWidth, endLineDifference);
5341
- const endX = await getX(lines[rowIndex], endColumnIndex, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, charWidth, endLineDifference);
5336
+ const x = await getX(lines[rowIndex], columnIndex, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, Infinity, charWidth, endLineDifference);
5337
+ const endX = await getX(lines[rowIndex], endColumnIndex, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, Infinity, charWidth, endLineDifference);
5342
5338
  const diagnosticWidth = Math.max(charWidth, endX - x);
5343
5339
  const visualRow = viewLineIndices ? getVisualRowForDocumentRow$1(rowIndex, viewLineIndices) : rowIndex;
5344
5340
  const y = (visualRow - startVisualRow) * rowHeight;
@@ -5417,10 +5413,10 @@ const updateHorizontalLayout = async state => {
5417
5413
  };
5418
5414
 
5419
5415
  const shouldUpdateDiagnosticData = (oldState, newState) => {
5420
- return oldState.diagnostics !== newState.diagnostics || (newState.diagnostics?.length ?? 0) > 0 && (oldState.minLineY !== newState.minLineY || oldState.charWidth !== newState.charWidth || oldState.fontFamily !== newState.fontFamily || oldState.fontSize !== newState.fontSize || oldState.fontWeight !== newState.fontWeight || oldState.isMonospaceFont !== newState.isMonospaceFont || oldState.letterSpacing !== newState.letterSpacing || oldState.lines !== newState.lines || oldState.rowHeight !== newState.rowHeight || oldState.tabSize !== newState.tabSize || oldState.width !== newState.width);
5416
+ return oldState.diagnostics !== newState.diagnostics || (newState.diagnostics?.length ?? 0) > 0 && (oldState.deltaX !== newState.deltaX || oldState.minLineY !== newState.minLineY || oldState.charWidth !== newState.charWidth || oldState.fontFamily !== newState.fontFamily || oldState.fontSize !== newState.fontSize || oldState.fontWeight !== newState.fontWeight || oldState.isMonospaceFont !== newState.isMonospaceFont || oldState.letterSpacing !== newState.letterSpacing || oldState.lines !== newState.lines || oldState.rowHeight !== newState.rowHeight || oldState.tabSize !== newState.tabSize || oldState.width !== newState.width);
5421
5417
  };
5422
5418
  const shouldUpdateSelectionData = (oldState, newState) => {
5423
- return oldState.selections !== newState.selections || oldState.focused !== newState.focused || oldState.minLineY !== newState.minLineY || oldState.maxLineY !== newState.maxLineY || oldState.visibleViewLineIndices !== newState.visibleViewLineIndices || oldState.foldingRanges !== newState.foldingRanges || oldState.differences !== newState.differences || oldState.charWidth !== newState.charWidth || oldState.cursorWidth !== newState.cursorWidth || oldState.fontFamily !== newState.fontFamily || oldState.fontSize !== newState.fontSize || oldState.fontWeight !== newState.fontWeight || oldState.isMonospaceFont !== newState.isMonospaceFont || oldState.letterSpacing !== newState.letterSpacing || oldState.lines !== newState.lines || oldState.rowHeight !== newState.rowHeight || oldState.tabSize !== newState.tabSize || oldState.width !== newState.width;
5419
+ return oldState.selections !== newState.selections || oldState.focused !== newState.focused || oldState.deltaX !== newState.deltaX || oldState.minLineY !== newState.minLineY || oldState.maxLineY !== newState.maxLineY || oldState.visibleViewLineIndices !== newState.visibleViewLineIndices || oldState.foldingRanges !== newState.foldingRanges || oldState.differences !== newState.differences || oldState.charWidth !== newState.charWidth || oldState.cursorWidth !== newState.cursorWidth || oldState.fontFamily !== newState.fontFamily || oldState.fontSize !== newState.fontSize || oldState.fontWeight !== newState.fontWeight || oldState.isMonospaceFont !== newState.isMonospaceFont || oldState.letterSpacing !== newState.letterSpacing || oldState.lines !== newState.lines || oldState.rowHeight !== newState.rowHeight || oldState.tabSize !== newState.tabSize || oldState.width !== newState.width;
5424
5420
  };
5425
5421
  const shouldUpdateBracketMatchData = (oldState, newState) => {
5426
5422
  if (!('bracketMatchInfos' in newState)) {
@@ -8319,7 +8315,7 @@ const cancelSelection = editor => {
8319
8315
  return scheduleSelections(editor, newSelections);
8320
8316
  };
8321
8317
 
8322
- const colorPattern = /#[\dA-Fa-f]+/g;
8318
+ const colorPattern$2 = /#[\dA-Fa-f]+/g;
8323
8319
  const numberPattern = /(?<![\w.#])[+-]?(?:(?:\d+(?:\.\d*)?)|(?:\.\d+))(?:[eE][+-]?\d+)?(?![\d.])/g;
8324
8320
  const validColorLengths = new Set([4, 5, 7, 9]);
8325
8321
  const isColor = value => {
@@ -8402,7 +8398,7 @@ const findMatchAt = (line, columnIndex, pattern, predicate) => {
8402
8398
  return undefined;
8403
8399
  };
8404
8400
  const findValueAt = (line, columnIndex) => {
8405
- return findMatchAt(line, columnIndex, colorPattern, isColor) ?? findMatchAt(line, columnIndex, numberPattern, isNumber);
8401
+ return findMatchAt(line, columnIndex, colorPattern$2, isColor) ?? findMatchAt(line, columnIndex, numberPattern, isNumber);
8406
8402
  };
8407
8403
  const getSelectionTarget = (editor, index) => {
8408
8404
  const selectionStartRow = editor.selections[index];
@@ -8770,7 +8766,7 @@ const openColorPicker = async editor => {
8770
8766
  const bounds = getColorPickerBounds(editor);
8771
8767
  const {
8772
8768
  getColorPickerRange
8773
- } = await import('./GetColorPickerRange-CsGZK202.js');
8769
+ } = await Promise.resolve().then(function () { return GetColorPickerRange; });
8774
8770
  const range = await getColorPickerRange(editor);
8775
8771
  const createWidget = () => create$6(bounds, range, editor.undoStack.length);
8776
8772
  return addWidgetToEditor(ColorPicker$2, ColorPicker, editor, createWidget, newStateGenerator$5, fullFocus);
@@ -11413,10 +11409,17 @@ const continueScrollingAndMovingSelection = async editorUid => {
11413
11409
  return;
11414
11410
  }
11415
11411
  set$a(editor.uid, editor, derivedEditor);
11412
+ await invoke$d('Editor.renderPending', editor.uid);
11416
11413
  if (derivedEditor.hasListener) {
11417
11414
  requestAnimationFrame(() => continueScrollingAndMovingSelection(editorUid));
11418
11415
  }
11419
11416
  };
11417
+ const scheduleInitialSelectionAutoScroll = editorUid => {
11418
+ // Let the wrapped pointer-move command commit hasListener before the loop reads state.
11419
+ requestAnimationFrame(() => {
11420
+ requestAnimationFrame(() => continueScrollingAndMovingSelection(editorUid));
11421
+ });
11422
+ };
11420
11423
  const moveSelectionPx = async (editor, x, y) => {
11421
11424
  object(editor);
11422
11425
  number(x);
@@ -11432,7 +11435,7 @@ const moveSelectionPx = async (editor, x, y) => {
11432
11435
  };
11433
11436
  }
11434
11437
  if (!editor.hasListener) {
11435
- requestAnimationFrame(() => continueScrollingAndMovingSelection(editor.uid));
11438
+ scheduleInitialSelectionAutoScroll(editor.uid);
11436
11439
  }
11437
11440
  return {
11438
11441
  ...newEditor,
@@ -15393,6 +15396,20 @@ const getPositionAtCursor = editorUid => {
15393
15396
  const editor = getEditor$1(editorUid);
15394
15397
  return getPositionAtCursor$1(editor);
15395
15398
  };
15399
+ const getCompletionContext = (editorUid, includeLine = false) => {
15400
+ const editor = getEditor$1(editorUid);
15401
+ const position = getPositionAtCursor$1(editor);
15402
+ if (!includeLine) {
15403
+ return {
15404
+ ...position,
15405
+ wordBefore: getWordBefore(editor, position.rowIndex, position.columnIndex)
15406
+ };
15407
+ }
15408
+ return {
15409
+ ...position,
15410
+ line: editor.lines[position.rowIndex] || ''
15411
+ };
15412
+ };
15396
15413
  const getUri = editorUid => {
15397
15414
  const editor = getEditor$1(editorUid);
15398
15415
  return editor.uri;
@@ -18773,6 +18790,7 @@ const commandMap = {
18773
18790
  'Editor.fold': wrapCommand(fold$1),
18774
18791
  'Editor.format': wrapCommand(format),
18775
18792
  'Editor.getCommandIds': getCommandIds,
18793
+ 'Editor.getCompletionContext': getCompletionContext,
18776
18794
  'Editor.getDiagnostics': getDiagnostics,
18777
18795
  'Editor.getKeyBindings': getKeyBindings,
18778
18796
  'Editor.getKeys': getKeys,
@@ -19446,4 +19464,100 @@ const main = async () => {
19446
19464
 
19447
19465
  main();
19448
19466
 
19449
- export { offsetAt as o };
19467
+ const noColorRange = {
19468
+ endOffset: -1,
19469
+ startOffset: -1,
19470
+ value: ''
19471
+ };
19472
+ const colorPattern$1 = /#[\da-f]{3,8}\b|(?<![\w$])0x[\da-f]{6}(?![\w$])|\b(?:hsla?|rgba?)\([^)]*\)/gi;
19473
+ const getColorPickerRange = async editor => {
19474
+ const {
19475
+ lines,
19476
+ selections
19477
+ } = editor;
19478
+ if (!selections || selections.length < 4) {
19479
+ return noColorRange;
19480
+ }
19481
+ const selectionStartRow = selections[0];
19482
+ const selectionEndRow = selections[2];
19483
+ if (selectionStartRow !== selectionEndRow) {
19484
+ return noColorRange;
19485
+ }
19486
+ const selectionStartColumn = selections[1];
19487
+ const selectionEndColumn = selections[3];
19488
+ const rowIndex = selectionEndRow;
19489
+ const line = lines[rowIndex];
19490
+ if (typeof line !== 'string') {
19491
+ return noColorRange;
19492
+ }
19493
+ if (selectionStartColumn !== selectionEndColumn) {
19494
+ const startColumn = Math.min(selectionStartColumn, selectionEndColumn);
19495
+ const endColumn = Math.max(selectionStartColumn, selectionEndColumn);
19496
+ return {
19497
+ endOffset: offsetAt(editor, rowIndex, endColumn),
19498
+ startOffset: offsetAt(editor, rowIndex, startColumn),
19499
+ value: line.slice(startColumn, endColumn)
19500
+ };
19501
+ }
19502
+ const columnIndex = selectionEndColumn;
19503
+ for (const match of line.matchAll(colorPattern$1)) {
19504
+ const startColumn = match.index;
19505
+ const endColumn = startColumn + match[0].length;
19506
+ if (columnIndex >= startColumn && columnIndex <= endColumn) {
19507
+ return {
19508
+ endOffset: offsetAt(editor, rowIndex, endColumn),
19509
+ startOffset: offsetAt(editor, rowIndex, startColumn),
19510
+ value: match[0]
19511
+ };
19512
+ }
19513
+ }
19514
+ const {
19515
+ getNamedColorRange
19516
+ } = await Promise.resolve().then(function () { return GetNamedColorRange; });
19517
+ const namedColorRange = getNamedColorRange(line, columnIndex);
19518
+ if (!namedColorRange) {
19519
+ return noColorRange;
19520
+ }
19521
+ return {
19522
+ endOffset: offsetAt(editor, rowIndex, namedColorRange.end),
19523
+ startOffset: offsetAt(editor, rowIndex, namedColorRange.start),
19524
+ value: namedColorRange.value
19525
+ };
19526
+ };
19527
+
19528
+ const GetColorPickerRange = {
19529
+ __proto__: null,
19530
+ getColorPickerRange
19531
+ };
19532
+
19533
+ const colorPattern = /\b[a-z]+\b/gi;
19534
+ const getNamedColorRange = (line, columnIndex) => {
19535
+ for (const match of line.matchAll(colorPattern)) {
19536
+ const start = match.index;
19537
+ const end = start + match[0].length;
19538
+ if (columnIndex < start || columnIndex > end || line[start - 1] === '-' || line[end] === '-') {
19539
+ continue;
19540
+ }
19541
+ const value = match[0];
19542
+ if (value.toLowerCase() === 'currentcolor') {
19543
+ return undefined;
19544
+ }
19545
+ const context = new OffscreenCanvas(1, 1).getContext('2d');
19546
+ context.fillStyle = '#010203';
19547
+ context.fillStyle = value;
19548
+ if (context.fillStyle === '#010203') {
19549
+ return undefined;
19550
+ }
19551
+ return {
19552
+ end,
19553
+ start,
19554
+ value
19555
+ };
19556
+ }
19557
+ return undefined;
19558
+ };
19559
+
19560
+ const GetNamedColorRange = {
19561
+ __proto__: null,
19562
+ getNamedColorRange
19563
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.72.1",
3
+ "version": "19.72.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"
@@ -1,64 +0,0 @@
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|(?<![\w$])0x[\da-f]{6}(?![\w$])|\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 };
@@ -1,28 +0,0 @@
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 };