@lvce-editor/editor-worker 3.25.0 → 3.26.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.
@@ -422,7 +422,7 @@ const positionAt = (textDocument, offset) => {
422
422
  };
423
423
 
424
424
  // TODO this should be in a separate scrolling module
425
- const setDeltaY$2 = (state, value) => {
425
+ const setDeltaY$3 = (state, value) => {
426
426
  object(state);
427
427
  number$1(value);
428
428
  const {
@@ -825,9 +825,9 @@ const applyEdit$1 = (editor, changes) => {
825
825
 
826
826
  // TODO
827
827
  const setDeltaYFixedValue$1 = (editor, value) => {
828
- return setDeltaY$2(editor, value);
828
+ return setDeltaY$3(editor, value);
829
829
  };
830
- const setDeltaY$1 = (editor, value) => {
830
+ const setDeltaY$2 = (editor, value) => {
831
831
  return setDeltaYFixedValue$1(editor, editor.deltaY + value);
832
832
  };
833
833
  const isAutoClosingChange = change => {
@@ -1855,7 +1855,7 @@ const createEditor = async ({
1855
1855
  // TODO avoid creating intermediate editors here
1856
1856
  const newEditor1 = setBounds(editor, x, y, width, height, 9);
1857
1857
  const newEditor2 = setText(newEditor1, content);
1858
- const newEditor3 = setDeltaY$2(newEditor2, 0);
1858
+ const newEditor3 = setDeltaY$3(newEditor2, 0);
1859
1859
  const newEditor4 = {
1860
1860
  ...newEditor3,
1861
1861
  focused: true
@@ -4154,8 +4154,8 @@ const handleTouchEnd = (editor, touchEvent) => {
4154
4154
  };
4155
4155
 
4156
4156
  // @ts-ignore
4157
- const setDeltaY = (editor, deltaY) => {
4158
- return setDeltaY$1(editor, deltaY);
4157
+ const setDeltaY$1 = (editor, deltaY) => {
4158
+ return setDeltaY$2(editor, deltaY);
4159
4159
  };
4160
4160
 
4161
4161
  // @ts-ignore
@@ -4174,11 +4174,11 @@ const setDelta = (editor, deltaMode, eventDeltaX, eventDeltaY) => {
4174
4174
  deltaY
4175
4175
  } = editor;
4176
4176
  if (eventDeltaX === 0) {
4177
- return setDeltaY(editor, eventDeltaY);
4177
+ return setDeltaY$1(editor, eventDeltaY);
4178
4178
  }
4179
4179
  const newDeltaX = clamp(deltaX + eventDeltaX, 0, Number.POSITIVE_INFINITY);
4180
4180
  return {
4181
- ...setDeltaY(editor, eventDeltaY),
4181
+ ...setDeltaY$1(editor, eventDeltaY),
4182
4182
  deltaX: newDeltaX
4183
4183
  };
4184
4184
  };
@@ -7457,14 +7457,48 @@ const focusPrevious = state => {
7457
7457
  return focusIndex(state, previousIndex);
7458
7458
  };
7459
7459
 
7460
- const handelWheel = (state, deltaMode, deltaY) => {
7461
- console.log({
7462
- deltaMode,
7460
+ // TODO optimize this function to return the minimum number
7461
+ // of visible items needed, e.g. when not scrolled 5 items with
7462
+ // 20px fill 100px but when scrolled 6 items are needed
7463
+ const getNumberOfVisibleItems = (listHeight, itemHeight) => {
7464
+ return Math.ceil(listHeight / itemHeight) + 1;
7465
+ };
7466
+
7467
+ const setDeltaY = (state, value) => {
7468
+ object(state);
7469
+ number$1(value);
7470
+ const {
7471
+ itemHeight,
7472
+ finalDeltaY,
7463
7473
  deltaY,
7464
- state
7465
- });
7466
- // TODO
7467
- return state;
7474
+ height,
7475
+ headerHeight
7476
+ } = state;
7477
+ const listHeight = height - headerHeight;
7478
+ const newDeltaY = clamp(value, 0, finalDeltaY);
7479
+ if (deltaY === newDeltaY) {
7480
+ return state;
7481
+ }
7482
+ // TODO when it only moves by one px, extensions don't need to be rerendered, only negative margin
7483
+ const minLineY = Math.floor(newDeltaY / itemHeight);
7484
+ const maxLineY = minLineY + getNumberOfVisibleItems(listHeight, itemHeight);
7485
+ return {
7486
+ ...state,
7487
+ deltaY: newDeltaY,
7488
+ minLineY,
7489
+ maxLineY
7490
+ };
7491
+ };
7492
+
7493
+ const handleWheel = (state, deltaMode, deltaY) => {
7494
+ number$1(deltaMode);
7495
+ number$1(deltaY);
7496
+ return setDeltaY(state, state.deltaY + deltaY);
7497
+ };
7498
+
7499
+ const handelWheel = (state, deltaMode, deltaY) => {
7500
+ const newState = handleWheel(state, deltaMode, deltaY);
7501
+ return newState;
7468
7502
  };
7469
7503
 
7470
7504
  const create = () => {
@@ -9012,7 +9046,7 @@ const commandMap = {
9012
9046
  'Editor.selectWordRight': selectWordRight,
9013
9047
  'Editor.setDecorations': setDecorations,
9014
9048
  'Editor.setDelta': setDelta,
9015
- 'Editor.setDeltaY': setDeltaY,
9049
+ 'Editor.setDeltaY': setDeltaY$1,
9016
9050
  'Editor.setLanguageId': setLanguageId,
9017
9051
  'Editor.setSelections': setSelections,
9018
9052
  'Editor.showHover': showHover,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "3.25.0",
3
+ "version": "3.26.0",
4
4
  "description": "",
5
5
  "main": "dist/editorWorkerMain.js",
6
6
  "type": "module",