@lvce-editor/editor-worker 18.11.0 → 18.13.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.
@@ -1229,7 +1229,6 @@ const SetFocusContext$1 = 'Viewlet.setFocusContext';
1229
1229
  const SetPatches = 'Viewlet.setPatches';
1230
1230
 
1231
1231
  const FocusEditorText$1 = 12;
1232
- const FocusExplorer = 13;
1233
1232
 
1234
1233
  const {
1235
1234
  invoke: invoke$f,
@@ -1572,7 +1571,6 @@ const editorStates = create$9();
1572
1571
  const {
1573
1572
  getCommandIds,
1574
1573
  registerCommands,
1575
- wrapCommand,
1576
1574
  wrapGetter
1577
1575
  } = editorStates;
1578
1576
  const get$6 = id => {
@@ -1607,6 +1605,7 @@ const createEditor2 = (id, uri, x, y, width, height, platform, assetDir) => {
1607
1605
  completionState: '',
1608
1606
  completionTriggerCharacters: [],
1609
1607
  completionUid: 0,
1608
+ cursorInfos: [],
1610
1609
  cursorWidth: 2,
1611
1610
  debugEnabled: false,
1612
1611
  decorations: [],
@@ -1655,6 +1654,7 @@ const createEditor2 = (id, uri, x, y, width, height, platform, assetDir) => {
1655
1654
  savedSelections: [],
1656
1655
  scrollBarHeight: 0,
1657
1656
  scrollBarWidth: 0,
1657
+ selectionInfos: [],
1658
1658
  selections: new Uint32Array(),
1659
1659
  tabSize: 0,
1660
1660
  textInfos: [],
@@ -3666,6 +3666,7 @@ const setText$1 = (editor, text) => {
3666
3666
  };
3667
3667
 
3668
3668
  const emptyEditor = {
3669
+ cursorInfos: [],
3669
3670
  debugEnabled: false,
3670
3671
  decorations: [],
3671
3672
  deltaX: 0,
@@ -3685,6 +3686,7 @@ const emptyEditor = {
3685
3686
  maxLineY: 0,
3686
3687
  minLineY: 0,
3687
3688
  scrollBarHeight: 0,
3689
+ selectionInfos: [],
3688
3690
  selections: new Uint32Array(),
3689
3691
  textInfos: [],
3690
3692
  tokenizerId: 0,
@@ -3973,6 +3975,7 @@ const createEditor = async ({
3973
3975
  completionState: '',
3974
3976
  completionTriggerCharacters,
3975
3977
  completionUid: 0,
3978
+ cursorInfos: [],
3976
3979
  cursorWidth: 2,
3977
3980
  decorations: [],
3978
3981
  deltaX: 0,
@@ -4016,6 +4019,7 @@ const createEditor = async ({
4016
4019
  savedSelections,
4017
4020
  scrollBarHeight: 0,
4018
4021
  scrollBarWidth: 0,
4022
+ selectionInfos: [],
4019
4023
  selections: new Uint32Array(),
4020
4024
  tabSize,
4021
4025
  textInfos: [],
@@ -4089,7 +4093,7 @@ const isEqual$1 = (oldState, newState) => {
4089
4093
  };
4090
4094
 
4091
4095
  const isEqual = (oldState, newState) => {
4092
- return oldState.lines === newState.lines && oldState.textInfos === newState.textInfos && oldState.differences === newState.differences && oldState.initial === newState.initial;
4096
+ return oldState.lines === newState.lines && oldState.textInfos === newState.textInfos && oldState.differences === newState.differences && oldState.initial === newState.initial && oldState.selections === newState.selections;
4093
4097
  };
4094
4098
 
4095
4099
  const RenderFocus = 6;
@@ -6337,6 +6341,210 @@ const handlePointerCaptureLost = editor => {
6337
6341
  return editor;
6338
6342
  };
6339
6343
 
6344
+ const handlePointerDown$1 = (state, button, altKey, ctrlKey, x, y, detail) => {
6345
+ const modifier = 0;
6346
+ const clickDetail = Single; // TODO
6347
+ // console.log({ detail })
6348
+ switch (clickDetail) {
6349
+ case Double:
6350
+ return handleDoubleClick(state, modifier, x, y);
6351
+ case Single:
6352
+ return handleSingleClick(state, modifier, x, y);
6353
+ case Triple:
6354
+ return handleTripleClick(state, modifier, x, y);
6355
+ default:
6356
+ return state;
6357
+ }
6358
+ };
6359
+
6360
+ const moveRectangleSelection = (editor, position) => {
6361
+ // @ts-ignore
6362
+ // const anchor = EditorMoveSelection.state.position
6363
+ // const startRowIndex = anchor.rowIndex
6364
+ // const startColumnIndex = anchor.columnIndex
6365
+ // const endRowIndex = position.rowIndex
6366
+ // const endColumnIndex = position.columnIndex
6367
+ // const selectionEdits: any[] = []
6368
+ // for (let i = startRowIndex; i <= endRowIndex; i++) {
6369
+ // selectionEdits.push({
6370
+ // start: {
6371
+ // rowIndex: i,
6372
+ // columnIndex: startColumnIndex,
6373
+ // },
6374
+ // end: {
6375
+ // rowIndex: i,
6376
+ // columnIndex: endColumnIndex,
6377
+ // },
6378
+ // })
6379
+ // }
6380
+ // // @ts-ignore
6381
+ // const cursorEdits = [selectionEdits.at(-1).end]
6382
+ // // @ts-ignore
6383
+ // Editor.scheduleCursorsAndSelections(editor, cursorEdits, selectionEdits)
6384
+ return editor;
6385
+ };
6386
+
6387
+ // @ts-ignore
6388
+ const moveRectangleSelectionPx = async (editor, x, y) => {
6389
+ await at(editor, x, y);
6390
+ };
6391
+
6392
+ const requestAnimationFrame = fn => {
6393
+ globalThis.requestAnimationFrame(fn);
6394
+ };
6395
+
6396
+ const LessThan = -1;
6397
+ const Equal = 0;
6398
+ const GreaterThan = 1;
6399
+
6400
+ // @ts-ignore
6401
+
6402
+ // @ts-ignore
6403
+ const compare = (positionA, positionB) => {
6404
+ if (positionA.rowIndex > positionB.rowIndex) {
6405
+ return GreaterThan;
6406
+ }
6407
+ if (positionA.rowIndex === positionB.rowIndex) {
6408
+ if (positionA.columnIndex > positionB.columnIndex) {
6409
+ return GreaterThan;
6410
+ }
6411
+ if (positionA.columnIndex < positionB.columnIndex) {
6412
+ return LessThan;
6413
+ }
6414
+ return Equal;
6415
+ }
6416
+ return LessThan;
6417
+ };
6418
+
6419
+ // @ts-ignore
6420
+ const editorMoveSelectionBackwards = (anchor, position) => {
6421
+ return new Uint32Array([anchor.rowIndex, anchor.columnIndex, position.rowIndex, position.columnIndex]);
6422
+ };
6423
+
6424
+ // @ts-ignore
6425
+ const editorMoveSelectionEqual = (anchor, position) => {
6426
+ return new Uint32Array([position.rowIndex, position.columnIndex, position.rowIndex, position.columnIndex]);
6427
+ };
6428
+
6429
+ // @ts-ignore
6430
+ const editorMoveSelectionForwards = (anchor, position) => {
6431
+ return new Uint32Array([anchor.rowIndex, anchor.columnIndex, position.rowIndex, position.columnIndex]);
6432
+ };
6433
+
6434
+ // @ts-ignore
6435
+ const getNewSelections$5 = (anchor, position) => {
6436
+ switch (compare(position, anchor)) {
6437
+ case Equal:
6438
+ return editorMoveSelectionEqual(anchor, position);
6439
+ case GreaterThan:
6440
+ return editorMoveSelectionForwards(anchor, position);
6441
+ case LessThan:
6442
+ return editorMoveSelectionBackwards(anchor, position);
6443
+ default:
6444
+ throw new Error('unexpected comparison result');
6445
+ }
6446
+ };
6447
+
6448
+ // @ts-ignore
6449
+ const editorMoveSelection = (editor, position) => {
6450
+ const anchor = getPosition$1();
6451
+ const newSelections = getNewSelections$5(anchor, position);
6452
+ // TODO if selection equals previous selection -> do nothing
6453
+ return scheduleSelections(editor, newSelections);
6454
+ };
6455
+
6456
+ // @ts-ignore
6457
+ const getNewEditor$1 = (editor, position) => {
6458
+ const {
6459
+ maxLineY,
6460
+ minLineY,
6461
+ rowHeight
6462
+ } = editor;
6463
+ const diff = maxLineY - minLineY;
6464
+ if (position.rowIndex < minLineY) {
6465
+ const newMinLineY = position.rowIndex;
6466
+ const newMaxLineY = position.rowIndex + diff;
6467
+ const newDeltaY = position.rowIndex * rowHeight;
6468
+ const anchor = getPosition$1();
6469
+ const newSelections = new Uint32Array([position.rowIndex - 1, position.columnIndex, anchor.rowIndex, anchor.columnIndex]);
6470
+ return {
6471
+ ...editor,
6472
+ deltaY: newDeltaY,
6473
+ maxLineY: newMaxLineY,
6474
+ minLineY: newMinLineY,
6475
+ selections: newSelections
6476
+ };
6477
+ }
6478
+ if (position.rowIndex > maxLineY) {
6479
+ const diff = maxLineY - minLineY;
6480
+ const newMinLineY = position.rowIndex - diff;
6481
+ const newMaxLineY = position.rowIndex;
6482
+ const newDeltaY = newMinLineY * rowHeight;
6483
+ const anchor = getPosition$1();
6484
+ const newSelections = new Uint32Array([anchor.rowIndex, anchor.columnIndex, position.rowIndex + 1, position.columnIndex]);
6485
+ return {
6486
+ ...editor,
6487
+ deltaY: newDeltaY,
6488
+ maxLineY: newMaxLineY,
6489
+ minLineY: newMinLineY,
6490
+ selections: newSelections
6491
+ };
6492
+ }
6493
+ return editor;
6494
+ };
6495
+ const continueScrollingAndMovingSelection = async () => {
6496
+ const editor = getEditor$1();
6497
+ if (!editor) {
6498
+ return;
6499
+ }
6500
+ const position = getPosition();
6501
+ if (position.rowIndex === 0) {
6502
+ return;
6503
+ }
6504
+ const newEditor = getNewEditor$1(editor, position);
6505
+ if (editor === newEditor) {
6506
+ return;
6507
+ }
6508
+ // await Viewlet.setState(ViewletModuleId.EditorText, newEditor)
6509
+ setEditor(newEditor);
6510
+ // @ts-ignore
6511
+ const delta = position.rowIndex < editor.minLineY ? -1 : 1;
6512
+ setPosition({
6513
+ columnIndex: position.columnIndex,
6514
+ rowIndex: position.rowIndex + delta
6515
+ });
6516
+ requestAnimationFrame(continueScrollingAndMovingSelection);
6517
+ // TODO get editor state
6518
+ // if editor is disposed, return and remove animation frame
6519
+ // on cursor up, remove animation frame
6520
+ //
6521
+ };
6522
+
6523
+ // @ts-ignore
6524
+ const moveSelectionPx = async (editor, x, y) => {
6525
+ object(editor);
6526
+ number(x);
6527
+ number(y);
6528
+ const position = await at(editor, x, y);
6529
+ if (!hasListener() && (position.rowIndex < editor.minLineY || position.rowIndex > editor.maxLineY)) {
6530
+ requestAnimationFrame(continueScrollingAndMovingSelection);
6531
+ setEditor(editor);
6532
+ setPosition(position);
6533
+ }
6534
+ return editorMoveSelection(editor, position);
6535
+ };
6536
+
6537
+ const handlePointerMove = (editor, x, y, altKey) => {
6538
+ if (altKey) {
6539
+ return moveRectangleSelectionPx(editor, x, y);
6540
+ }
6541
+ return moveSelectionPx(editor, x, y);
6542
+ };
6543
+
6544
+ const handlePointerUp = editor => {
6545
+ return editor;
6546
+ };
6547
+
6340
6548
  // @ts-ignore
6341
6549
 
6342
6550
  // @ts-ignore
@@ -6738,183 +6946,6 @@ const insertLineBreak = async editor => {
6738
6946
  return scheduleDocumentAndCursorsSelections(editor, changes, selectionChanges);
6739
6947
  };
6740
6948
 
6741
- const moveRectangleSelection = (editor, position) => {
6742
- // @ts-ignore
6743
- // const anchor = EditorMoveSelection.state.position
6744
- // const startRowIndex = anchor.rowIndex
6745
- // const startColumnIndex = anchor.columnIndex
6746
- // const endRowIndex = position.rowIndex
6747
- // const endColumnIndex = position.columnIndex
6748
- // const selectionEdits: any[] = []
6749
- // for (let i = startRowIndex; i <= endRowIndex; i++) {
6750
- // selectionEdits.push({
6751
- // start: {
6752
- // rowIndex: i,
6753
- // columnIndex: startColumnIndex,
6754
- // },
6755
- // end: {
6756
- // rowIndex: i,
6757
- // columnIndex: endColumnIndex,
6758
- // },
6759
- // })
6760
- // }
6761
- // // @ts-ignore
6762
- // const cursorEdits = [selectionEdits.at(-1).end]
6763
- // // @ts-ignore
6764
- // Editor.scheduleCursorsAndSelections(editor, cursorEdits, selectionEdits)
6765
- return editor;
6766
- };
6767
-
6768
- // @ts-ignore
6769
- const moveRectangleSelectionPx = async (editor, x, y) => {
6770
- await at(editor, x, y);
6771
- };
6772
-
6773
- const LessThan = -1;
6774
- const Equal = 0;
6775
- const GreaterThan = 1;
6776
-
6777
- // @ts-ignore
6778
-
6779
- // @ts-ignore
6780
- const compare = (positionA, positionB) => {
6781
- if (positionA.rowIndex > positionB.rowIndex) {
6782
- return GreaterThan;
6783
- }
6784
- if (positionA.rowIndex === positionB.rowIndex) {
6785
- if (positionA.columnIndex > positionB.columnIndex) {
6786
- return GreaterThan;
6787
- }
6788
- if (positionA.columnIndex < positionB.columnIndex) {
6789
- return LessThan;
6790
- }
6791
- return Equal;
6792
- }
6793
- return LessThan;
6794
- };
6795
-
6796
- // @ts-ignore
6797
- const editorMoveSelectionBackwards = (anchor, position) => {
6798
- return new Uint32Array([anchor.rowIndex, anchor.columnIndex, position.rowIndex, position.columnIndex]);
6799
- };
6800
-
6801
- // @ts-ignore
6802
- const editorMoveSelectionEqual = (anchor, position) => {
6803
- return new Uint32Array([position.rowIndex, position.columnIndex, position.rowIndex, position.columnIndex]);
6804
- };
6805
-
6806
- // @ts-ignore
6807
- const editorMoveSelectionForwards = (anchor, position) => {
6808
- return new Uint32Array([anchor.rowIndex, anchor.columnIndex, position.rowIndex, position.columnIndex]);
6809
- };
6810
-
6811
- // @ts-ignore
6812
- const getNewSelections$5 = (anchor, position) => {
6813
- switch (compare(position, anchor)) {
6814
- case Equal:
6815
- return editorMoveSelectionEqual(anchor, position);
6816
- case GreaterThan:
6817
- return editorMoveSelectionForwards(anchor, position);
6818
- case LessThan:
6819
- return editorMoveSelectionBackwards(anchor, position);
6820
- default:
6821
- throw new Error('unexpected comparison result');
6822
- }
6823
- };
6824
-
6825
- // @ts-ignore
6826
- const editorMoveSelection = (editor, position) => {
6827
- const anchor = getPosition$1();
6828
- const newSelections = getNewSelections$5(anchor, position);
6829
- // TODO if selection equals previous selection -> do nothing
6830
- return scheduleSelections(editor, newSelections);
6831
- };
6832
-
6833
- const requestAnimationFrame = fn => {
6834
- globalThis.requestAnimationFrame(fn);
6835
- };
6836
-
6837
- // @ts-ignore
6838
- const getNewEditor$1 = (editor, position) => {
6839
- const {
6840
- maxLineY,
6841
- minLineY,
6842
- rowHeight
6843
- } = editor;
6844
- const diff = maxLineY - minLineY;
6845
- if (position.rowIndex < minLineY) {
6846
- const newMinLineY = position.rowIndex;
6847
- const newMaxLineY = position.rowIndex + diff;
6848
- const newDeltaY = position.rowIndex * rowHeight;
6849
- const anchor = getPosition$1();
6850
- const newSelections = new Uint32Array([position.rowIndex - 1, position.columnIndex, anchor.rowIndex, anchor.columnIndex]);
6851
- return {
6852
- ...editor,
6853
- deltaY: newDeltaY,
6854
- maxLineY: newMaxLineY,
6855
- minLineY: newMinLineY,
6856
- selections: newSelections
6857
- };
6858
- }
6859
- if (position.rowIndex > maxLineY) {
6860
- const diff = maxLineY - minLineY;
6861
- const newMinLineY = position.rowIndex - diff;
6862
- const newMaxLineY = position.rowIndex;
6863
- const newDeltaY = newMinLineY * rowHeight;
6864
- const anchor = getPosition$1();
6865
- const newSelections = new Uint32Array([anchor.rowIndex, anchor.columnIndex, position.rowIndex + 1, position.columnIndex]);
6866
- return {
6867
- ...editor,
6868
- deltaY: newDeltaY,
6869
- maxLineY: newMaxLineY,
6870
- minLineY: newMinLineY,
6871
- selections: newSelections
6872
- };
6873
- }
6874
- return editor;
6875
- };
6876
- const continueScrollingAndMovingSelection = async () => {
6877
- const editor = getEditor$1();
6878
- if (!editor) {
6879
- return;
6880
- }
6881
- const position = getPosition();
6882
- if (position.rowIndex === 0) {
6883
- return;
6884
- }
6885
- const newEditor = getNewEditor$1(editor, position);
6886
- if (editor === newEditor) {
6887
- return;
6888
- }
6889
- // await Viewlet.setState(ViewletModuleId.EditorText, newEditor)
6890
- setEditor(newEditor);
6891
- // @ts-ignore
6892
- const delta = position.rowIndex < editor.minLineY ? -1 : 1;
6893
- setPosition({
6894
- columnIndex: position.columnIndex,
6895
- rowIndex: position.rowIndex + delta
6896
- });
6897
- requestAnimationFrame(continueScrollingAndMovingSelection);
6898
- // TODO get editor state
6899
- // if editor is disposed, return and remove animation frame
6900
- // on cursor up, remove animation frame
6901
- //
6902
- };
6903
-
6904
- // @ts-ignore
6905
- const moveSelectionPx = async (editor, x, y) => {
6906
- object(editor);
6907
- number(x);
6908
- number(y);
6909
- const position = await at(editor, x, y);
6910
- if (!hasListener() && (position.rowIndex < editor.minLineY || position.rowIndex > editor.maxLineY)) {
6911
- requestAnimationFrame(continueScrollingAndMovingSelection);
6912
- setEditor(editor);
6913
- setPosition(position);
6914
- }
6915
- return editorMoveSelection(editor, position);
6916
- };
6917
-
6918
6949
  const Script = 2;
6919
6950
  const Unknown$1 = 0;
6920
6951
 
@@ -9520,23 +9551,34 @@ const InputBox = 'InputBox';
9520
9551
  const MaskIcon = 'MaskIcon';
9521
9552
  const Viewlet = 'Viewlet';
9522
9553
 
9523
- const HandleBeforeInput = 'handleBeforeInput';
9524
- const HandleBlur = 'handleBlur';
9525
- const HandleClose = 'handleClose';
9526
- const HandleCompositionEnd = 'handleCompositionEnd';
9527
- const HandleCompositionStart = 'handleCompositionStart';
9528
- const HandleCompositionUpdate = 'handleCompositionUpdate';
9529
- const HandleContextMenu = 'handleContextMenu';
9530
- const HandleCut = 'handleCut';
9531
- const HandleFocus = 'handleFocus';
9532
- const HandleMouseMove = 'handleMouseMove';
9533
- const HandleSashPointerDown = 'handleSashPointerDown';
9534
- const HandleWheel = 'handleWheel';
9554
+ const HandleBeforeInput = 1;
9555
+ const HandleBlur = 2;
9556
+ const HandleClose = 9;
9557
+ const HandleCompositionEnd = 10;
9558
+ const HandleCompositionStart = 11;
9559
+ const HandleCompositionUpdate = 12;
9560
+ const HandleContextMenu = 13;
9561
+ const HandleCut = 14;
9562
+ const HandleFocus = 15;
9563
+ const HandleMouseMove = 19;
9564
+ const HandlePaste = 20;
9565
+ const HandlePointerDown = 21;
9566
+ const HandlePointerMove = 22;
9567
+ const HandlePointerUp = 23;
9568
+ const HandleSashPointerDown = 26;
9569
+ const HandleScrollBarHorizontalPointerDown = 27;
9570
+ const HandleScrollBarHorizontalPointerMove = 28;
9571
+ const HandleScrollBarHorizontalPointerUp = 29;
9572
+ const HandleScrollBarVerticalPointerDown = 30;
9573
+ const HandleScrollBarVerticalPointerMove = 31;
9574
+ const HandleScrollBarVerticalPointerUp = 32;
9575
+ const HandleWheel = 33;
9535
9576
 
9536
9577
  const Div = 4;
9537
9578
  const Input = 6;
9538
9579
  const Span = 8;
9539
9580
  const Text = 12;
9581
+ const TextArea = 62;
9540
9582
 
9541
9583
  const text = data => {
9542
9584
  return {
@@ -9855,6 +9897,24 @@ const unsetAdditionalFocus = async focusKey => {
9855
9897
  await invoke$c('Focus.removeAdditionalFocus', focusKey);
9856
9898
  };
9857
9899
 
9900
+ const shouldUpdateSelectionData = (oldState, newState) => {
9901
+ return oldState.selections !== newState.selections || oldState.focused !== newState.focused || oldState.minLineY !== newState.minLineY || oldState.maxLineY !== newState.maxLineY || oldState.differences !== newState.differences || oldState.charWidth !== newState.charWidth || oldState.cursorWidth !== newState.cursorWidth || oldState.fontFamily !== newState.fontFamily || oldState.fontSize !== newState.fontSize || oldState.fontWeight !== newState.fontWeight || oldState.isMonospaceFont !== newState.isMonospaceFont || oldState.letterSpacing !== newState.letterSpacing || oldState.lines !== newState.lines || oldState.rowHeight !== newState.rowHeight || oldState.tabSize !== newState.tabSize || oldState.width !== newState.width;
9902
+ };
9903
+ const updateDerivedState = async (oldState, newState) => {
9904
+ if (!shouldUpdateSelectionData(oldState, newState)) {
9905
+ return newState;
9906
+ }
9907
+ const {
9908
+ cursorInfos,
9909
+ selectionInfos
9910
+ } = await getVisible(newState);
9911
+ return {
9912
+ ...newState,
9913
+ cursorInfos,
9914
+ selectionInfos
9915
+ };
9916
+ };
9917
+
9858
9918
  const FocusEditor = 12;
9859
9919
  const FocusEditorCompletions = 9;
9860
9920
  const FocusEditorRename = 11;
@@ -9916,13 +9976,14 @@ const getSelections2 = editorUid => {
9916
9976
  } = editor;
9917
9977
  return selections;
9918
9978
  };
9919
- const setSelections2 = (editorUid, selections) => {
9979
+ const setSelections2 = async (editorUid, selections) => {
9920
9980
  const editor = getEditor(editorUid);
9921
9981
  const newEditor = {
9922
9982
  ...editor,
9923
9983
  selections
9924
9984
  };
9925
- set$7(editorUid, editor, newEditor);
9985
+ const newEditorWithDerivedState = await updateDerivedState(editor, newEditor);
9986
+ set$7(editorUid, editor, newEditorWithDerivedState);
9926
9987
  };
9927
9988
  const closeWidget2 = async (editorUid, widgetId, widgetName, unsetAdditionalFocus$1) => {
9928
9989
  const editor = getEditor(editorUid);
@@ -9941,7 +10002,8 @@ const closeWidget2 = async (editorUid, widgetId, widgetName, unsetAdditionalFocu
9941
10002
  focused: true,
9942
10003
  widgets: newWidgets
9943
10004
  };
9944
- set$7(editorUid, editor, newEditor);
10005
+ const newEditorWithDerivedState = await updateDerivedState(editor, newEditor);
10006
+ set$7(editorUid, editor, newEditorWithDerivedState);
9945
10007
  await setFocus(FocusEditorText);
9946
10008
  if (unsetAdditionalFocus$1) {
9947
10009
  await unsetAdditionalFocus(unsetAdditionalFocus$1);
@@ -9953,7 +10015,8 @@ const closeFind2 = async editorUid => {
9953
10015
  const applyEdits2 = async (editorUid, edits) => {
9954
10016
  const editor = getEditor(editorUid);
9955
10017
  const newEditor = await applyEdit(editor, edits);
9956
- set$7(editorUid, editor, newEditor);
10018
+ const newEditorWithDerivedState = await updateDerivedState(editor, newEditor);
10019
+ set$7(editorUid, editor, newEditorWithDerivedState);
9957
10020
  };
9958
10021
  const getSourceActions = async editorUid => {
9959
10022
  const actions = await getEditorSourceActions(editorUid);
@@ -11026,7 +11089,7 @@ const renderFocus$2 = (oldState, newState) => {
11026
11089
  };
11027
11090
 
11028
11091
  const renderFocusContext$1 = (oldState, newState) => {
11029
- return [SetFocusContext$1, newState.uid, FocusExplorer];
11092
+ return [SetFocusContext$1, newState.uid, FocusEditorText$1];
11030
11093
  };
11031
11094
 
11032
11095
  const SetText = 1;
@@ -11412,6 +11475,29 @@ const getEditorRowsVirtualDom = (textInfos, differences, lineNumbers = true, hig
11412
11475
  return dom;
11413
11476
  };
11414
11477
 
11478
+ const getScrollBarVirtualDom = () => {
11479
+ return [{
11480
+ childCount: 1,
11481
+ className: 'ScrollBar ScrollBarVertical',
11482
+ onContextMenu: HandleContextMenu,
11483
+ onPointerDown: HandleScrollBarVerticalPointerDown,
11484
+ type: Div
11485
+ }, {
11486
+ childCount: 0,
11487
+ className: 'ScrollBarThumb ScrollBarThumbVertical',
11488
+ type: Div
11489
+ }, {
11490
+ childCount: 1,
11491
+ className: 'ScrollBar ScrollBarHorizontal',
11492
+ onPointerDown: HandleScrollBarHorizontalPointerDown,
11493
+ type: Div
11494
+ }, {
11495
+ childCount: 0,
11496
+ className: 'ScrollBarThumb ScrollBarThumbHorizontal',
11497
+ type: Div
11498
+ }];
11499
+ };
11500
+
11415
11501
  const getSelectionsVirtualDom = selections => {
11416
11502
  const dom = [];
11417
11503
  for (let i = 0; i < selections.length; i += 4) {
@@ -11452,9 +11538,12 @@ const getEditorVirtualDom = ({
11452
11538
  const diagnosticsDom = getDiagnosticsVirtualDom(diagnosticsArray);
11453
11539
  const gutterDom = getEditorGutterVirtualDom(gutterInfosArray);
11454
11540
  const scrollBarDiagnosticsDom = getDiagnosticsVirtualDom(scrollBarDiagnosticsArray);
11541
+ const scrollBarDom = getScrollBarVirtualDom();
11455
11542
  return [{
11456
11543
  childCount: 2,
11457
11544
  className: 'Viewlet Editor',
11545
+ onContextMenu: HandleContextMenu,
11546
+ onWheel: HandleWheel,
11458
11547
  role: 'code',
11459
11548
  type: Div
11460
11549
  }, {
@@ -11462,9 +11551,32 @@ const getEditorVirtualDom = ({
11462
11551
  className: 'Gutter',
11463
11552
  type: Div
11464
11553
  }, ...gutterDom, {
11465
- childCount: 4,
11554
+ childCount: 5,
11466
11555
  className: 'EditorContent',
11556
+ onMouseMove: HandleMouseMove,
11467
11557
  type: Div
11558
+ }, {
11559
+ ariaAutoComplete: 'list',
11560
+ ariaMultiLine: 'true',
11561
+ ariaRoleDescription: 'editor',
11562
+ autocapitalize: 'off',
11563
+ autocomplete: 'off',
11564
+ autocorrect: 'off',
11565
+ childCount: 0,
11566
+ className: 'EditorInput',
11567
+ name: 'editor',
11568
+ onBeforeInput: HandleBeforeInput,
11569
+ onBlur: HandleBlur,
11570
+ onCompositionEnd: HandleCompositionEnd,
11571
+ onCompositionStart: HandleCompositionStart,
11572
+ onCompositionUpdate: HandleCompositionUpdate,
11573
+ onCut: HandleCut,
11574
+ onFocus: HandleFocus,
11575
+ onPaste: HandlePaste,
11576
+ role: 'textbox',
11577
+ spellcheck: false,
11578
+ type: TextArea,
11579
+ wrap: 'off'
11468
11580
  }, {
11469
11581
  childCount: 4,
11470
11582
  className: 'EditorLayers',
@@ -11476,6 +11588,8 @@ const getEditorVirtualDom = ({
11476
11588
  }, ...selectionsDom, {
11477
11589
  childCount: textInfos.length,
11478
11590
  className: 'EditorRows',
11591
+ // onMouseDown: DomEventListenerFunctions.HandleMouseDown,
11592
+ onPointerDown: HandlePointerDown,
11479
11593
  type: Div
11480
11594
  }, ...rowsDom, {
11481
11595
  childCount: cursorsDom.length,
@@ -11489,27 +11603,15 @@ const getEditorVirtualDom = ({
11489
11603
  childCount: scrollBarDiagnosticsDom.length,
11490
11604
  className: 'EditorScrollBarDiagnostics',
11491
11605
  type: Div
11492
- }, ...scrollBarDiagnosticsDom, {
11493
- childCount: 1,
11494
- className: 'ScrollBar ScrollBarVertical',
11495
- type: Div
11496
- }, {
11497
- childCount: 0,
11498
- className: 'ScrollBarThumb ScrollBarThumbVertical',
11499
- type: Div
11500
- }, {
11501
- childCount: 1,
11502
- className: 'ScrollBar ScrollBarHorizontal',
11503
- type: Div
11504
- }, {
11505
- childCount: 0,
11506
- className: 'ScrollBarThumb ScrollBarThumbHorizontal',
11507
- type: Div
11508
- }];
11606
+ }, ...scrollBarDiagnosticsDom, ...scrollBarDom];
11509
11607
  };
11510
11608
 
11511
11609
  const getDom = state => {
11512
- if (state.initial && state.textInfos.length === 0) {
11610
+ const {
11611
+ initial,
11612
+ textInfos
11613
+ } = state;
11614
+ if (initial && textInfos.length === 0) {
11513
11615
  return [];
11514
11616
  }
11515
11617
  return getEditorVirtualDom(state);
@@ -11606,17 +11708,17 @@ const renderLines = {
11606
11708
  }
11607
11709
  };
11608
11710
  const renderSelections = {
11609
- apply: async (oldState, newState) => {
11711
+ apply: (oldState, newState) => {
11610
11712
  const {
11611
- cursorInfos,
11612
- selectionInfos
11613
- } = await getVisible(newState);
11713
+ cursorInfos = [],
11714
+ selectionInfos = []
11715
+ } = newState;
11614
11716
  const cursorsDom = getCursorsVirtualDom(cursorInfos);
11615
11717
  const selectionsDom = getSelectionsVirtualDom(selectionInfos);
11616
11718
  return [/* method */'setSelections', cursorsDom, selectionsDom];
11617
11719
  },
11618
11720
  isEqual(oldState, newState) {
11619
- return oldState.selections === newState.selections && oldState.focused === newState.focused && oldState.minLineY === newState.minLineY && oldState.deltaX === newState.deltaX;
11721
+ return oldState.cursorInfos === newState.cursorInfos && oldState.selectionInfos === newState.selectionInfos;
11620
11722
  }
11621
11723
  };
11622
11724
  const renderScrollBarY = {
@@ -11785,13 +11887,14 @@ const renderEventListeners = () => {
11785
11887
  params: ['handleFocus']
11786
11888
  }, {
11787
11889
  name: HandleMouseMove,
11788
- params: ['handleInput', ClientX, ClientY, AltKey]
11890
+ params: ['handleMouseMove', ClientX, ClientY, AltKey]
11789
11891
  }, {
11790
11892
  name: HandleBlur,
11791
11893
  params: ['handleBlur']
11792
11894
  }, {
11793
11895
  name: HandleBeforeInput,
11794
- params: ['handleBeforeInput', 'event.inputType', 'event.data']
11896
+ params: ['handleBeforeInput', 'event.inputType', 'event.data'],
11897
+ preventDefault: true
11795
11898
  }, {
11796
11899
  name: HandleCompositionStart,
11797
11900
  params: ['compositionStart', 'event.data']
@@ -11800,11 +11903,25 @@ const renderEventListeners = () => {
11800
11903
  params: ['compositionUpdate', 'event.data']
11801
11904
  }, {
11802
11905
  name: HandleCompositionEnd,
11803
- params: ['compositionUpdate', 'event.data']
11906
+ params: ['compositionEnd', 'event.data']
11804
11907
  }, {
11805
11908
  name: HandleCut,
11806
11909
  params: ['cut'],
11807
11910
  preventDefault: true
11911
+ }, {
11912
+ name: HandlePaste,
11913
+ params: ['paste', 'event.clipboardData ? event.clipboardData.getData("text/plain") : ""'],
11914
+ preventDefault: true
11915
+ }, {
11916
+ name: HandlePointerDown,
11917
+ params: ['handlePointerDown', 'event.button', 'event.altKey', 'event.ctrlKey', ClientX, ClientY],
11918
+ trackPointerEvents: [HandlePointerMove, HandlePointerUp]
11919
+ }, {
11920
+ name: HandlePointerMove,
11921
+ params: ['handlePointerMove', ClientX, ClientY, AltKey]
11922
+ }, {
11923
+ name: HandlePointerUp,
11924
+ params: ['handlePointerUp']
11808
11925
  }, {
11809
11926
  name: HandleWheel,
11810
11927
  params: ['setDelta', DeltaMode, DeltaY],
@@ -11813,6 +11930,26 @@ const renderEventListeners = () => {
11813
11930
  name: HandleContextMenu,
11814
11931
  params: ['handleContextMenu', Button, ClientX, ClientY],
11815
11932
  preventDefault: true
11933
+ }, {
11934
+ name: HandleScrollBarVerticalPointerDown,
11935
+ params: ['handleScrollBarVerticalPointerDown', ClientY],
11936
+ trackPointerEvents: [HandleScrollBarVerticalPointerMove, HandleScrollBarVerticalPointerUp]
11937
+ }, {
11938
+ name: HandleScrollBarVerticalPointerMove,
11939
+ params: ['handleScrollBarVerticalPointerMove', ClientY]
11940
+ }, {
11941
+ name: HandleScrollBarVerticalPointerUp,
11942
+ params: ['handlePointerUp']
11943
+ }, {
11944
+ name: HandleScrollBarHorizontalPointerDown,
11945
+ params: ['handleScrollBarHorizontalPointerDown', ClientX],
11946
+ trackPointerEvents: [HandleScrollBarHorizontalPointerMove, HandleScrollBarHorizontalPointerUp]
11947
+ }, {
11948
+ name: HandleScrollBarHorizontalPointerMove,
11949
+ params: ['handleScrollBarHorizontalMove', ClientX]
11950
+ }, {
11951
+ name: HandleScrollBarHorizontalPointerUp,
11952
+ params: ['handlePointerUp']
11816
11953
  }];
11817
11954
  };
11818
11955
 
@@ -11874,6 +12011,25 @@ const updateDebugInfo = async debugId => {
11874
12011
  await invoke$c('Editor.rerender', key);
11875
12012
  };
11876
12013
 
12014
+ // TODO wrap commands globally, not per editor
12015
+ // TODO only store editor state in editor worker, not in renderer worker also
12016
+
12017
+ const wrapCommand = fn => async (editorUid, ...args) => {
12018
+ const oldInstance = get$6(editorUid);
12019
+ const state = oldInstance.newState;
12020
+ const newEditor = await fn(state, ...args);
12021
+ if (state === newEditor) {
12022
+ return newEditor;
12023
+ }
12024
+ const newEditorWithDerivedState = await updateDerivedState(state, newEditor);
12025
+ // TODO if editor did not change, no need to update furthur
12026
+
12027
+ // TODO combine neweditor with latest editor?
12028
+
12029
+ set$7(editorUid, state, newEditorWithDerivedState);
12030
+ return newEditorWithDerivedState;
12031
+ };
12032
+
11877
12033
  const wrapCommandOld = wrapCommand;
11878
12034
  const commandMap = {
11879
12035
  'ActivateByEvent.activateByEvent': activateByEvent,
@@ -11960,7 +12116,7 @@ const commandMap = {
11960
12116
  'Editor.handleBeforeInput': wrapCommandOld(handleBeforeInput),
11961
12117
  'Editor.handleBeforeInputFromContentEditable': wrapCommandOld(handleBeforeInputFromContentEditable),
11962
12118
  'Editor.handleBlur': wrapCommandOld(handleBlur$1),
11963
- 'Editor.handleClickAtPosition': handleClickAtPosition,
12119
+ 'Editor.handleClickAtPosition': wrapCommandOld(handleClickAtPosition),
11964
12120
  'Editor.handleContextMenu': wrapCommandOld(handleContextMenu),
11965
12121
  'Editor.handleDoubleClick': wrapCommandOld(handleDoubleClick),
11966
12122
  'Editor.handleFocus': wrapCommandOld(handleFocus$1),
@@ -11969,6 +12125,9 @@ const commandMap = {
11969
12125
  'Editor.handleMouseMoveWithAltKey': wrapCommandOld(handleMouseMoveWithAltKey),
11970
12126
  'Editor.handleNativeSelectionChange': editorHandleNativeSelectionChange,
11971
12127
  'Editor.handlePointerCaptureLost': wrapCommandOld(handlePointerCaptureLost),
12128
+ 'Editor.handlePointerDown': wrapCommandOld(handlePointerDown$1),
12129
+ 'Editor.handlePointerMove': wrapCommandOld(handlePointerMove),
12130
+ 'Editor.handlePointerUp': wrapCommandOld(handlePointerUp),
11972
12131
  'Editor.handleScrollBarClick': handleScrollBarPointerDown,
11973
12132
  'Editor.handleScrollBarHorizontalMove': wrapCommandOld(handleScrollBarHorizontalMove),
11974
12133
  'Editor.handleScrollBarHorizontalPointerDown': wrapCommandOld(handleScrollBarHorizontalPointerDown),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "18.11.0",
3
+ "version": "18.13.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"