@univerjs/sheets-formula-ui 1.0.3 → 1.0.4

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.
package/lib/cjs/index.js CHANGED
@@ -999,7 +999,7 @@ const menuSchema = {
999
999
  //#endregion
1000
1000
  //#region package.json
1001
1001
  var name = "@univerjs/sheets-formula-ui";
1002
- var version = "1.0.3";
1002
+ var version = "1.0.4";
1003
1003
 
1004
1004
  //#endregion
1005
1005
  //#region src/config/config.ts
@@ -1582,6 +1582,10 @@ let FormulaEditorShowController = class FormulaEditorShowController extends _uni
1582
1582
  if (range == null) return true;
1583
1583
  const { startRow, startColumn, endRow, endColumn } = range;
1584
1584
  if (rowIndex === row && columnIndex === col) {
1585
+ result = {
1586
+ ...cellInfo,
1587
+ isInArrayFormulaRange: false
1588
+ };
1585
1589
  this._createArrayFormulaRangeShape(range, unitId, subUnitId);
1586
1590
  return false;
1587
1591
  }
@@ -1772,15 +1776,17 @@ function registerFormulaEditorRuntimePortal(options) {
1772
1776
  let registeredPortalRoot = null;
1773
1777
  let disposed = false;
1774
1778
  const tryRegister = () => {
1779
+ var _options$editorServic;
1775
1780
  if (disposed) return;
1776
- const portalRoot = resolveFormulaEditorPortalRoot(options.editorId, ownerDocument);
1781
+ const selection = (_options$editorServic = options.editorService.getEditor(options.editorId)) === null || _options$editorServic === void 0 ? void 0 : _options$editorServic.docSelectionRenderService;
1782
+ const portalRoot = (selection === null || selection === void 0 ? void 0 : selection.selectionContainer.isConnected) ? selection.selectionContainer : null;
1777
1783
  if (portalRoot === registeredPortalRoot) return;
1778
1784
  portalRegistration === null || portalRegistration === void 0 || portalRegistration.dispose();
1779
1785
  portalRegistration = void 0;
1780
1786
  registeredPortalRoot = null;
1781
- if (!portalRoot) return;
1787
+ if (!portalRoot || !selection) return;
1782
1788
  registeredPortalRoot = portalRoot;
1783
- portalRegistration = registerFormulaEditorPortalRoot(options, ownerDocument, portalRoot);
1789
+ portalRegistration = registerFormulaEditorPortalRoot(options, selection);
1784
1790
  };
1785
1791
  const scheduleRetry = (remaining) => {
1786
1792
  if (remaining <= 0 || !(view === null || view === void 0 ? void 0 : view.requestAnimationFrame)) return;
@@ -1816,13 +1822,9 @@ function registerFormulaEditorRuntimePortal(options) {
1816
1822
  }));
1817
1823
  return collection;
1818
1824
  }
1819
- function resolveFormulaEditorPortalRoot(editorId, ownerDocument) {
1820
- return ownerDocument.getElementById(`univer-doc-selection-container-${editorId}`) ?? ownerDocument.getElementById(`__editor_${editorId}`);
1821
- }
1822
- function registerFormulaEditorPortalRoot(options, ownerDocument, portalRoot) {
1825
+ function registerFormulaEditorPortalRoot(options, selection) {
1823
1826
  const collection = new _univerjs_core.DisposableCollection();
1824
- const editorElement = ownerDocument.getElementById(`__editor_${options.editorId}`);
1825
- (editorElement && editorElement !== portalRoot ? [portalRoot, editorElement] : [portalRoot]).forEach((element) => {
1827
+ [selection.selectionContainer, selection.inputElement].forEach((element) => {
1826
1828
  if (options.interactionBoundaryService) collection.add(options.interactionBoundaryService.registerOwnedElement(options.embedId, element));
1827
1829
  if (options.focusCoordinator) collection.add(options.focusCoordinator.registerElement({
1828
1830
  embedId: options.embedId,
@@ -1862,7 +1864,7 @@ function focusFormulaEditor(editorService, editor, offset) {
1862
1864
  if (!editor) return;
1863
1865
  const selections = [...editor.getSelectionRanges()];
1864
1866
  editorService.focus(editor.getEditorId());
1865
- focusFormulaEditorElement(editor);
1867
+ editor.docSelectionRenderService.focus();
1866
1868
  if (editor.docSelectionRenderService.isOnPointerEvent) return;
1867
1869
  if (_univerjs_core.Tools.isDefine(offset)) editor.setSelectionRanges([{
1868
1870
  startOffset: offset,
@@ -1878,16 +1880,7 @@ function focusFormulaEditor(editorService, editor, offset) {
1878
1880
  }]);
1879
1881
  } else editor.setSelectionRanges(selections);
1880
1882
  }
1881
- function focusFormulaEditorElement(editor) {
1882
- var _editor$editorDOM;
1883
- const editorElement = (((_editor$editorDOM = editor.editorDOM) === null || _editor$editorDOM === void 0 ? void 0 : _editor$editorDOM.ownerDocument) ?? document).getElementById(`__editor_${editor.getEditorId()}`);
1884
- editorElement === null || editorElement === void 0 || editorElement.focus({ preventScroll: true });
1885
- }
1886
- function shouldSkipFormulaEditorMouseUpFocus(_target) {
1887
- return false;
1888
- }
1889
1883
  function shouldRefocusFormulaEditorOnMouseUp(options) {
1890
- if (shouldSkipFormulaEditorMouseUpFocus(options.target)) return false;
1891
1884
  if (options.isPointerSelecting || options.isFocusing) return false;
1892
1885
  return true;
1893
1886
  }
@@ -1975,18 +1968,16 @@ let RefSelectionsRenderService = class RefSelectionsRenderService extends _unive
1975
1968
  if (evt.button !== 2) state.stopPropagation();
1976
1969
  }));
1977
1970
  listenerDisposables.add(spreadsheetRowHeader === null || spreadsheetRowHeader === void 0 ? void 0 : spreadsheetRowHeader.onPointerDown$.subscribeEvent((evt, state) => {
1978
- if (!this.inRefSelectionMode()) return;
1979
1971
  const skeleton = this._sheetSkeletonManagerService.getCurrentSkeleton();
1980
- if (!skeleton) return;
1972
+ if (!this.inRefSelectionMode() || !skeleton) return;
1981
1973
  const { row } = (0, _univerjs_sheets_ui.getCoordByOffset)(evt.offsetX, evt.offsetY, scene, skeleton);
1982
1974
  if ((0, _univerjs_sheets_ui.checkInHeaderRanges)(this._workbookSelections.getCurrentSelections(), row, _univerjs_core.RANGE_TYPE.ROW)) return;
1983
1975
  this._onPointerDown(evt, (spreadsheet.zIndex || 1) + 1, _univerjs_core.RANGE_TYPE.ROW, this._getActiveViewport(evt), _univerjs_engine_render.ScrollTimerType.Y);
1984
1976
  if (evt.button !== 2) state.stopPropagation();
1985
1977
  }));
1986
1978
  listenerDisposables.add(spreadsheetColumnHeader === null || spreadsheetColumnHeader === void 0 ? void 0 : spreadsheetColumnHeader.onPointerDown$.subscribeEvent((evt, state) => {
1987
- if (!this.inRefSelectionMode()) return;
1988
1979
  const skeleton = this._sheetSkeletonManagerService.getCurrentSkeleton();
1989
- if (!skeleton) return;
1980
+ if (!this.inRefSelectionMode() || !skeleton) return;
1990
1981
  const { column } = (0, _univerjs_sheets_ui.getCoordByOffset)(evt.offsetX, evt.offsetY, scene, skeleton);
1991
1982
  if ((0, _univerjs_sheets_ui.checkInHeaderRanges)(this._workbookSelections.getCurrentSelections(), column, _univerjs_core.RANGE_TYPE.COLUMN)) return;
1992
1983
  this._onPointerDown(evt, (spreadsheet.zIndex || 1) + 1, _univerjs_core.RANGE_TYPE.COLUMN, this._getActiveViewport(evt), _univerjs_engine_render.ScrollTimerType.X);
@@ -1994,9 +1985,8 @@ let RefSelectionsRenderService = class RefSelectionsRenderService extends _unive
1994
1985
  }));
1995
1986
  listenerDisposables.add(spreadsheetLeftTopPlaceholder === null || spreadsheetLeftTopPlaceholder === void 0 ? void 0 : spreadsheetLeftTopPlaceholder.onPointerDown$.subscribeEvent((evt, state) => {
1996
1987
  this._reset();
1997
- if (!this.inRefSelectionMode()) return;
1998
1988
  const skeleton = this._sheetSkeletonManagerService.getCurrentSkeleton();
1999
- if (!skeleton) return;
1989
+ if (!this.inRefSelectionMode() || !skeleton) return;
2000
1990
  const selectionWithStyle = (0, _univerjs_sheets_ui.getAllSelection)(skeleton);
2001
1991
  this._addSelectionControlByModelData(selectionWithStyle);
2002
1992
  this._selectionMoveStart$.next(this.getSelectionDataWithStyle());
@@ -2162,7 +2152,7 @@ let RefSelectionsRenderService = class RefSelectionsRenderService extends _unive
2162
2152
  endRow: activeSelectionControl.model.endRow,
2163
2153
  endColumn: activeSelectionControl.model.endColumn
2164
2154
  } : null;
2165
- const remainLastEnable = this._remainLastEnabled && !evt.ctrlKey && !evt.metaKey && !evt.shiftKey && !this._skipLastEnabled && !this._singleSelectionEnabled;
2155
+ const remainLastEnable = this._remainLastEnabled && !this._isMultiSelectModifier(evt) && !evt.shiftKey && !this._skipLastEnabled && !this._singleSelectionEnabled;
2166
2156
  if (expandByShiftKey && currentCell) this._makeSelectionByTwoCells(currentCell, cursorCellRangeWithRangeType, skeleton, rangeType, activeSelectionControl);
2167
2157
  else if (remainLastEnable && activeSelectionControl) activeSelectionControl.updateRangeBySelectionWithCoord(selectionCellWithCoord);
2168
2158
  else activeSelectionControl = this.newSelectionControl(scene, skeleton, selectionWithStyle);
@@ -2735,8 +2725,8 @@ const useLeftAndRightArrow = (isNeed, shouldMoveSelection, editor, onMoveInEdito
2735
2725
  if (keycode === _univerjs_ui.KeyCode.ARROW_DOWN) direction = _univerjs_core.Direction.DOWN;
2736
2726
  else if (keycode === _univerjs_ui.KeyCode.ARROW_UP) direction = _univerjs_core.Direction.UP;
2737
2727
  else if (keycode === _univerjs_ui.KeyCode.ARROW_RIGHT) direction = _univerjs_core.Direction.RIGHT;
2738
- if (metaKey === _univerjs_ui.MetaKeys.SHIFT) commandService.executeCommand(_univerjs_docs_ui.MoveSelectionOperation.id, { direction });
2739
- else commandService.executeCommand(_univerjs_docs_ui.MoveCursorOperation.id, { direction });
2728
+ if (metaKey === _univerjs_ui.MetaKeys.SHIFT) return commandService.syncExecuteCommand(_univerjs_docs_ui.MoveSelectionOperation.id, { direction });
2729
+ else return commandService.syncExecuteCommand(_univerjs_docs_ui.MoveCursorOperation.id, { direction });
2740
2730
  };
2741
2731
  const handleKeycode = (keycode, metaKey) => {
2742
2732
  let direction = _univerjs_core.Direction.DOWN;
@@ -2746,35 +2736,38 @@ const useLeftAndRightArrow = (isNeed, shouldMoveSelection, editor, onMoveInEdito
2746
2736
  else if (keycode === _univerjs_ui.KeyCode.ARROW_RIGHT) direction = _univerjs_core.Direction.RIGHT;
2747
2737
  if (shouldMoveSelectionRef.current) {
2748
2738
  var _getRefSelectionCount;
2749
- const fromCurrentSelection = shouldMoveFormulaSelectionFromCurrentSelection(shouldMoveSelectionRef.current, ((_getRefSelectionCount = getRefSelectionCountRef.current) === null || _getRefSelectionCount === void 0 ? void 0 : _getRefSelectionCount.call(getRefSelectionCountRef)) ?? 0);
2750
- if (metaKey === _univerjs_ui.MetaKeys.CTRL_COMMAND) commandService.executeCommand(_univerjs_sheets_ui.MoveSelectionCommand.id, {
2739
+ const refSelectionCount = ((_getRefSelectionCount = getRefSelectionCountRef.current) === null || _getRefSelectionCount === void 0 ? void 0 : _getRefSelectionCount.call(getRefSelectionCountRef)) ?? 0;
2740
+ const fromCurrentSelection = shouldMoveFormulaSelectionFromCurrentSelection(shouldMoveSelectionRef.current, refSelectionCount);
2741
+ if (metaKey === _univerjs_ui.MetaKeys.CTRL_COMMAND) return commandService.executeCommand(_univerjs_sheets_ui.MoveSelectionCommand.id, {
2751
2742
  direction,
2752
2743
  jumpOver: _univerjs_sheets_ui.JumpOver.moveGap,
2753
2744
  extra: "formula-editor",
2754
2745
  fromCurrentSelection
2755
2746
  });
2756
- else if (metaKey === _univerjs_ui.MetaKeys.SHIFT) commandService.executeCommand(_univerjs_sheets_ui.ExpandSelectionCommand.id, {
2747
+ else if (metaKey === _univerjs_ui.MetaKeys.SHIFT) return commandService.executeCommand(_univerjs_sheets_ui.ExpandSelectionCommand.id, {
2757
2748
  direction,
2758
- extra: "formula-editor"
2749
+ extra: "formula-editor",
2750
+ fromCurrentSelection: refSelectionCount === 0
2759
2751
  });
2760
- else if (metaKey === (_univerjs_ui.MetaKeys.CTRL_COMMAND | _univerjs_ui.MetaKeys.SHIFT)) commandService.executeCommand(_univerjs_sheets_ui.ExpandSelectionCommand.id, {
2752
+ else if (metaKey === (_univerjs_ui.MetaKeys.CTRL_COMMAND | _univerjs_ui.MetaKeys.SHIFT)) return commandService.executeCommand(_univerjs_sheets_ui.ExpandSelectionCommand.id, {
2761
2753
  direction,
2762
2754
  jumpOver: _univerjs_sheets_ui.JumpOver.moveGap,
2763
- extra: "formula-editor"
2755
+ extra: "formula-editor",
2756
+ fromCurrentSelection: refSelectionCount === 0
2764
2757
  });
2765
- else commandService.executeCommand(_univerjs_sheets_ui.MoveSelectionCommand.id, {
2758
+ else return commandService.executeCommand(_univerjs_sheets_ui.MoveSelectionCommand.id, {
2766
2759
  direction,
2767
2760
  extra: "formula-editor",
2768
2761
  fromCurrentSelection
2769
2762
  });
2770
- } else handleMoveInEditor(keycode, metaKey);
2763
+ } else return handleMoveInEditor(keycode, metaKey);
2771
2764
  };
2772
2765
  d.add(commandService.registerCommand({
2773
2766
  id: operationId,
2774
2767
  type: _univerjs_core.CommandType.OPERATION,
2775
2768
  handler(_event, params) {
2776
2769
  const { keyCode, metaKey } = params;
2777
- handleKeycode(keyCode, metaKey);
2770
+ return handleKeycode(keyCode, metaKey);
2778
2771
  }
2779
2772
  }));
2780
2773
  [
@@ -2834,7 +2827,7 @@ const useLeftAndRightArrow = (isNeed, shouldMoveSelection, editor, onMoveInEdito
2834
2827
  return {
2835
2828
  id: operationId,
2836
2829
  binding: metaKey ? keyCode | metaKey : keyCode,
2837
- preconditions: shouldHandleShortcut,
2830
+ preconditions: () => shouldHandleShortcut() && (!(metaKey && metaKey & _univerjs_ui.MetaKeys.CTRL_COMMAND) || Boolean(shouldMoveSelectionRef.current)),
2838
2831
  priority: 900,
2839
2832
  staticParameters: {
2840
2833
  eventType: _univerjs_engine_render.DeviceInputEventType.Keyboard,
@@ -4392,6 +4385,7 @@ const MobileFormulaEditor = (0, react.forwardRef)((props, ref) => {
4392
4385
  element: formulaEditorContainer
4393
4386
  }));
4394
4387
  collection.add(registerFormulaEditorRuntimePortal({
4388
+ editorService,
4395
4389
  embedId: scope.embedId,
4396
4390
  editorId,
4397
4391
  ownerDocument: formulaEditorContainer.ownerDocument,
@@ -4401,6 +4395,7 @@ const MobileFormulaEditor = (0, react.forwardRef)((props, ref) => {
4401
4395
  return () => collection.dispose();
4402
4396
  }, [
4403
4397
  editorId,
4398
+ editorService,
4404
4399
  injector,
4405
4400
  isFocus
4406
4401
  ]);
@@ -4544,10 +4539,9 @@ const MobileFormulaEditor = (0, react.forwardRef)((props, ref) => {
4544
4539
  contextService.setContextValue(_univerjs_sheets_ui.MOBILE_FORMULA_FUNCTION_PANEL_OPEN, false);
4545
4540
  });
4546
4541
  };
4547
- const handleMouseUp = (event) => {
4542
+ const handleMouseUp = () => {
4548
4543
  if (hasActiveFormulaEmbedInteraction(formulaEditorContainerRef.current)) return;
4549
4544
  if (!shouldRefocusFormulaEditorOnMouseUp({
4550
- target: event.target,
4551
4545
  isFocusing,
4552
4546
  isPointerSelecting: docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isOnPointerEvent
4553
4547
  })) return;
@@ -5213,6 +5207,7 @@ function RangeSelector(props) {
5213
5207
  const { className, onVerify, selectorRef, unitId, subUnitId, maxRangeCount, supportAcrossSheet, keepSheetReference, autoFocus, onChange, onRangeSelectorDialogVisibleChange, onClickOutside, onFocusChange, forceShowDialogWhenSelectionChanged, hideEditor, resetRange, onClose } = props;
5214
5208
  const [focusing, setFocusing] = (0, react.useState)(autoFocus ?? false);
5215
5209
  const [popupVisible, setPopupVisible] = (0, react.useState)(false);
5210
+ const [tooltipVisible, setTooltipVisible] = (0, react.useState)(false);
5216
5211
  const [rangeSelectorRanges, setRangeSelectorRanges] = (0, react.useState)([]);
5217
5212
  const editorService = (0, _univerjs_ui.useDependency)(_univerjs_docs_ui.IEditorService);
5218
5213
  const { sequenceNodes } = useRangesHighlight(editor, focusing, unitId, subUnitId);
@@ -5226,6 +5221,7 @@ function RangeSelector(props) {
5226
5221
  });
5227
5222
  const handleOpenModal = (0, _univerjs_ui.useEvent)(() => {
5228
5223
  var _editor$getDocumentDa;
5224
+ setTooltipVisible(false);
5229
5225
  blurEditor();
5230
5226
  setRangeSelectorRanges(parseRanges((editor === null || editor === void 0 || (_editor$getDocumentDa = editor.getDocumentDataModel()) === null || _editor$getDocumentDa === void 0 ? void 0 : _editor$getDocumentDa.getPlainText()) ?? ""));
5231
5227
  setPopupVisible(true);
@@ -5242,6 +5238,7 @@ function RangeSelector(props) {
5242
5238
  blur: blurEditor,
5243
5239
  verify: () => verifyRange(sequenceNodesRef.current),
5244
5240
  showDialog: (ranges) => {
5241
+ setTooltipVisible(false);
5245
5242
  blurEditor();
5246
5243
  setRangeSelectorRanges(ranges);
5247
5244
  setPopupVisible(true);
@@ -5297,6 +5294,8 @@ function RangeSelector(props) {
5297
5294
  icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Tooltip, {
5298
5295
  title: localeService.t("sheets-formula-ui.rangeSelector.buttonTooltip"),
5299
5296
  placement: "bottom",
5297
+ visible: tooltipVisible && !popupVisible,
5298
+ onVisibleChange: (visible) => setTooltipVisible(visible && !popupVisible),
5300
5299
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.SelectRangeIcon, {
5301
5300
  className: "-univer-translate-y-0.5 univer-cursor-pointer dark:!univer-text-gray-300",
5302
5301
  onClick: handleOpenModal
@@ -5328,6 +5327,7 @@ function RangeSelector(props) {
5328
5327
  keepSheetReference,
5329
5328
  onShowBySelection: (ranges) => {
5330
5329
  if (focusing || forceShowDialogWhenSelectionChanged) {
5330
+ setTooltipVisible(false);
5331
5331
  setRangeSelectorRanges(ranges);
5332
5332
  setPopupVisible(true);
5333
5333
  return false;
@@ -6764,6 +6764,7 @@ const FormulaEditor = (0, react.forwardRef)((props, ref) => {
6764
6764
  element: formulaEditorContainer
6765
6765
  }));
6766
6766
  collection.add(registerFormulaEditorRuntimePortal({
6767
+ editorService,
6767
6768
  embedId: scope.embedId,
6768
6769
  editorId,
6769
6770
  ownerDocument: formulaEditorContainer.ownerDocument,
@@ -6773,6 +6774,7 @@ const FormulaEditor = (0, react.forwardRef)((props, ref) => {
6773
6774
  return () => collection.dispose();
6774
6775
  }, [
6775
6776
  editorId,
6777
+ editorService,
6776
6778
  injector,
6777
6779
  isFocus
6778
6780
  ]);
@@ -6866,10 +6868,9 @@ const FormulaEditor = (0, react.forwardRef)((props, ref) => {
6866
6868
  highlight(`=${res.text}`);
6867
6869
  }
6868
6870
  };
6869
- const handleMouseUp = (event) => {
6871
+ const handleMouseUp = () => {
6870
6872
  if (hasActiveFormulaEmbedInteraction(formulaEditorContainerRef.current)) return;
6871
6873
  if (!shouldRefocusFormulaEditorOnMouseUp({
6872
- target: event.target,
6873
6874
  isFocusing,
6874
6875
  isPointerSelecting: docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isOnPointerEvent
6875
6876
  })) return;
@@ -7095,6 +7096,7 @@ Object.defineProperty(exports, 'FormulaReorderController', {
7095
7096
  exports.GlobalRangeSelectorService = GlobalRangeSelectorService;
7096
7097
  exports.HelpFunctionOperation = HelpFunctionOperation;
7097
7098
  exports.InsertFunctionOperation = InsertFunctionOperation;
7099
+ exports.MORE_FUNCTIONS_COMPONENT = MORE_FUNCTIONS_COMPONENT;
7098
7100
  exports.MobileRangeSelector = MobileRangeSelector;
7099
7101
  exports.MoreFunctionsOperation = MoreFunctionsOperation;
7100
7102
  exports.RangeSelector = RangeSelector;
package/lib/es/index.js CHANGED
@@ -998,7 +998,7 @@ const menuSchema = {
998
998
  //#endregion
999
999
  //#region package.json
1000
1000
  var name = "@univerjs/sheets-formula-ui";
1001
- var version = "1.0.3";
1001
+ var version = "1.0.4";
1002
1002
 
1003
1003
  //#endregion
1004
1004
  //#region src/config/config.ts
@@ -1581,6 +1581,10 @@ let FormulaEditorShowController = class FormulaEditorShowController extends Disp
1581
1581
  if (range == null) return true;
1582
1582
  const { startRow, startColumn, endRow, endColumn } = range;
1583
1583
  if (rowIndex === row && columnIndex === col) {
1584
+ result = {
1585
+ ...cellInfo,
1586
+ isInArrayFormulaRange: false
1587
+ };
1584
1588
  this._createArrayFormulaRangeShape(range, unitId, subUnitId);
1585
1589
  return false;
1586
1590
  }
@@ -1771,15 +1775,17 @@ function registerFormulaEditorRuntimePortal(options) {
1771
1775
  let registeredPortalRoot = null;
1772
1776
  let disposed = false;
1773
1777
  const tryRegister = () => {
1778
+ var _options$editorServic;
1774
1779
  if (disposed) return;
1775
- const portalRoot = resolveFormulaEditorPortalRoot(options.editorId, ownerDocument);
1780
+ const selection = (_options$editorServic = options.editorService.getEditor(options.editorId)) === null || _options$editorServic === void 0 ? void 0 : _options$editorServic.docSelectionRenderService;
1781
+ const portalRoot = (selection === null || selection === void 0 ? void 0 : selection.selectionContainer.isConnected) ? selection.selectionContainer : null;
1776
1782
  if (portalRoot === registeredPortalRoot) return;
1777
1783
  portalRegistration === null || portalRegistration === void 0 || portalRegistration.dispose();
1778
1784
  portalRegistration = void 0;
1779
1785
  registeredPortalRoot = null;
1780
- if (!portalRoot) return;
1786
+ if (!portalRoot || !selection) return;
1781
1787
  registeredPortalRoot = portalRoot;
1782
- portalRegistration = registerFormulaEditorPortalRoot(options, ownerDocument, portalRoot);
1788
+ portalRegistration = registerFormulaEditorPortalRoot(options, selection);
1783
1789
  };
1784
1790
  const scheduleRetry = (remaining) => {
1785
1791
  if (remaining <= 0 || !(view === null || view === void 0 ? void 0 : view.requestAnimationFrame)) return;
@@ -1815,13 +1821,9 @@ function registerFormulaEditorRuntimePortal(options) {
1815
1821
  }));
1816
1822
  return collection;
1817
1823
  }
1818
- function resolveFormulaEditorPortalRoot(editorId, ownerDocument) {
1819
- return ownerDocument.getElementById(`univer-doc-selection-container-${editorId}`) ?? ownerDocument.getElementById(`__editor_${editorId}`);
1820
- }
1821
- function registerFormulaEditorPortalRoot(options, ownerDocument, portalRoot) {
1824
+ function registerFormulaEditorPortalRoot(options, selection) {
1822
1825
  const collection = new DisposableCollection();
1823
- const editorElement = ownerDocument.getElementById(`__editor_${options.editorId}`);
1824
- (editorElement && editorElement !== portalRoot ? [portalRoot, editorElement] : [portalRoot]).forEach((element) => {
1826
+ [selection.selectionContainer, selection.inputElement].forEach((element) => {
1825
1827
  if (options.interactionBoundaryService) collection.add(options.interactionBoundaryService.registerOwnedElement(options.embedId, element));
1826
1828
  if (options.focusCoordinator) collection.add(options.focusCoordinator.registerElement({
1827
1829
  embedId: options.embedId,
@@ -1861,7 +1863,7 @@ function focusFormulaEditor(editorService, editor, offset) {
1861
1863
  if (!editor) return;
1862
1864
  const selections = [...editor.getSelectionRanges()];
1863
1865
  editorService.focus(editor.getEditorId());
1864
- focusFormulaEditorElement(editor);
1866
+ editor.docSelectionRenderService.focus();
1865
1867
  if (editor.docSelectionRenderService.isOnPointerEvent) return;
1866
1868
  if (Tools.isDefine(offset)) editor.setSelectionRanges([{
1867
1869
  startOffset: offset,
@@ -1877,16 +1879,7 @@ function focusFormulaEditor(editorService, editor, offset) {
1877
1879
  }]);
1878
1880
  } else editor.setSelectionRanges(selections);
1879
1881
  }
1880
- function focusFormulaEditorElement(editor) {
1881
- var _editor$editorDOM;
1882
- const editorElement = (((_editor$editorDOM = editor.editorDOM) === null || _editor$editorDOM === void 0 ? void 0 : _editor$editorDOM.ownerDocument) ?? document).getElementById(`__editor_${editor.getEditorId()}`);
1883
- editorElement === null || editorElement === void 0 || editorElement.focus({ preventScroll: true });
1884
- }
1885
- function shouldSkipFormulaEditorMouseUpFocus(_target) {
1886
- return false;
1887
- }
1888
1882
  function shouldRefocusFormulaEditorOnMouseUp(options) {
1889
- if (shouldSkipFormulaEditorMouseUpFocus(options.target)) return false;
1890
1883
  if (options.isPointerSelecting || options.isFocusing) return false;
1891
1884
  return true;
1892
1885
  }
@@ -1974,18 +1967,16 @@ let RefSelectionsRenderService = class RefSelectionsRenderService extends BaseSe
1974
1967
  if (evt.button !== 2) state.stopPropagation();
1975
1968
  }));
1976
1969
  listenerDisposables.add(spreadsheetRowHeader === null || spreadsheetRowHeader === void 0 ? void 0 : spreadsheetRowHeader.onPointerDown$.subscribeEvent((evt, state) => {
1977
- if (!this.inRefSelectionMode()) return;
1978
1970
  const skeleton = this._sheetSkeletonManagerService.getCurrentSkeleton();
1979
- if (!skeleton) return;
1971
+ if (!this.inRefSelectionMode() || !skeleton) return;
1980
1972
  const { row } = getCoordByOffset(evt.offsetX, evt.offsetY, scene, skeleton);
1981
1973
  if (checkInHeaderRanges(this._workbookSelections.getCurrentSelections(), row, RANGE_TYPE.ROW)) return;
1982
1974
  this._onPointerDown(evt, (spreadsheet.zIndex || 1) + 1, RANGE_TYPE.ROW, this._getActiveViewport(evt), ScrollTimerType.Y);
1983
1975
  if (evt.button !== 2) state.stopPropagation();
1984
1976
  }));
1985
1977
  listenerDisposables.add(spreadsheetColumnHeader === null || spreadsheetColumnHeader === void 0 ? void 0 : spreadsheetColumnHeader.onPointerDown$.subscribeEvent((evt, state) => {
1986
- if (!this.inRefSelectionMode()) return;
1987
1978
  const skeleton = this._sheetSkeletonManagerService.getCurrentSkeleton();
1988
- if (!skeleton) return;
1979
+ if (!this.inRefSelectionMode() || !skeleton) return;
1989
1980
  const { column } = getCoordByOffset(evt.offsetX, evt.offsetY, scene, skeleton);
1990
1981
  if (checkInHeaderRanges(this._workbookSelections.getCurrentSelections(), column, RANGE_TYPE.COLUMN)) return;
1991
1982
  this._onPointerDown(evt, (spreadsheet.zIndex || 1) + 1, RANGE_TYPE.COLUMN, this._getActiveViewport(evt), ScrollTimerType.X);
@@ -1993,9 +1984,8 @@ let RefSelectionsRenderService = class RefSelectionsRenderService extends BaseSe
1993
1984
  }));
1994
1985
  listenerDisposables.add(spreadsheetLeftTopPlaceholder === null || spreadsheetLeftTopPlaceholder === void 0 ? void 0 : spreadsheetLeftTopPlaceholder.onPointerDown$.subscribeEvent((evt, state) => {
1995
1986
  this._reset();
1996
- if (!this.inRefSelectionMode()) return;
1997
1987
  const skeleton = this._sheetSkeletonManagerService.getCurrentSkeleton();
1998
- if (!skeleton) return;
1988
+ if (!this.inRefSelectionMode() || !skeleton) return;
1999
1989
  const selectionWithStyle = getAllSelection(skeleton);
2000
1990
  this._addSelectionControlByModelData(selectionWithStyle);
2001
1991
  this._selectionMoveStart$.next(this.getSelectionDataWithStyle());
@@ -2161,7 +2151,7 @@ let RefSelectionsRenderService = class RefSelectionsRenderService extends BaseSe
2161
2151
  endRow: activeSelectionControl.model.endRow,
2162
2152
  endColumn: activeSelectionControl.model.endColumn
2163
2153
  } : null;
2164
- const remainLastEnable = this._remainLastEnabled && !evt.ctrlKey && !evt.metaKey && !evt.shiftKey && !this._skipLastEnabled && !this._singleSelectionEnabled;
2154
+ const remainLastEnable = this._remainLastEnabled && !this._isMultiSelectModifier(evt) && !evt.shiftKey && !this._skipLastEnabled && !this._singleSelectionEnabled;
2165
2155
  if (expandByShiftKey && currentCell) this._makeSelectionByTwoCells(currentCell, cursorCellRangeWithRangeType, skeleton, rangeType, activeSelectionControl);
2166
2156
  else if (remainLastEnable && activeSelectionControl) activeSelectionControl.updateRangeBySelectionWithCoord(selectionCellWithCoord);
2167
2157
  else activeSelectionControl = this.newSelectionControl(scene, skeleton, selectionWithStyle);
@@ -2734,8 +2724,8 @@ const useLeftAndRightArrow = (isNeed, shouldMoveSelection, editor, onMoveInEdito
2734
2724
  if (keycode === KeyCode.ARROW_DOWN) direction = Direction.DOWN;
2735
2725
  else if (keycode === KeyCode.ARROW_UP) direction = Direction.UP;
2736
2726
  else if (keycode === KeyCode.ARROW_RIGHT) direction = Direction.RIGHT;
2737
- if (metaKey === MetaKeys.SHIFT) commandService.executeCommand(MoveSelectionOperation.id, { direction });
2738
- else commandService.executeCommand(MoveCursorOperation.id, { direction });
2727
+ if (metaKey === MetaKeys.SHIFT) return commandService.syncExecuteCommand(MoveSelectionOperation.id, { direction });
2728
+ else return commandService.syncExecuteCommand(MoveCursorOperation.id, { direction });
2739
2729
  };
2740
2730
  const handleKeycode = (keycode, metaKey) => {
2741
2731
  let direction = Direction.DOWN;
@@ -2745,35 +2735,38 @@ const useLeftAndRightArrow = (isNeed, shouldMoveSelection, editor, onMoveInEdito
2745
2735
  else if (keycode === KeyCode.ARROW_RIGHT) direction = Direction.RIGHT;
2746
2736
  if (shouldMoveSelectionRef.current) {
2747
2737
  var _getRefSelectionCount;
2748
- const fromCurrentSelection = shouldMoveFormulaSelectionFromCurrentSelection(shouldMoveSelectionRef.current, ((_getRefSelectionCount = getRefSelectionCountRef.current) === null || _getRefSelectionCount === void 0 ? void 0 : _getRefSelectionCount.call(getRefSelectionCountRef)) ?? 0);
2749
- if (metaKey === MetaKeys.CTRL_COMMAND) commandService.executeCommand(MoveSelectionCommand.id, {
2738
+ const refSelectionCount = ((_getRefSelectionCount = getRefSelectionCountRef.current) === null || _getRefSelectionCount === void 0 ? void 0 : _getRefSelectionCount.call(getRefSelectionCountRef)) ?? 0;
2739
+ const fromCurrentSelection = shouldMoveFormulaSelectionFromCurrentSelection(shouldMoveSelectionRef.current, refSelectionCount);
2740
+ if (metaKey === MetaKeys.CTRL_COMMAND) return commandService.executeCommand(MoveSelectionCommand.id, {
2750
2741
  direction,
2751
2742
  jumpOver: JumpOver.moveGap,
2752
2743
  extra: "formula-editor",
2753
2744
  fromCurrentSelection
2754
2745
  });
2755
- else if (metaKey === MetaKeys.SHIFT) commandService.executeCommand(ExpandSelectionCommand.id, {
2746
+ else if (metaKey === MetaKeys.SHIFT) return commandService.executeCommand(ExpandSelectionCommand.id, {
2756
2747
  direction,
2757
- extra: "formula-editor"
2748
+ extra: "formula-editor",
2749
+ fromCurrentSelection: refSelectionCount === 0
2758
2750
  });
2759
- else if (metaKey === (MetaKeys.CTRL_COMMAND | MetaKeys.SHIFT)) commandService.executeCommand(ExpandSelectionCommand.id, {
2751
+ else if (metaKey === (MetaKeys.CTRL_COMMAND | MetaKeys.SHIFT)) return commandService.executeCommand(ExpandSelectionCommand.id, {
2760
2752
  direction,
2761
2753
  jumpOver: JumpOver.moveGap,
2762
- extra: "formula-editor"
2754
+ extra: "formula-editor",
2755
+ fromCurrentSelection: refSelectionCount === 0
2763
2756
  });
2764
- else commandService.executeCommand(MoveSelectionCommand.id, {
2757
+ else return commandService.executeCommand(MoveSelectionCommand.id, {
2765
2758
  direction,
2766
2759
  extra: "formula-editor",
2767
2760
  fromCurrentSelection
2768
2761
  });
2769
- } else handleMoveInEditor(keycode, metaKey);
2762
+ } else return handleMoveInEditor(keycode, metaKey);
2770
2763
  };
2771
2764
  d.add(commandService.registerCommand({
2772
2765
  id: operationId,
2773
2766
  type: CommandType.OPERATION,
2774
2767
  handler(_event, params) {
2775
2768
  const { keyCode, metaKey } = params;
2776
- handleKeycode(keyCode, metaKey);
2769
+ return handleKeycode(keyCode, metaKey);
2777
2770
  }
2778
2771
  }));
2779
2772
  [
@@ -2833,7 +2826,7 @@ const useLeftAndRightArrow = (isNeed, shouldMoveSelection, editor, onMoveInEdito
2833
2826
  return {
2834
2827
  id: operationId,
2835
2828
  binding: metaKey ? keyCode | metaKey : keyCode,
2836
- preconditions: shouldHandleShortcut,
2829
+ preconditions: () => shouldHandleShortcut() && (!(metaKey && metaKey & MetaKeys.CTRL_COMMAND) || Boolean(shouldMoveSelectionRef.current)),
2837
2830
  priority: 900,
2838
2831
  staticParameters: {
2839
2832
  eventType: DeviceInputEventType.Keyboard,
@@ -4391,6 +4384,7 @@ const MobileFormulaEditor = forwardRef((props, ref) => {
4391
4384
  element: formulaEditorContainer
4392
4385
  }));
4393
4386
  collection.add(registerFormulaEditorRuntimePortal({
4387
+ editorService,
4394
4388
  embedId: scope.embedId,
4395
4389
  editorId,
4396
4390
  ownerDocument: formulaEditorContainer.ownerDocument,
@@ -4400,6 +4394,7 @@ const MobileFormulaEditor = forwardRef((props, ref) => {
4400
4394
  return () => collection.dispose();
4401
4395
  }, [
4402
4396
  editorId,
4397
+ editorService,
4403
4398
  injector,
4404
4399
  isFocus
4405
4400
  ]);
@@ -4543,10 +4538,9 @@ const MobileFormulaEditor = forwardRef((props, ref) => {
4543
4538
  contextService.setContextValue(MOBILE_FORMULA_FUNCTION_PANEL_OPEN, false);
4544
4539
  });
4545
4540
  };
4546
- const handleMouseUp = (event) => {
4541
+ const handleMouseUp = () => {
4547
4542
  if (hasActiveFormulaEmbedInteraction(formulaEditorContainerRef.current)) return;
4548
4543
  if (!shouldRefocusFormulaEditorOnMouseUp({
4549
- target: event.target,
4550
4544
  isFocusing,
4551
4545
  isPointerSelecting: docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isOnPointerEvent
4552
4546
  })) return;
@@ -5212,6 +5206,7 @@ function RangeSelector(props) {
5212
5206
  const { className, onVerify, selectorRef, unitId, subUnitId, maxRangeCount, supportAcrossSheet, keepSheetReference, autoFocus, onChange, onRangeSelectorDialogVisibleChange, onClickOutside, onFocusChange, forceShowDialogWhenSelectionChanged, hideEditor, resetRange, onClose } = props;
5213
5207
  const [focusing, setFocusing] = useState(autoFocus ?? false);
5214
5208
  const [popupVisible, setPopupVisible] = useState(false);
5209
+ const [tooltipVisible, setTooltipVisible] = useState(false);
5215
5210
  const [rangeSelectorRanges, setRangeSelectorRanges] = useState([]);
5216
5211
  const editorService = useDependency(IEditorService);
5217
5212
  const { sequenceNodes } = useRangesHighlight(editor, focusing, unitId, subUnitId);
@@ -5225,6 +5220,7 @@ function RangeSelector(props) {
5225
5220
  });
5226
5221
  const handleOpenModal = useEvent(() => {
5227
5222
  var _editor$getDocumentDa;
5223
+ setTooltipVisible(false);
5228
5224
  blurEditor();
5229
5225
  setRangeSelectorRanges(parseRanges((editor === null || editor === void 0 || (_editor$getDocumentDa = editor.getDocumentDataModel()) === null || _editor$getDocumentDa === void 0 ? void 0 : _editor$getDocumentDa.getPlainText()) ?? ""));
5230
5226
  setPopupVisible(true);
@@ -5241,6 +5237,7 @@ function RangeSelector(props) {
5241
5237
  blur: blurEditor,
5242
5238
  verify: () => verifyRange(sequenceNodesRef.current),
5243
5239
  showDialog: (ranges) => {
5240
+ setTooltipVisible(false);
5244
5241
  blurEditor();
5245
5242
  setRangeSelectorRanges(ranges);
5246
5243
  setPopupVisible(true);
@@ -5296,6 +5293,8 @@ function RangeSelector(props) {
5296
5293
  icon: /* @__PURE__ */ jsx(Tooltip, {
5297
5294
  title: localeService.t("sheets-formula-ui.rangeSelector.buttonTooltip"),
5298
5295
  placement: "bottom",
5296
+ visible: tooltipVisible && !popupVisible,
5297
+ onVisibleChange: (visible) => setTooltipVisible(visible && !popupVisible),
5299
5298
  children: /* @__PURE__ */ jsx(SelectRangeIcon, {
5300
5299
  className: "-univer-translate-y-0.5 univer-cursor-pointer dark:!univer-text-gray-300",
5301
5300
  onClick: handleOpenModal
@@ -5327,6 +5326,7 @@ function RangeSelector(props) {
5327
5326
  keepSheetReference,
5328
5327
  onShowBySelection: (ranges) => {
5329
5328
  if (focusing || forceShowDialogWhenSelectionChanged) {
5329
+ setTooltipVisible(false);
5330
5330
  setRangeSelectorRanges(ranges);
5331
5331
  setPopupVisible(true);
5332
5332
  return false;
@@ -6763,6 +6763,7 @@ const FormulaEditor = forwardRef((props, ref) => {
6763
6763
  element: formulaEditorContainer
6764
6764
  }));
6765
6765
  collection.add(registerFormulaEditorRuntimePortal({
6766
+ editorService,
6766
6767
  embedId: scope.embedId,
6767
6768
  editorId,
6768
6769
  ownerDocument: formulaEditorContainer.ownerDocument,
@@ -6772,6 +6773,7 @@ const FormulaEditor = forwardRef((props, ref) => {
6772
6773
  return () => collection.dispose();
6773
6774
  }, [
6774
6775
  editorId,
6776
+ editorService,
6775
6777
  injector,
6776
6778
  isFocus
6777
6779
  ]);
@@ -6865,10 +6867,9 @@ const FormulaEditor = forwardRef((props, ref) => {
6865
6867
  highlight(`=${res.text}`);
6866
6868
  }
6867
6869
  };
6868
- const handleMouseUp = (event) => {
6870
+ const handleMouseUp = () => {
6869
6871
  if (hasActiveFormulaEmbedInteraction(formulaEditorContainerRef.current)) return;
6870
6872
  if (!shouldRefocusFormulaEditorOnMouseUp({
6871
- target: event.target,
6872
6873
  isFocusing,
6873
6874
  isPointerSelecting: docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isOnPointerEvent
6874
6875
  })) return;
@@ -7083,4 +7084,4 @@ UniverSheetsFormulaUIPlugin = __decorate([
7083
7084
  ], UniverSheetsFormulaUIPlugin);
7084
7085
 
7085
7086
  //#endregion
7086
- export { FORMULA_PROMPT_ACTIVATED, FormulaEditor, FormulaReorderController, GlobalRangeSelectorService, HelpFunctionOperation, InsertFunctionOperation, MobileRangeSelector, MoreFunctionsOperation, RangeSelector, RefSelectionsRenderService, ReferenceAbsoluteOperation, SearchFunctionOperation, SheetCopyFormulaOnlyCommand, SheetOnlyPasteFormulaCommand, menuSchema as SheetsFormulaUIMenuSchema, UniverSheetsFormulaMobileUIPlugin, UniverSheetsFormulaUIPlugin, genFormulaRefSelectionStyle };
7087
+ export { FORMULA_PROMPT_ACTIVATED, FormulaEditor, FormulaReorderController, GlobalRangeSelectorService, HelpFunctionOperation, InsertFunctionOperation, MORE_FUNCTIONS_COMPONENT, MobileRangeSelector, MoreFunctionsOperation, RangeSelector, RefSelectionsRenderService, ReferenceAbsoluteOperation, SearchFunctionOperation, SheetCopyFormulaOnlyCommand, SheetOnlyPasteFormulaCommand, menuSchema as SheetsFormulaUIMenuSchema, UniverSheetsFormulaMobileUIPlugin, UniverSheetsFormulaUIPlugin, genFormulaRefSelectionStyle };