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