@lvce-editor/editor-worker 19.74.4 → 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.
@@ -2369,7 +2369,13 @@ const getHorizontalScrollDimensions = ({
2369
2369
  };
2370
2370
 
2371
2371
  const defaultThreshold = 500;
2372
+ const simpleAscii = /^[\t -~]*$/;
2372
2373
  const getSegments = line => {
2374
+ if (simpleAscii.test(line)) {
2375
+ return Array.from({
2376
+ length: line.length + 1
2377
+ }, (_, index) => index);
2378
+ }
2373
2379
  if (typeof Intl.Segmenter === 'function') {
2374
2380
  // @ts-ignore
2375
2381
  return [...Array.from(new Intl.Segmenter(undefined, {
@@ -6091,26 +6097,45 @@ const updateHorizontalLayout = async state => {
6091
6097
  const previous = caches.get(owner);
6092
6098
  const previousWidths = previous?.font === font ? previous.widths : undefined;
6093
6099
  const widths = new Map();
6094
- let longestLineWidth = 0;
6100
+ const textsToMeasure = new Set();
6101
+ const textByLine = new Map();
6095
6102
  for (const line of lines) {
6096
- let measured = widths.get(line) ?? previousWidths?.get(line);
6097
- if (measured === undefined) {
6098
- 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;
6099
6107
  }
6100
- widths.set(line, measured);
6101
- longestLineWidth = Math.max(longestLineWidth, measured);
6108
+ const text = line.replaceAll('\t', () => ' '.repeat(tabSize));
6109
+ textByLine.set(line, text);
6110
+ textsToMeasure.add(text);
6102
6111
  }
6103
6112
  const showGutter = lineNumbers || breakPoints.length > 0 || lightBulbRowIndex >= 0 || gutterDecorations.length > 0;
6104
6113
  const gutterText = String(lines.length);
6105
- let gutterWidth = 0;
6106
- if (showGutter) {
6107
- const measured = widths.get(gutterText) ?? previousWidths?.get(gutterText) ?? (await measureTextWidth(gutterText, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, charWidth));
6108
- widths.set(gutterText, measured);
6109
- 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));
6110
6134
  }
6111
6135
  if (lifecycle?.disposed) {
6112
6136
  return state;
6113
6137
  }
6138
+ const gutterWidth = showGutter ? Math.max(30, widths.get(gutterText) + 1) : 0;
6114
6139
  caches.set(owner, {
6115
6140
  font,
6116
6141
  widths
@@ -8866,6 +8891,26 @@ const wrapFocusCommand$1 = (fn, returnState = true) => {
8866
8891
  };
8867
8892
  };
8868
8893
 
8894
+ // Mouse positions are replaceable; edits and explicit navigation remain ordered.
8895
+ // Check before starting provider work and again before committing its result.
8896
+ const wrapLatestCommand$1 = (fn, returnState = true) => {
8897
+ const latest = new Map();
8898
+ return async (uid, ...args) => {
8899
+ const token = {};
8900
+ latest.set(uid, token);
8901
+ const command = wrapCommand$1(async editor => {
8902
+ if (latest.get(uid) !== token) return editor;
8903
+ const result = await fn(editor, ...args);
8904
+ return latest.get(uid) === token ? result : editor;
8905
+ }, false, returnState);
8906
+ try {
8907
+ return await command(uid);
8908
+ } finally {
8909
+ if (latest.get(uid) === token) latest.delete(uid);
8910
+ }
8911
+ };
8912
+ };
8913
+
8869
8914
  // Optional provider work must not hold the editing queue while another worker responds.
8870
8915
  const wrapDeferredCommand$1 = (fn, returnState = true) => {
8871
8916
  const apply = wrapCommand$1((editor, snapshot, result) => merge(editor, snapshot, result), false, returnState);
@@ -19486,6 +19531,9 @@ const wrapFocusCommand = fn => {
19486
19531
  const wrapDeferredCommand = fn => {
19487
19532
  return wrapDeferredCommand$1(fn, false);
19488
19533
  };
19534
+ const wrapLatestCommand = fn => {
19535
+ return wrapLatestCommand$1(fn, false);
19536
+ };
19489
19537
 
19490
19538
  const executeViewletCommand = (uid, commandId, ...args) => {
19491
19539
  return executeViewletCommand$1(commandMap, uid, commandId, ...args);
@@ -19644,8 +19692,8 @@ const commandMap = {
19644
19692
  'Editor.handleMouseDown': wrapCommand(handleMouseDown),
19645
19693
  'Editor.handleMouseEnter': handleMouseEnter,
19646
19694
  'Editor.handleMouseLeave': handleMouseLeave,
19647
- 'Editor.handleMouseMove': wrapCommand(handleMouseMove),
19648
- 'Editor.handleMouseMoveWithAltKey': wrapCommand(handleMouseMoveWithAltKey),
19695
+ 'Editor.handleMouseMove': wrapLatestCommand(handleMouseMove),
19696
+ 'Editor.handleMouseMoveWithAltKey': wrapLatestCommand(handleMouseMoveWithAltKey),
19649
19697
  'Editor.handleNativeSelectionChange': editorHandleNativeSelectionChange,
19650
19698
  'Editor.handlePointerCaptureLost': wrapCommand(handlePointerCaptureLost),
19651
19699
  'Editor.handlePointerDown': wrapCommand(handlePointerDown$1),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.74.4",
3
+ "version": "19.74.6",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"