@lvce-editor/editor-worker 19.74.5 → 19.74.7

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.
@@ -6097,26 +6097,45 @@ const updateHorizontalLayout = async state => {
6097
6097
  const previous = caches.get(owner);
6098
6098
  const previousWidths = previous?.font === font ? previous.widths : undefined;
6099
6099
  const widths = new Map();
6100
- let longestLineWidth = 0;
6100
+ const textsToMeasure = new Set();
6101
+ const textByLine = new Map();
6101
6102
  for (const line of lines) {
6102
- let measured = widths.get(line) ?? previousWidths?.get(line);
6103
- if (measured === undefined) {
6104
- measured = await measureTextWidth(line.replaceAll('\t', () => ' '.repeat(tabSize)), fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, charWidth);
6103
+ const measured = previousWidths?.get(line);
6104
+ if (measured !== undefined) {
6105
+ widths.set(line, measured);
6106
+ continue;
6105
6107
  }
6106
- widths.set(line, measured);
6107
- longestLineWidth = Math.max(longestLineWidth, measured);
6108
+ const text = line.replaceAll('\t', () => ' '.repeat(tabSize));
6109
+ textByLine.set(line, text);
6110
+ textsToMeasure.add(text);
6108
6111
  }
6109
6112
  const showGutter = lineNumbers || breakPoints.length > 0 || lightBulbRowIndex >= 0 || gutterDecorations.length > 0;
6110
6113
  const gutterText = String(lines.length);
6111
- let gutterWidth = 0;
6112
- if (showGutter) {
6113
- const measured = widths.get(gutterText) ?? previousWidths?.get(gutterText) ?? (await measureTextWidth(gutterText, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, charWidth));
6114
- widths.set(gutterText, measured);
6115
- gutterWidth = Math.max(30, measured + 1);
6114
+ if (showGutter && !widths.has(gutterText)) {
6115
+ const measured = previousWidths?.get(gutterText);
6116
+ if (measured === undefined) {
6117
+ textsToMeasure.add(gutterText);
6118
+ } else {
6119
+ widths.set(gutterText, measured);
6120
+ }
6121
+ }
6122
+ const texts = [...textsToMeasure];
6123
+ const measuredWidths = texts.length > 0 ? await measureTextWidths(texts, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, charWidth) : [];
6124
+ const measuredByText = new Map(texts.map((text, index) => [text, measuredWidths[index]]));
6125
+ for (const [line, text] of textByLine) {
6126
+ widths.set(line, measuredByText.get(text));
6127
+ }
6128
+ if (showGutter && !widths.has(gutterText)) {
6129
+ widths.set(gutterText, measuredByText.get(gutterText));
6130
+ }
6131
+ let longestLineWidth = 0;
6132
+ for (const line of lines) {
6133
+ longestLineWidth = Math.max(longestLineWidth, widths.get(line));
6116
6134
  }
6117
6135
  if (lifecycle?.disposed) {
6118
6136
  return state;
6119
6137
  }
6138
+ const gutterWidth = showGutter ? Math.max(30, widths.get(gutterText) + 1) : 0;
6120
6139
  caches.set(owner, {
6121
6140
  font,
6122
6141
  widths
@@ -9546,14 +9565,18 @@ const getColorPickerBounds = editor => {
9546
9565
  const newStateGenerator$3 = (state, parentUid) => {
9547
9566
  return loadContent$3(state, parentUid);
9548
9567
  };
9549
- const openColorPicker = async editor => {
9568
+ const openColorPicker = async (editor, initialColor) => {
9550
9569
  const fullFocus = true;
9551
9570
  const bounds = getColorPickerBounds(editor);
9552
9571
  const {
9553
9572
  getColorPickerRange
9554
9573
  } = await Promise.resolve().then(function () { return GetColorPickerRange; });
9555
9574
  const range = await getColorPickerRange(editor);
9556
- const createWidget = () => create$5(bounds, range, editor.undoStack.length);
9575
+ const colorRange = initialColor === undefined ? range : {
9576
+ ...range,
9577
+ value: initialColor
9578
+ };
9579
+ const createWidget = () => create$5(bounds, colorRange, editor.undoStack.length);
9557
9580
  return addWidgetToEditor(ColorPicker$2, ColorPicker, editor, createWidget, newStateGenerator$3, fullFocus);
9558
9581
  };
9559
9582
  const closeColorPicker = editor => {
@@ -17602,6 +17625,8 @@ const loadContent = async (state, savedState, largeFile = false, focus = true, f
17602
17625
  tabSize,
17603
17626
  tokenizerId: state.tokenizerId
17604
17627
  };
17628
+ const snapshot = savedState;
17629
+ const hotReload = snapshot?.hotReload === true && Array.isArray(snapshot.lines) && snapshot.lines.every(line => typeof line === 'string');
17605
17630
  let existingEditor;
17606
17631
  if (!forceReload) {
17607
17632
  for (const key of getKeys$2()) {
@@ -17615,7 +17640,10 @@ const loadContent = async (state, savedState, largeFile = false, focus = true, f
17615
17640
  let content = existingEditor ? getText$1(existingEditor) : '';
17616
17641
  let endOfLine = existingEditor?.endOfLine || 'lf';
17617
17642
  try {
17618
- if (!existingEditor) {
17643
+ if (!existingEditor && hotReload) {
17644
+ content = snapshot.lines.join('\n');
17645
+ endOfLine = snapshot.endOfLine === 'crlf' ? 'crlf' : 'lf';
17646
+ } else if (!existingEditor) {
17619
17647
  content = await readFile(state.applicationId, uri, forceReload, state.editorFileCacheEnabled === true);
17620
17648
  endOfLine = getEndOfLine(content);
17621
17649
  content = normalizeLineEndings(content);
@@ -17699,7 +17727,7 @@ const loadContent = async (state, savedState, largeFile = false, focus = true, f
17699
17727
  ...newEditor4,
17700
17728
  completionsOnType: !largeFile && completionsOnType,
17701
17729
  initial: false,
17702
- modified: existingEditor?.modified || false,
17730
+ modified: existingEditor?.modified || hotReload && snapshot.modified === true,
17703
17731
  redoStack: existingEditor?.redoStack || savedHistory?.redoStack || [],
17704
17732
  undoStack: existingEditor?.undoStack || savedHistory?.undoStack || []
17705
17733
  };
@@ -19396,12 +19424,16 @@ const save = async (uid, skipFormatting = false) => {
19396
19424
  }
19397
19425
  };
19398
19426
 
19399
- const saveState = async (state, savedState) => {
19427
+ const saveState = async (state, hotReload) => {
19400
19428
  const {
19429
+ deltaY,
19430
+ endOfLine,
19401
19431
  explicitLanguageId,
19402
19432
  largeFile,
19403
19433
  lines,
19434
+ modified,
19404
19435
  redoStack,
19436
+ selections,
19405
19437
  undoStack,
19406
19438
  widgets: stateWidgets
19407
19439
  } = state;
@@ -19421,7 +19453,7 @@ const saveState = async (state, savedState) => {
19421
19453
  state: widgetState
19422
19454
  });
19423
19455
  }
19424
- return {
19456
+ const savedState = {
19425
19457
  ...(explicitLanguageId && {
19426
19458
  explicitLanguageId
19427
19459
  }),
@@ -19437,6 +19469,20 @@ const saveState = async (state, savedState) => {
19437
19469
  undoStack
19438
19470
  })
19439
19471
  };
19472
+ if (hotReload !== true) {
19473
+ return savedState;
19474
+ }
19475
+ return {
19476
+ ...savedState,
19477
+ deltaY,
19478
+ endOfLine,
19479
+ hotReload: true,
19480
+ lines,
19481
+ modified,
19482
+ redoStack,
19483
+ selections: [...selections],
19484
+ undoStack
19485
+ };
19440
19486
  };
19441
19487
 
19442
19488
  const sendMessagePortToExtensionManagementWorker = async (port, rpcId) => {
@@ -344,7 +344,17 @@
344
344
  "description": "Enables tab completions",
345
345
  "heading": "Tab Completion",
346
346
  "id": "editor.tabCompletion",
347
- "type": "string",
347
+ "options": [
348
+ {
349
+ "id": "on",
350
+ "label": "On"
351
+ },
352
+ {
353
+ "id": "off",
354
+ "label": "off"
355
+ }
356
+ ],
357
+ "type": "enum",
348
358
  "value": "on"
349
359
  },
350
360
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.74.5",
3
+ "version": "19.74.7",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"