@lvce-editor/editor-worker 19.51.1 → 19.53.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.
@@ -5249,8 +5249,8 @@ const createEditor2 = (id, uri, x, y, width, height, platform, assetDir) => {
5249
5249
  rowIndex: 0
5250
5250
  },
5251
5251
  selectionAutoMovePosition: {
5252
- columnIndex: 0,
5253
- rowIndex: 0
5252
+ x: 0,
5253
+ y: 0
5254
5254
  },
5255
5255
  selectionInfos: [],
5256
5256
  selections: new Uint32Array(),
@@ -5326,8 +5326,8 @@ const emptyEditor = {
5326
5326
  rowIndex: 0
5327
5327
  },
5328
5328
  selectionAutoMovePosition: {
5329
- columnIndex: 0,
5330
- rowIndex: 0
5329
+ x: 0,
5330
+ y: 0
5331
5331
  },
5332
5332
  selectionInfos: [],
5333
5333
  selections: new Uint32Array(),
@@ -5420,7 +5420,8 @@ const getLanguages = async (platform, assetDir) => {
5420
5420
  };
5421
5421
 
5422
5422
  const measureCharacterWidth = async (fontWeight, fontSize, fontFamily, letterSpacing) => {
5423
- return await measureTextWidth('a', fontWeight, fontSize, fontFamily, letterSpacing, false, 0);
5423
+ const width = await measureTextWidth('a', fontWeight, fontSize, fontFamily, letterSpacing, false, 0);
5424
+ return width + letterSpacing;
5424
5425
  };
5425
5426
 
5426
5427
  const normalizeLineEndings = content => {
@@ -5548,8 +5549,8 @@ const createEditor = async ({
5548
5549
  rowIndex: 0
5549
5550
  },
5550
5551
  selectionAutoMovePosition: {
5551
- columnIndex: 0,
5552
- rowIndex: 0
5552
+ x: 0,
5553
+ y: 0
5553
5554
  },
5554
5555
  selectionInfos: [],
5555
5556
  selections: new Uint32Array(),
@@ -6435,7 +6436,7 @@ const format = async editor => {
6435
6436
  };
6436
6437
 
6437
6438
  // @ts-ignore
6438
- const getNewEditor$1 = async editor => {
6439
+ const getNewEditor = async editor => {
6439
6440
  return editor;
6440
6441
  };
6441
6442
 
@@ -6501,7 +6502,7 @@ const save = async editor => {
6501
6502
  platform,
6502
6503
  uri
6503
6504
  } = editor;
6504
- const newEditor = await getNewEditor$1(editor);
6505
+ const newEditor = await getNewEditor(editor);
6505
6506
  const content = applyLineEndings(getText$1(newEditor), newEditor.endOfLine);
6506
6507
  if (isUntitledFile(uri)) {
6507
6508
  const pickedFilePath = await saveUntitledFile(uri, content, platform);
@@ -7366,10 +7367,7 @@ const copy$1 = async editor => {
7366
7367
  lines,
7367
7368
  selections
7368
7369
  } = editor;
7369
- const selectionStartRowIndex = selections[0];
7370
- const selectionStartColumnIndex = selections[1];
7371
- const selectionEndRowIndex = selections[2];
7372
- const selectionEndColumnIndex = selections[3];
7370
+ const [selectionStartRowIndex, selectionStartColumnIndex, selectionEndRowIndex, selectionEndColumnIndex] = getSelectionPairs(selections, 0);
7373
7371
  const copyFullLine = shouldCopyFullLine(selectionStartRowIndex, selectionStartColumnIndex, selectionEndRowIndex, selectionEndColumnIndex);
7374
7372
  const range = getSelectionRange(lines, copyFullLine, selectionStartRowIndex, selectionStartColumnIndex, selectionEndRowIndex, selectionEndColumnIndex);
7375
7373
  const selectedLines = getSelectionText(editor, range);
@@ -9531,8 +9529,8 @@ const handlePointerCaptureLost = async editor => {
9531
9529
  hasListener: false,
9532
9530
  isSelecting: false,
9533
9531
  selectionAutoMovePosition: {
9534
- columnIndex: 0,
9535
- rowIndex: 0
9532
+ x: 0,
9533
+ y: 0
9536
9534
  },
9537
9535
  textDragDropPosition: {
9538
9536
  columnIndex: 0,
@@ -9642,96 +9640,84 @@ const getNewSelections$5 = (anchor, position) => {
9642
9640
  };
9643
9641
 
9644
9642
  // @ts-ignore
9645
- const editorMoveSelection = (editor, position) => {
9643
+ const editorMoveSelection = (editor, position, scroll = true) => {
9646
9644
  const anchor = editor.selectionAnchorPosition;
9647
9645
  const newSelections = getNewSelections$5(anchor, position);
9648
9646
  // TODO if selection equals previous selection -> do nothing
9649
- return scheduleSelections(editor, newSelections);
9647
+ return scroll ? scheduleSelections(editor, newSelections) : {
9648
+ ...editor,
9649
+ selections: newSelections
9650
+ };
9650
9651
  };
9651
9652
 
9652
- // @ts-ignore
9653
- const getNewEditor = (editor, position) => {
9653
+ const advanceSelectionAutoScroll = async editor => {
9654
9654
  const {
9655
- maxLineY,
9656
- minLineY,
9657
- rowHeight
9658
- } = editor;
9659
- const diff = maxLineY - minLineY;
9660
- if (position.rowIndex < minLineY) {
9661
- const newMinLineY = position.rowIndex;
9662
- const newMaxLineY = position.rowIndex + diff;
9663
- const newDeltaY = position.rowIndex * rowHeight;
9664
- const anchor = editor.selectionAnchorPosition;
9665
- const newSelections = new Uint32Array([position.rowIndex - 1, position.columnIndex, anchor.rowIndex, anchor.columnIndex]);
9655
+ x,
9656
+ y
9657
+ } = editor.selectionAutoMovePosition;
9658
+ const bottom = editor.y + editor.height;
9659
+ if (y >= editor.y && y <= bottom) {
9666
9660
  return {
9667
9661
  ...editor,
9668
- deltaY: newDeltaY,
9669
- maxLineY: newMaxLineY,
9670
- minLineY: newMinLineY,
9671
- selections: newSelections
9662
+ hasListener: false
9672
9663
  };
9673
9664
  }
9674
- if (position.rowIndex > maxLineY) {
9675
- const diff = maxLineY - minLineY;
9676
- const newMinLineY = position.rowIndex - diff;
9677
- const newMaxLineY = position.rowIndex;
9678
- const newDeltaY = newMinLineY * rowHeight;
9679
- const anchor = editor.selectionAnchorPosition;
9680
- const newSelections = new Uint32Array([anchor.rowIndex, anchor.columnIndex, position.rowIndex + 1, position.columnIndex]);
9665
+ const deltaY = (y - (y < editor.y ? editor.y : bottom)) * 0.1;
9666
+ const scrolledEditor = await setDeltaY$1(editor, editor.deltaY + deltaY);
9667
+ if (scrolledEditor === editor) {
9681
9668
  return {
9682
9669
  ...editor,
9683
- deltaY: newDeltaY,
9684
- maxLineY: newMaxLineY,
9685
- minLineY: newMinLineY,
9686
- selections: newSelections
9670
+ hasListener: false
9687
9671
  };
9688
9672
  }
9689
- return editor;
9673
+ const selectionY = Math.max(editor.y, Math.min(y, bottom - 1));
9674
+ const position = await at(scrolledEditor, x, selectionY);
9675
+ return editorMoveSelection(scrolledEditor, position, false);
9690
9676
  };
9691
9677
  const continueScrollingAndMovingSelection = async editorUid => {
9692
- const editorState = get$8(editorUid);
9693
- const editor = editorState?.newState;
9694
- if (!editor || !editor.hasListener || !editor.isSelecting) {
9678
+ const editor = get$8(editorUid)?.newState;
9679
+ if (!editor?.isSelecting || !editor.hasListener) {
9695
9680
  return;
9696
9681
  }
9697
- const position = editor.selectionAutoMovePosition;
9698
- if (position.rowIndex === 0) {
9682
+ const nextEditor = await advanceSelectionAutoScroll(editor);
9683
+ const derivedEditor = await updateDerivedState(editor, nextEditor);
9684
+ const currentEditor = get$8(editorUid)?.newState;
9685
+ if (currentEditor !== editor) {
9686
+ if (currentEditor?.isSelecting && currentEditor.hasListener) {
9687
+ requestAnimationFrame(() => continueScrollingAndMovingSelection(editorUid));
9688
+ }
9699
9689
  return;
9700
9690
  }
9701
- const newEditor = getNewEditor(editor, position);
9702
- if (editor === newEditor) {
9703
- return;
9691
+ set$8(editor.uid, editor, derivedEditor);
9692
+ if (derivedEditor.hasListener) {
9693
+ requestAnimationFrame(() => continueScrollingAndMovingSelection(editorUid));
9704
9694
  }
9705
- // @ts-ignore
9706
- const delta = position.rowIndex < editor.minLineY ? -1 : 1;
9707
- const nextEditor = {
9708
- ...newEditor,
9709
- selectionAutoMovePosition: {
9710
- columnIndex: position.columnIndex,
9711
- rowIndex: position.rowIndex + delta
9712
- }
9713
- };
9714
- const newEditorWithDerivedState = await updateDerivedState(editor, nextEditor);
9715
- set$8(editor.uid, editor, newEditorWithDerivedState);
9716
- requestAnimationFrame(() => continueScrollingAndMovingSelection(editorUid));
9717
9695
  };
9718
-
9719
- // @ts-ignore
9720
9696
  const moveSelectionPx = async (editor, x, y) => {
9721
9697
  object(editor);
9722
9698
  number(x);
9723
9699
  number(y);
9724
- const position = await at(editor, x, y);
9700
+ const bottom = editor.y + editor.height;
9701
+ const selectionY = Math.max(editor.y, Math.min(y, bottom - 1));
9702
+ const position = await at(editor, x, selectionY);
9725
9703
  const newEditor = editorMoveSelection(editor, position);
9726
- if (!editor.hasListener && (position.rowIndex < editor.minLineY || position.rowIndex > editor.maxLineY)) {
9727
- requestAnimationFrame(() => continueScrollingAndMovingSelection(editor.uid));
9704
+ if (y >= editor.y && y <= bottom) {
9728
9705
  return {
9729
9706
  ...newEditor,
9730
- hasListener: true,
9731
- selectionAutoMovePosition: position
9707
+ hasListener: false
9732
9708
  };
9733
9709
  }
9734
- return newEditor;
9710
+ if (!editor.hasListener) {
9711
+ requestAnimationFrame(() => continueScrollingAndMovingSelection(editor.uid));
9712
+ }
9713
+ return {
9714
+ ...newEditor,
9715
+ hasListener: true,
9716
+ selectionAutoMovePosition: {
9717
+ x,
9718
+ y
9719
+ }
9720
+ };
9735
9721
  };
9736
9722
 
9737
9723
  const handlePointerMove = async (editor, x, y, altKey) => {
@@ -9808,8 +9794,8 @@ const handlePointerUp = async editor => {
9808
9794
  hasListener: false,
9809
9795
  isSelecting: false,
9810
9796
  selectionAutoMovePosition: {
9811
- columnIndex: 0,
9812
- rowIndex: 0
9797
+ x: 0,
9798
+ y: 0
9813
9799
  },
9814
9800
  textDragDropPosition: {
9815
9801
  columnIndex: 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.51.1",
3
+ "version": "19.53.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"