@lvce-editor/editor-worker 19.74.5 → 19.74.6

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
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.6",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"