@univerjs/sheets-formula-ui 1.0.0-alpha.1 → 1.0.0-alpha.3

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
@@ -778,10 +778,231 @@ FormulaReorderController = __decorate([
778
778
  __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_engine_formula.LexerTreeBuilder))
779
779
  ], FormulaReorderController);
780
780
 
781
+ //#endregion
782
+ //#region src/menu/menu.ts
783
+ function InsertCommonFunctionMenuItemFactory(accessor) {
784
+ const commonFunctions = [
785
+ "SUMIF",
786
+ "SUM",
787
+ "AVERAGE",
788
+ "IF",
789
+ "COUNT",
790
+ "SIN",
791
+ "MAX"
792
+ ];
793
+ let selections = commonFunctions.map((name) => ({
794
+ label: {
795
+ name,
796
+ selectable: false
797
+ },
798
+ value: name
799
+ }));
800
+ try {
801
+ const descriptionService = accessor.get(_univerjs_sheets_formula.IDescriptionService);
802
+ const filtered = commonFunctions.filter((name) => Boolean(descriptionService.getFunctionInfo(name)));
803
+ if (filtered.length > 0) selections = filtered.map((name) => ({
804
+ label: {
805
+ name,
806
+ selectable: false
807
+ },
808
+ value: name
809
+ }));
810
+ } catch {}
811
+ return {
812
+ id: `${InsertFunctionOperation.id}.common`,
813
+ commandId: InsertFunctionOperation.id,
814
+ title: "sheets-formula-ui.insert.common",
815
+ tooltip: "sheets-formula-ui.insert.tooltip",
816
+ icon: "FunctionIcon",
817
+ type: _univerjs_ui.MenuItemType.SELECTOR,
818
+ selections,
819
+ hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET)
820
+ };
821
+ }
822
+ function createInsertFunctionCategoryMenuItemFactory(functionType, categoryKey, icon) {
823
+ return function insertFunctionCategoryMenuItemFactory(accessor) {
824
+ let selections = [];
825
+ try {
826
+ selections = accessor.get(_univerjs_sheets_formula.IDescriptionService).getSearchListByType(functionType).map(({ name }) => ({
827
+ label: {
828
+ name,
829
+ selectable: false
830
+ },
831
+ value: name
832
+ }));
833
+ } catch {
834
+ selections = [];
835
+ }
836
+ return {
837
+ id: `${InsertFunctionOperation.id}.${categoryKey}`,
838
+ commandId: InsertFunctionOperation.id,
839
+ title: `sheets-formula-ui.functionType.${categoryKey}`,
840
+ tooltip: "sheets-formula-ui.insert.tooltip",
841
+ icon,
842
+ type: _univerjs_ui.MenuItemType.SELECTOR,
843
+ selections,
844
+ hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET)
845
+ };
846
+ };
847
+ }
848
+ const InsertFinancialFunctionMenuItemFactory = createInsertFunctionCategoryMenuItemFactory(_univerjs_engine_formula.FunctionType.Financial, "financial");
849
+ const InsertLogicalFunctionMenuItemFactory = createInsertFunctionCategoryMenuItemFactory(_univerjs_engine_formula.FunctionType.Logical, "logical");
850
+ const InsertTextFunctionMenuItemFactory = createInsertFunctionCategoryMenuItemFactory(_univerjs_engine_formula.FunctionType.Text, "text");
851
+ const InsertDateFunctionMenuItemFactory = createInsertFunctionCategoryMenuItemFactory(_univerjs_engine_formula.FunctionType.Date, "date");
852
+ const InsertLookupFunctionMenuItemFactory = createInsertFunctionCategoryMenuItemFactory(_univerjs_engine_formula.FunctionType.Lookup, "lookup");
853
+ const InsertMathFunctionMenuItemFactory = createInsertFunctionCategoryMenuItemFactory(_univerjs_engine_formula.FunctionType.Math, "math");
854
+ const InsertStatisticalFunctionMenuItemFactory = createInsertFunctionCategoryMenuItemFactory(_univerjs_engine_formula.FunctionType.Statistical, "statistical");
855
+ const InsertEngineeringFunctionMenuItemFactory = createInsertFunctionCategoryMenuItemFactory(_univerjs_engine_formula.FunctionType.Engineering, "engineering");
856
+ const InsertInformationFunctionMenuItemFactory = createInsertFunctionCategoryMenuItemFactory(_univerjs_engine_formula.FunctionType.Information, "information");
857
+ const InsertDatabaseFunctionMenuItemFactory = createInsertFunctionCategoryMenuItemFactory(_univerjs_engine_formula.FunctionType.Database, "database");
858
+ function AllFunctionsMenuItemFactory(accessor) {
859
+ return {
860
+ id: MoreFunctionsOperation.id,
861
+ title: "sheets-formula-ui.moreFunctions.allFunctions",
862
+ tooltip: "sheets-formula-ui.insert.tooltip",
863
+ type: _univerjs_ui.MenuItemType.BUTTON,
864
+ hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET),
865
+ disabled$: (0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
866
+ workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
867
+ worksheetTypes: [_univerjs_sheets.WorksheetEditPermission, _univerjs_sheets.WorksheetSetCellValuePermission],
868
+ rangeTypes: [_univerjs_sheets.RangeProtectionPermissionEditPoint]
869
+ })
870
+ };
871
+ }
872
+ function CopyFormulaOnlyMenuItemFactory(accessor) {
873
+ return {
874
+ id: SheetCopyFormulaOnlyCommand.id,
875
+ type: _univerjs_ui.MenuItemType.BUTTON,
876
+ title: "sheets-formula-ui.operation.copyFormulaOnly",
877
+ disabled$: (0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
878
+ workbookTypes: [_univerjs_sheets.WorkbookCopyPermission],
879
+ worksheetTypes: [_univerjs_sheets.WorksheetCopyPermission],
880
+ rangeTypes: [_univerjs_sheets.RangeProtectionPermissionViewPoint]
881
+ }),
882
+ hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET)
883
+ };
884
+ }
885
+ function PasteFormulaMenuItemFactory(accessor) {
886
+ return {
887
+ id: SheetOnlyPasteFormulaCommand.id,
888
+ type: _univerjs_ui.MenuItemType.BUTTON,
889
+ title: "sheets-formula-ui.operation.pasteFormula",
890
+ disabled$: (0, _univerjs_sheets_ui.menuClipboardDisabledObservable)(accessor).pipe((0, rxjs.combineLatestWith)((0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
891
+ workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
892
+ rangeTypes: [_univerjs_sheets.RangeProtectionPermissionEditPoint],
893
+ worksheetTypes: [_univerjs_sheets.WorksheetSetCellValuePermission, _univerjs_sheets.WorksheetEditPermission]
894
+ })), (0, rxjs.map)(([d1, d2]) => d1 || d2)),
895
+ hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET)
896
+ };
897
+ }
898
+
899
+ //#endregion
900
+ //#region src/menu/schema.ts
901
+ const menuSchema = {
902
+ [_univerjs_ui.RibbonFormulasGroup.BASIC]: {
903
+ [`${InsertFunctionOperation.id}.common`]: {
904
+ order: 0,
905
+ menuItemFactory: InsertCommonFunctionMenuItemFactory,
906
+ [MoreFunctionsOperation.id]: {
907
+ order: 0,
908
+ menuItemFactory: AllFunctionsMenuItemFactory
909
+ }
910
+ },
911
+ [`${InsertFunctionOperation.id}.financial`]: {
912
+ order: 1,
913
+ menuItemFactory: InsertFinancialFunctionMenuItemFactory,
914
+ [MoreFunctionsOperation.id]: {
915
+ order: 0,
916
+ menuItemFactory: AllFunctionsMenuItemFactory
917
+ }
918
+ },
919
+ [`${InsertFunctionOperation.id}.logical`]: {
920
+ order: 2,
921
+ menuItemFactory: InsertLogicalFunctionMenuItemFactory,
922
+ [MoreFunctionsOperation.id]: {
923
+ order: 0,
924
+ menuItemFactory: AllFunctionsMenuItemFactory
925
+ }
926
+ },
927
+ [`${InsertFunctionOperation.id}.text`]: {
928
+ order: 3,
929
+ menuItemFactory: InsertTextFunctionMenuItemFactory,
930
+ [MoreFunctionsOperation.id]: {
931
+ order: 0,
932
+ menuItemFactory: AllFunctionsMenuItemFactory
933
+ }
934
+ },
935
+ [`${InsertFunctionOperation.id}.date`]: {
936
+ order: 4,
937
+ menuItemFactory: InsertDateFunctionMenuItemFactory,
938
+ [MoreFunctionsOperation.id]: {
939
+ order: 0,
940
+ menuItemFactory: AllFunctionsMenuItemFactory
941
+ }
942
+ },
943
+ [`${InsertFunctionOperation.id}.lookup`]: {
944
+ order: 5,
945
+ menuItemFactory: InsertLookupFunctionMenuItemFactory,
946
+ [MoreFunctionsOperation.id]: {
947
+ order: 0,
948
+ menuItemFactory: AllFunctionsMenuItemFactory
949
+ }
950
+ },
951
+ [`${InsertFunctionOperation.id}.math`]: {
952
+ order: 6,
953
+ menuItemFactory: InsertMathFunctionMenuItemFactory,
954
+ [MoreFunctionsOperation.id]: {
955
+ order: 0,
956
+ menuItemFactory: AllFunctionsMenuItemFactory
957
+ }
958
+ },
959
+ [`${InsertFunctionOperation.id}.statistical`]: {
960
+ order: 7,
961
+ menuItemFactory: InsertStatisticalFunctionMenuItemFactory,
962
+ [MoreFunctionsOperation.id]: {
963
+ order: 0,
964
+ menuItemFactory: AllFunctionsMenuItemFactory
965
+ }
966
+ },
967
+ [`${InsertFunctionOperation.id}.engineering`]: {
968
+ order: 8,
969
+ menuItemFactory: InsertEngineeringFunctionMenuItemFactory,
970
+ [MoreFunctionsOperation.id]: {
971
+ order: 0,
972
+ menuItemFactory: AllFunctionsMenuItemFactory
973
+ }
974
+ },
975
+ [`${InsertFunctionOperation.id}.information`]: {
976
+ order: 9,
977
+ menuItemFactory: InsertInformationFunctionMenuItemFactory,
978
+ [MoreFunctionsOperation.id]: {
979
+ order: 0,
980
+ menuItemFactory: AllFunctionsMenuItemFactory
981
+ }
982
+ },
983
+ [`${InsertFunctionOperation.id}.database`]: {
984
+ order: 10,
985
+ menuItemFactory: InsertDatabaseFunctionMenuItemFactory,
986
+ [MoreFunctionsOperation.id]: {
987
+ order: 0,
988
+ menuItemFactory: AllFunctionsMenuItemFactory
989
+ }
990
+ }
991
+ },
992
+ [_univerjs_sheets_ui.COPY_SPECIAL_MENU_ID]: { [SheetCopyFormulaOnlyCommand.id]: {
993
+ order: 0,
994
+ menuItemFactory: CopyFormulaOnlyMenuItemFactory
995
+ } },
996
+ [_univerjs_sheets_ui.PASTE_SPECIAL_MENU_ID]: { [SheetOnlyPasteFormulaCommand.id]: {
997
+ order: 4,
998
+ menuItemFactory: PasteFormulaMenuItemFactory
999
+ } }
1000
+ };
1001
+
781
1002
  //#endregion
782
1003
  //#region package.json
783
1004
  var name = "@univerjs/sheets-formula-ui";
784
- var version = "1.0.0-alpha.1";
1005
+ var version = "1.0.0-alpha.3";
785
1006
 
786
1007
  //#endregion
787
1008
  //#region src/config/config.ts
@@ -826,6 +1047,112 @@ const findRefSequenceIndex = (sequenceNode, targetIndex) => {
826
1047
  return result;
827
1048
  };
828
1049
 
1050
+ //#endregion
1051
+ //#region src/views/formula-editor/formula-embed-integration.service.ts
1052
+ const FORMULA_EMBED_INTERACTION_BOUNDARY_OWNER_ATTRIBUTE = "data-embed-interaction-boundary-owner";
1053
+ const FORMULA_EMBED_ID_ATTRIBUTE = "data-embed-id";
1054
+ const FORMULA_EMBED_HOST_UNIT_ID_ATTRIBUTE = "data-embed-host-unit-id";
1055
+ const FORMULA_EMBED_CHILD_UNIT_ID_ATTRIBUTE = "data-embed-child-unit-id";
1056
+ const IFormulaEmbedRuntimeFocusCoordinator = (0, _univerjs_core.createIdentifier)("sheets-formula-ui.embed-runtime-focus-coordinator");
1057
+ const IFormulaEmbedInteractionBoundaryService = (0, _univerjs_core.createIdentifier)("sheets-formula-ui.embed-interaction-boundary.service");
1058
+ function registerFormulaEditorRuntimePortal(options) {
1059
+ var _options$ownerDocumen;
1060
+ const ownerDocument = (_options$ownerDocumen = options.ownerDocument) !== null && _options$ownerDocumen !== void 0 ? _options$ownerDocumen : typeof document === "undefined" ? void 0 : document;
1061
+ if (!ownerDocument) return (0, _univerjs_core.toDisposable)(() => {});
1062
+ const collection = new _univerjs_core.DisposableCollection();
1063
+ const view = ownerDocument.defaultView;
1064
+ const frameHandles = [];
1065
+ let observer;
1066
+ let portalRegistration;
1067
+ let registeredPortalRoot = null;
1068
+ let disposed = false;
1069
+ const tryRegister = () => {
1070
+ if (disposed) return;
1071
+ const portalRoot = resolveFormulaEditorPortalRoot(options.editorId, ownerDocument);
1072
+ if (portalRoot === registeredPortalRoot) return;
1073
+ portalRegistration === null || portalRegistration === void 0 || portalRegistration.dispose();
1074
+ portalRegistration = void 0;
1075
+ registeredPortalRoot = null;
1076
+ if (!portalRoot) return;
1077
+ registeredPortalRoot = portalRoot;
1078
+ portalRegistration = registerFormulaEditorPortalRoot(options, ownerDocument, portalRoot);
1079
+ };
1080
+ const scheduleRetry = (remaining) => {
1081
+ if (remaining <= 0 || !(view === null || view === void 0 ? void 0 : view.requestAnimationFrame)) return;
1082
+ const handle = view.requestAnimationFrame(() => {
1083
+ const index = frameHandles.indexOf(handle);
1084
+ if (index >= 0) frameHandles.splice(index, 1);
1085
+ tryRegister();
1086
+ if (!registeredPortalRoot) scheduleRetry(remaining - 1);
1087
+ });
1088
+ frameHandles.push(handle);
1089
+ };
1090
+ tryRegister();
1091
+ if (!registeredPortalRoot) scheduleRetry(2);
1092
+ if ((view === null || view === void 0 ? void 0 : view.MutationObserver) && ownerDocument.body) {
1093
+ observer = new view.MutationObserver(() => tryRegister());
1094
+ observer.observe(ownerDocument.body, {
1095
+ childList: true,
1096
+ subtree: true
1097
+ });
1098
+ }
1099
+ collection.add((0, _univerjs_core.toDisposable)(() => {
1100
+ disposed = true;
1101
+ frameHandles.forEach((handle) => {
1102
+ var _view$cancelAnimation;
1103
+ return view === null || view === void 0 || (_view$cancelAnimation = view.cancelAnimationFrame) === null || _view$cancelAnimation === void 0 ? void 0 : _view$cancelAnimation.call(view, handle);
1104
+ });
1105
+ frameHandles.length = 0;
1106
+ observer === null || observer === void 0 || observer.disconnect();
1107
+ observer = void 0;
1108
+ portalRegistration === null || portalRegistration === void 0 || portalRegistration.dispose();
1109
+ portalRegistration = void 0;
1110
+ registeredPortalRoot = null;
1111
+ }));
1112
+ return collection;
1113
+ }
1114
+ function resolveFormulaEditorPortalRoot(editorId, ownerDocument) {
1115
+ var _ref;
1116
+ return (_ref = ownerDocument.getElementById(`univer-doc-selection-container-${editorId}`)) !== null && _ref !== void 0 ? _ref : ownerDocument.getElementById(`__editor_${editorId}`);
1117
+ }
1118
+ function registerFormulaEditorPortalRoot(options, ownerDocument, portalRoot) {
1119
+ const collection = new _univerjs_core.DisposableCollection();
1120
+ const editorElement = ownerDocument.getElementById(`__editor_${options.editorId}`);
1121
+ (editorElement && editorElement !== portalRoot ? [portalRoot, editorElement] : [portalRoot]).forEach((element) => {
1122
+ if (options.interactionBoundaryService) collection.add(options.interactionBoundaryService.registerOwnedElement(options.embedId, element));
1123
+ if (options.focusCoordinator) collection.add(options.focusCoordinator.registerElement({
1124
+ embedId: options.embedId,
1125
+ role: "child-editor",
1126
+ element
1127
+ }));
1128
+ });
1129
+ return collection;
1130
+ }
1131
+ function resolveFormulaEmbedRuntimeDomScope(root) {
1132
+ var _scopeElement$getAttr, _scopeElement$getAttr2;
1133
+ const scopeElement = root === null || root === void 0 ? void 0 : root.closest(`[${FORMULA_EMBED_ID_ATTRIBUTE}]`);
1134
+ const embedId = scopeElement === null || scopeElement === void 0 ? void 0 : scopeElement.getAttribute(FORMULA_EMBED_ID_ATTRIBUTE);
1135
+ if (!scopeElement || !embedId) return;
1136
+ return {
1137
+ embedId,
1138
+ hostUnitId: (_scopeElement$getAttr = scopeElement.getAttribute("data-embed-host-unit-id")) !== null && _scopeElement$getAttr !== void 0 ? _scopeElement$getAttr : void 0,
1139
+ childUnitId: (_scopeElement$getAttr2 = scopeElement.getAttribute("data-embed-child-unit-id")) !== null && _scopeElement$getAttr2 !== void 0 ? _scopeElement$getAttr2 : void 0
1140
+ };
1141
+ }
1142
+ function resolveActiveFormulaEmbedRuntimeDomScope(ownerDocument) {
1143
+ const activeElement = ownerDocument === null || ownerDocument === void 0 ? void 0 : ownerDocument.activeElement;
1144
+ return activeElement instanceof HTMLElement ? resolveFormulaEmbedRuntimeDomScope(activeElement) : void 0;
1145
+ }
1146
+ function isEventTargetInSameFormulaEmbedInteractionBoundary(left, right) {
1147
+ const leftOwner = resolveFormulaEmbedInteractionOwnerId(left);
1148
+ return Boolean(leftOwner && leftOwner === resolveFormulaEmbedInteractionOwnerId(right));
1149
+ }
1150
+ function resolveFormulaEmbedInteractionOwnerId(target) {
1151
+ var _target$closest$getAt, _target$closest;
1152
+ if (!(target instanceof Element)) return;
1153
+ return (_target$closest$getAt = (_target$closest = target.closest(`[${"data-embed-interaction-boundary-owner"}]`)) === null || _target$closest === void 0 ? void 0 : _target$closest.getAttribute("data-embed-interaction-boundary-owner")) !== null && _target$closest$getAt !== void 0 ? _target$closest$getAt : void 0;
1154
+ }
1155
+
829
1156
  //#endregion
830
1157
  //#region src/services/utils.ts
831
1158
  function getFunctionTypeValues(localeService, customFormula) {
@@ -1065,16 +1392,19 @@ const HelpHiddenTip = ({ onClick }) => {
1065
1392
 
1066
1393
  //#endregion
1067
1394
  //#region src/views/formula-editor/help-function/HelpFunction.tsx
1068
- const Params = ({ className, title, value }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1069
- className: "univer-my-2",
1070
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1071
- className: (0, _univerjs_design.clsx)("univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-white", className),
1072
- children: title
1073
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1074
- className: "univer-whitespace-pre-wrap univer-break-words univer-text-xs univer-text-gray-500",
1075
- children: value
1076
- })]
1077
- });
1395
+ const Params = ({ className, title, titleKey, value }) => {
1396
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
1397
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1398
+ className: "univer-my-2",
1399
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1400
+ className: (0, _univerjs_design.clsx)("univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-white", className),
1401
+ children: titleKey ? localeService.t(titleKey) : title
1402
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1403
+ className: "univer-whitespace-pre-wrap univer-break-words univer-text-xs univer-text-gray-500",
1404
+ children: value
1405
+ })]
1406
+ });
1407
+ };
1078
1408
  const Help = (props) => {
1079
1409
  const { prefix, value, active, onClick } = props;
1080
1410
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [
@@ -1150,11 +1480,11 @@ function HelpFunction(props) {
1150
1480
  className: "univer-mt-3",
1151
1481
  children: [
1152
1482
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Params, {
1153
- title: localeService.t("sheets-formula-ui.prompt.helpExample"),
1483
+ titleKey: "sheets-formula-ui.prompt.helpExample",
1154
1484
  value: `${functionInfo.functionName}(${functionInfo.functionParameter.map((item) => item.example).join(",")})`
1155
1485
  }),
1156
1486
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Params, {
1157
- title: localeService.t("sheets-formula-ui.prompt.helpAbstract"),
1487
+ titleKey: "sheets-formula-ui.prompt.helpAbstract",
1158
1488
  value: functionInfo.description
1159
1489
  }),
1160
1490
  functionInfo && functionInfo.functionParameter && functionInfo.functionParameter.map((item, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Params, {
@@ -1171,26 +1501,47 @@ function HelpFunction(props) {
1171
1501
 
1172
1502
  //#endregion
1173
1503
  //#region src/views/formula-editor/hooks/use-focus.ts
1504
+ function focusFormulaEditor(editorService, editor, offset) {
1505
+ if (!editor) return;
1506
+ editorService.focus(editor.getEditorId());
1507
+ focusFormulaEditorElement(editor);
1508
+ if (editor.docSelectionRenderService.isOnPointerEvent) return;
1509
+ const selections = [...editor.getSelectionRanges()];
1510
+ if (_univerjs_core.Tools.isDefine(offset)) editor.setSelectionRanges([{
1511
+ startOffset: offset,
1512
+ endOffset: offset
1513
+ }]);
1514
+ else if (!selections.length) {
1515
+ var _editor$getDocumentDa, _editor$getDocumentDa2;
1516
+ const body = (_editor$getDocumentDa = (_editor$getDocumentDa2 = editor.getDocumentData().body) === null || _editor$getDocumentDa2 === void 0 ? void 0 : _editor$getDocumentDa2.dataStream) !== null && _editor$getDocumentDa !== void 0 ? _editor$getDocumentDa : "\r\n";
1517
+ const offset = Math.max(body.length - 2, 0);
1518
+ editor.setSelectionRanges([{
1519
+ startOffset: offset,
1520
+ endOffset: offset
1521
+ }]);
1522
+ } else editor.setSelectionRanges(selections);
1523
+ }
1524
+ function focusFormulaEditorElement(editor) {
1525
+ var _editor$editorDOM$own, _editor$editorDOM;
1526
+ const editorElement = ((_editor$editorDOM$own = (_editor$editorDOM = editor.editorDOM) === null || _editor$editorDOM === void 0 ? void 0 : _editor$editorDOM.ownerDocument) !== null && _editor$editorDOM$own !== void 0 ? _editor$editorDOM$own : document).getElementById(`__editor_${editor.getEditorId()}`);
1527
+ editorElement === null || editorElement === void 0 || editorElement.focus({ preventScroll: true });
1528
+ }
1529
+ function shouldSkipFormulaEditorMouseUpFocus(_target) {
1530
+ return false;
1531
+ }
1532
+ function shouldRefocusFormulaEditorOnMouseUp(options) {
1533
+ if (shouldSkipFormulaEditorMouseUpFocus(options.target)) return false;
1534
+ if (options.isPointerSelecting || options.isFocusing) return false;
1535
+ return true;
1536
+ }
1537
+ function hasActiveFormulaEmbedInteraction(scopeElement) {
1538
+ const ownerDocument = scopeElement === null || scopeElement === void 0 ? void 0 : scopeElement.ownerDocument;
1539
+ return isEventTargetInSameFormulaEmbedInteractionBoundary(scopeElement, ownerDocument === null || ownerDocument === void 0 ? void 0 : ownerDocument.activeElement);
1540
+ }
1174
1541
  const useFocus = (editor) => {
1175
1542
  const editorService = (0, _univerjs_ui.useDependency)(_univerjs_docs_ui.IEditorService);
1176
1543
  return (0, _univerjs_ui.useEvent)((offset) => {
1177
- if (editor) {
1178
- editorService.focus(editor.getEditorId());
1179
- const selections = [...editor.getSelectionRanges()];
1180
- if (_univerjs_core.Tools.isDefine(offset)) editor.setSelectionRanges([{
1181
- startOffset: offset,
1182
- endOffset: offset
1183
- }]);
1184
- else if (!selections.length && !editor.docSelectionRenderService.isOnPointerEvent) {
1185
- var _editor$getDocumentDa, _editor$getDocumentDa2;
1186
- const body = (_editor$getDocumentDa = (_editor$getDocumentDa2 = editor.getDocumentData().body) === null || _editor$getDocumentDa2 === void 0 ? void 0 : _editor$getDocumentDa2.dataStream) !== null && _editor$getDocumentDa !== void 0 ? _editor$getDocumentDa : "\r\n";
1187
- const offset = Math.max(body.length - 2, 0);
1188
- editor.setSelectionRanges([{
1189
- startOffset: offset,
1190
- endOffset: offset
1191
- }]);
1192
- } else editor.setSelectionRanges(selections);
1193
- }
1544
+ focusFormulaEditor(editorService, editor, offset);
1194
1545
  });
1195
1546
  };
1196
1547
 
@@ -1539,9 +1890,16 @@ function getDefaultRefSelectionStyle(themeService) {
1539
1890
 
1540
1891
  //#endregion
1541
1892
  //#region src/views/formula-editor/hooks/use-formula-selection.ts
1542
- function getCurrentBodyDataStreamAndOffset(accssor) {
1543
- var _documentModel$getBod, _documentModel$getBod2;
1544
- const documentModel = accssor.get(_univerjs_core.IUniverInstanceService).getCurrentUniverDocInstance();
1893
+ function resolveFormulaSelectionDataStream(accssor, editor, editorId) {
1894
+ var _editor$getDocumentDa, _documentModel$getBod, _documentModel$getBod2;
1895
+ const editorDataStream = editor === null || editor === void 0 || (_editor$getDocumentDa = editor.getDocumentData().body) === null || _editor$getDocumentDa === void 0 ? void 0 : _editor$getDocumentDa.dataStream;
1896
+ if (editorDataStream != null) return {
1897
+ dataStream: editorDataStream,
1898
+ offset: 0
1899
+ };
1900
+ const univerInstanceService = accssor.get(_univerjs_core.IUniverInstanceService);
1901
+ const editorDocumentModel = editorId ? univerInstanceService.getUnit(editorId, _univerjs_core.UniverInstanceType.UNIVER_DOC) : void 0;
1902
+ const documentModel = editorDocumentModel !== null && editorDocumentModel !== void 0 ? editorDocumentModel : univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
1545
1903
  if (!(documentModel === null || documentModel === void 0 ? void 0 : documentModel.getBody())) return;
1546
1904
  return {
1547
1905
  dataStream: (_documentModel$getBod = (_documentModel$getBod2 = documentModel.getBody()) === null || _documentModel$getBod2 === void 0 ? void 0 : _documentModel$getBod2.dataStream) !== null && _documentModel$getBod !== void 0 ? _documentModel$getBod : "",
@@ -1551,9 +1909,36 @@ function getCurrentBodyDataStreamAndOffset(accssor) {
1551
1909
  function shouldSkipReferenceEditingByPointer(isDisabledByPointer, disableOnClick) {
1552
1910
  return isDisabledByPointer && !disableOnClick;
1553
1911
  }
1912
+ function resolveFormulaSelectionWorkbook(currentWorkbook, fallbackWorkbook) {
1913
+ var _ref;
1914
+ return (_ref = currentWorkbook !== null && currentWorkbook !== void 0 ? currentWorkbook : fallbackWorkbook) !== null && _ref !== void 0 ? _ref : void 0;
1915
+ }
1916
+ function resolveFormulaSelectionCursorIndex(activeRange, dataStream) {
1917
+ const index = (activeRange === null || activeRange === void 0 ? void 0 : activeRange.collapsed) ? activeRange.startOffset : -1;
1918
+ if (index <= 0 && dataStream.startsWith("=") && dataStream.length > 0) return dataStream.length;
1919
+ return index;
1920
+ }
1921
+ function getSelectionAfterLaggingFormulaInput(dataStream, selection, content) {
1922
+ if (!content || content.includes("\r") || content.includes("\n") || !dataStream.startsWith("=") || !(selection === null || selection === void 0 ? void 0 : selection.collapsed)) return;
1923
+ const startOffset = selection.startOffset;
1924
+ if (startOffset == null) return;
1925
+ if (selection.endOffset !== startOffset) return;
1926
+ if (dataStream.slice(startOffset, startOffset + content.length) !== content) return;
1927
+ const nextOffset = startOffset + content.length;
1928
+ return {
1929
+ startOffset: nextOffset,
1930
+ endOffset: nextOffset,
1931
+ collapsed: true
1932
+ };
1933
+ }
1934
+ function resolveFormulaSelectingIntent(adding, editing) {
1935
+ if (adding) return 1;
1936
+ if (editing) return 2;
1937
+ return 0;
1938
+ }
1554
1939
  function useFormulaSelecting(opts) {
1555
1940
  var _renderer$mainCompone2;
1556
- const { editorId, isFocus, disableOnClick, unitId, subUnitId } = opts;
1941
+ const { editor, editorId, isFocus, disableOnClick, unitId, subUnitId } = opts;
1557
1942
  const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
1558
1943
  const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
1559
1944
  const sheetRenderer = renderManagerService.getRenderById(unitId);
@@ -1564,6 +1949,7 @@ function useFormulaSelecting(opts) {
1564
1949
  const [isSelecting, innerSetIsSelecting] = (0, react.useState)(0);
1565
1950
  const lexerTreeBuilder = (0, _univerjs_ui.useDependency)(_univerjs_engine_formula.LexerTreeBuilder);
1566
1951
  const isDisabledByPointer = (0, react.useRef)(true);
1952
+ const lastInputContentRef = (0, react.useRef)("");
1567
1953
  const refSelectionsRenderService = sheetRenderer === null || sheetRenderer === void 0 ? void 0 : sheetRenderer.with(RefSelectionsRenderService);
1568
1954
  const isSelectingRef = useStateRef(isSelecting);
1569
1955
  const workbook = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
@@ -1574,15 +1960,15 @@ function useFormulaSelecting(opts) {
1574
1960
  innerSetIsSelecting(v);
1575
1961
  });
1576
1962
  const calculateSelectingType = (0, _univerjs_ui.useEvent)(() => {
1577
- var _config$dataStream, _lexerTreeBuilder$seq;
1578
- const currentWorkbook = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
1963
+ var _editor$getSelectionR, _editor$getSelectionR2, _config$dataStream, _getSelectionAfterLag, _lexerTreeBuilder$seq;
1964
+ const currentWorkbook = resolveFormulaSelectionWorkbook(univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET), workbook);
1579
1965
  if (!currentWorkbook) return;
1580
1966
  const currentSheet = currentWorkbook.getActiveSheet();
1581
- const activeRange = docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.getActiveTextRange();
1582
- const index = (activeRange === null || activeRange === void 0 ? void 0 : activeRange.collapsed) ? activeRange.startOffset : -1;
1583
- const config = getCurrentBodyDataStreamAndOffset(injector);
1967
+ const activeRange = (_editor$getSelectionR = editor === null || editor === void 0 || (_editor$getSelectionR2 = editor.getSelectionRanges()) === null || _editor$getSelectionR2 === void 0 ? void 0 : _editor$getSelectionR2[0]) !== null && _editor$getSelectionR !== void 0 ? _editor$getSelectionR : docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.getActiveTextRange();
1968
+ const config = resolveFormulaSelectionDataStream(injector, editor, editorId);
1584
1969
  if (!config) return;
1585
1970
  const dataStream = config === null || config === void 0 || (_config$dataStream = config.dataStream) === null || _config$dataStream === void 0 ? void 0 : _config$dataStream.slice(0, -2);
1971
+ const index = resolveFormulaSelectionCursorIndex((_getSelectionAfterLag = getSelectionAfterLaggingFormulaInput(dataStream, activeRange, lastInputContentRef.current)) !== null && _getSelectionAfterLag !== void 0 ? _getSelectionAfterLag : activeRange, dataStream);
1586
1972
  const nodes = ((_lexerTreeBuilder$seq = lexerTreeBuilder.sequenceNodesBuilder(dataStream)) !== null && _lexerTreeBuilder$seq !== void 0 ? _lexerTreeBuilder$seq : []).map((node) => {
1587
1973
  if (typeof node === "object") {
1588
1974
  if (node.nodeType === _univerjs_engine_formula.sequenceNodeType.REFERENCE) return {
@@ -1600,21 +1986,22 @@ function useFormulaSelecting(opts) {
1600
1986
  const nextChar = dataStream[index];
1601
1987
  const focusingNode = nodes.find((node) => typeof node === "object" && node.nodeType === _univerjs_engine_formula.sequenceNodeType.REFERENCE && index === node.endIndex + 2);
1602
1988
  const adding = char && (0, _univerjs_engine_formula.matchRefDrawToken)(char) && (!nextChar || (0, _univerjs_engine_formula.isFormulaLexerToken)(nextChar) && nextChar !== _univerjs_engine_formula.matchToken.OPEN_BRACKET);
1603
- const editing = Boolean(focusingNode);
1604
- if ((dataStream === null || dataStream === void 0 ? void 0 : dataStream.substring(0, 1)) === "=" && (adding || editing)) if (editing) {
1605
- var _univerInstanceServic;
1606
- if (shouldSkipReferenceEditingByPointer(isDisabledByPointer.current, disableOnClick)) return;
1607
- isDisabledByPointer.current = false;
1608
- const { sheetName, unitId } = focusingNode.range;
1609
- const currentUnitId = (_univerInstanceServic = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET)) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getUnitId();
1610
- if (unitId && unitId !== currentUnitId) setIsSelecting(4);
1611
- else if (!sheetName && currentSheet.getSheetId() === (sourceSheet === null || sourceSheet === void 0 ? void 0 : sourceSheet.getSheetId()) || sheetName === currentSheet.getName()) setIsSelecting(2);
1612
- else setIsSelecting(3);
1613
- } else {
1614
- isDisabledByPointer.current = false;
1615
- setIsSelecting(1);
1616
- }
1617
- else setIsSelecting(0);
1989
+ const selectingIntent = resolveFormulaSelectingIntent(Boolean(adding), Boolean(focusingNode));
1990
+ if ((dataStream === null || dataStream === void 0 ? void 0 : dataStream.substring(0, 1)) === "=" && selectingIntent !== 0) {
1991
+ if (selectingIntent === 1) {
1992
+ isDisabledByPointer.current = false;
1993
+ setIsSelecting(1);
1994
+ } else if (focusingNode) {
1995
+ var _resolveFormulaSelect;
1996
+ if (shouldSkipReferenceEditingByPointer(isDisabledByPointer.current, disableOnClick)) return;
1997
+ isDisabledByPointer.current = false;
1998
+ const { sheetName, unitId } = focusingNode.range;
1999
+ const currentUnitId = (_resolveFormulaSelect = resolveFormulaSelectionWorkbook(univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET), workbook)) === null || _resolveFormulaSelect === void 0 ? void 0 : _resolveFormulaSelect.getUnitId();
2000
+ if (unitId && unitId !== currentUnitId) setIsSelecting(4);
2001
+ else if (!sheetName && currentSheet.getSheetId() === (sourceSheet === null || sourceSheet === void 0 ? void 0 : sourceSheet.getSheetId()) || sheetName === currentSheet.getName()) setIsSelecting(2);
2002
+ else setIsSelecting(3);
2003
+ }
2004
+ } else setIsSelecting(0);
1618
2005
  });
1619
2006
  (0, react.useEffect)(() => {
1620
2007
  const sub = docSelectionManagerService.textSelection$.pipe((0, rxjs.filter)((param) => param.unitId === editorId)).subscribe(() => {
@@ -1626,6 +2013,43 @@ function useFormulaSelecting(opts) {
1626
2013
  docSelectionManagerService.textSelection$,
1627
2014
  editorId
1628
2015
  ]);
2016
+ (0, react.useEffect)(() => {
2017
+ if (!isFocus || !editor) return;
2018
+ let timeout;
2019
+ const sub = editor.input$.subscribe(({ content, isComposing }) => {
2020
+ if (!isComposing) lastInputContentRef.current = content;
2021
+ queueMicrotask(() => {
2022
+ calculateSelectingType();
2023
+ });
2024
+ if (timeout) clearTimeout(timeout);
2025
+ timeout = setTimeout(() => {
2026
+ calculateSelectingType();
2027
+ lastInputContentRef.current = "";
2028
+ }, 0);
2029
+ });
2030
+ return () => {
2031
+ if (timeout) clearTimeout(timeout);
2032
+ sub.unsubscribe();
2033
+ };
2034
+ }, [
2035
+ calculateSelectingType,
2036
+ editor,
2037
+ isFocus
2038
+ ]);
2039
+ (0, react.useEffect)(() => {
2040
+ var _editorDocumentModel$;
2041
+ if (!isFocus) return;
2042
+ const editorDocumentModel = univerInstanceService.getUnit(editorId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
2043
+ const sub = editorDocumentModel === null || editorDocumentModel === void 0 || (_editorDocumentModel$ = editorDocumentModel.change$) === null || _editorDocumentModel$ === void 0 ? void 0 : _editorDocumentModel$.subscribe(() => {
2044
+ queueMicrotask(calculateSelectingType);
2045
+ });
2046
+ return () => sub === null || sub === void 0 ? void 0 : sub.unsubscribe();
2047
+ }, [
2048
+ calculateSelectingType,
2049
+ editorId,
2050
+ isFocus,
2051
+ univerInstanceService
2052
+ ]);
1629
2053
  (0, react.useEffect)(() => {
1630
2054
  if (!isFocus) {
1631
2055
  setIsSelecting(0);
@@ -1711,10 +2135,7 @@ function calcHighlightRanges(opts) {
1711
2135
  const workbook = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
1712
2136
  const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getActiveSheet();
1713
2137
  const selectionWithStyle = [];
1714
- if (!workbook || !worksheet) {
1715
- refSelectionsService.setSelections(selectionWithStyle);
1716
- return;
1717
- }
2138
+ if (!workbook || !worksheet) return selectionWithStyle;
1718
2139
  const currentSheetId = worksheet.getSheetId();
1719
2140
  const getSheetIdByName = (name) => {
1720
2141
  var _workbook$getSheetByS;
@@ -1759,6 +2180,7 @@ function calcHighlightRanges(opts) {
1759
2180
  const cursor = (_editor$getSelectionR = editor.getSelectionRanges()) === null || _editor$getSelectionR === void 0 || (_editor$getSelectionR = _editor$getSelectionR[0]) === null || _editor$getSelectionR === void 0 ? void 0 : _editor$getSelectionR.startOffset;
1760
2181
  const activeIndex = endIndexes.findIndex((end) => end + 2 === cursor);
1761
2182
  if (activeIndex !== -1) refSelectionsRenderService === null || refSelectionsRenderService === void 0 || refSelectionsRenderService.setActiveSelectionIndex(activeIndex);
2183
+ else if (selectionWithStyle.length) refSelectionsRenderService === null || refSelectionsRenderService === void 0 || refSelectionsRenderService.setActiveSelectionIndex(selectionWithStyle.length - 1);
1762
2184
  else refSelectionsRenderService === null || refSelectionsRenderService === void 0 || refSelectionsRenderService.resetActiveSelectionIndex();
1763
2185
  }
1764
2186
  return selectionWithStyle;
@@ -1773,14 +2195,25 @@ function useSheetHighlight(unitId, subUnitId) {
1773
2195
  const themeService = (0, _univerjs_ui.useDependency)(_univerjs_core.ThemeService);
1774
2196
  const refSelectionsService = (0, _univerjs_ui.useDependency)(_univerjs_sheets.IRefSelectionsService);
1775
2197
  const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
1776
- const currentWorkbook = (0, _univerjs_ui.useObservable)((0, react.useMemo)(() => univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET), [univerInstanceService]));
1777
- const currentRender = currentWorkbook ? renderManagerService.getRenderById(currentWorkbook.getUnitId()) : null;
1778
- const refSelectionsRenderService = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(RefSelectionsRenderService);
1779
- const sheetSkeletonManagerService = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(_univerjs_sheets_ui.SheetSkeletonManagerService);
1780
- const highlightSheet = (0, _univerjs_ui.useEvent)((refSelections, editor) => {
2198
+ const ownerRender = renderManagerService.getRenderById(unitId);
2199
+ const ownerRefSelectionsRenderService = ownerRender === null || ownerRender === void 0 ? void 0 : ownerRender.with(RefSelectionsRenderService);
2200
+ const getHighlightWorkbook = (0, _univerjs_ui.useEvent)((refSelections) => {
2201
+ const ownerWorkbook = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
1781
2202
  const currentWorkbook = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
2203
+ const currentUnitId = currentWorkbook === null || currentWorkbook === void 0 ? void 0 : currentWorkbook.getUnitId();
2204
+ return Boolean(currentUnitId) && refSelections.some((refSelection) => (0, _univerjs_engine_formula.deserializeRangeWithSheet)(refSelection.token).unitId === currentUnitId) ? currentWorkbook : ownerWorkbook !== null && ownerWorkbook !== void 0 ? ownerWorkbook : currentWorkbook;
2205
+ });
2206
+ const highlightSheet = (0, _univerjs_ui.useEvent)((refSelections, editor, isEnd = false) => {
2207
+ var _currentWorkbook$getA;
2208
+ const currentWorkbook = getHighlightWorkbook(refSelections);
1782
2209
  if (!currentWorkbook) return;
1783
- if (refSelectionsRenderService === null || refSelectionsRenderService === void 0 ? void 0 : refSelectionsRenderService.selectionMoving) return;
2210
+ const currentRender = renderManagerService.getRenderById(currentWorkbook.getUnitId());
2211
+ const refSelectionsRenderService = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(RefSelectionsRenderService);
2212
+ const sheetSelectionRenderService = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(_univerjs_sheets_ui.ISheetSelectionRenderService);
2213
+ const sheetSkeletonManagerService = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(_univerjs_sheets_ui.SheetSkeletonManagerService);
2214
+ if (!isEnd && (refSelectionsRenderService === null || refSelectionsRenderService === void 0 ? void 0 : refSelectionsRenderService.selectionMoving)) return;
2215
+ const currentSheetId = (_currentWorkbook$getA = currentWorkbook.getActiveSheet()) === null || _currentWorkbook$getA === void 0 ? void 0 : _currentWorkbook$getA.getSheetId();
2216
+ if (!currentSheetId) return;
1784
2217
  const selectionWithStyle = calcHighlightRanges({
1785
2218
  unitId,
1786
2219
  subUnitId,
@@ -1795,13 +2228,14 @@ function useSheetHighlight(unitId, subUnitId) {
1795
2228
  });
1796
2229
  if (!selectionWithStyle) return;
1797
2230
  if (((refSelectionsRenderService === null || refSelectionsRenderService === void 0 ? void 0 : refSelectionsRenderService.getSelectionControls()) || []).length === selectionWithStyle.length) refSelectionsRenderService === null || refSelectionsRenderService === void 0 || refSelectionsRenderService.resetSelectionsByModelData(selectionWithStyle);
1798
- else refSelectionsService.setSelections(selectionWithStyle);
2231
+ else refSelectionsService.setSelections(currentWorkbook.getUnitId(), currentSheetId, selectionWithStyle);
2232
+ if (isEnd && selectionWithStyle.length) sheetSelectionRenderService === null || sheetSelectionRenderService === void 0 || sheetSelectionRenderService.resetSelectionsByModelData([]);
1799
2233
  });
1800
2234
  (0, react.useEffect)(() => {
1801
2235
  return () => {
1802
- refSelectionsRenderService === null || refSelectionsRenderService === void 0 || refSelectionsRenderService.resetActiveSelectionIndex();
2236
+ ownerRefSelectionsRenderService === null || ownerRefSelectionsRenderService === void 0 || ownerRefSelectionsRenderService.resetActiveSelectionIndex();
1803
2237
  };
1804
- }, [refSelectionsRenderService]);
2238
+ }, [ownerRefSelectionsRenderService]);
1805
2239
  return highlightSheet;
1806
2240
  }
1807
2241
  function useDocHight(_leadingCharacter = "") {
@@ -1809,23 +2243,18 @@ function useDocHight(_leadingCharacter = "") {
1809
2243
  const colorMap = useColor();
1810
2244
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
1811
2245
  const leadingCharacterLength = (0, react.useMemo)(() => _leadingCharacter.length, [_leadingCharacter]);
1812
- return (0, _univerjs_ui.useEvent)((editor, sequenceNodes, isNeedResetSelection = true, newSelections) => {
2246
+ return (0, _univerjs_ui.useEvent)((editor, sequenceNodes, isNeedResetSelection = true, newSelections, sourceText) => {
1813
2247
  const data = editor.getDocumentData();
1814
2248
  const editorId = editor.getEditorId();
1815
2249
  if (!data) return [];
1816
2250
  const body = data.body;
1817
2251
  if (!body) return [];
1818
2252
  const str = body.dataStream.slice(0, body.dataStream.length - 2);
1819
- const cloneBody = {
1820
- dataStream: "",
1821
- ...data.body
1822
- };
1823
2253
  if (!str.startsWith(_leadingCharacter)) return [];
1824
2254
  if (sequenceNodes == null || sequenceNodes.length === 0) {
1825
- cloneBody.textRuns = [];
1826
2255
  commandService.syncExecuteCommand(_univerjs_docs_ui.ReplaceTextRunsCommand.id, {
1827
2256
  unitId: editorId,
1828
- body: (0, _univerjs_core.getBodySlice)(cloneBody, 0, cloneBody.dataStream.length - 2)
2257
+ body: createFormulaHighlightBody(str, [])
1829
2258
  });
1830
2259
  return [];
1831
2260
  } else {
@@ -1834,19 +2263,16 @@ function useDocHight(_leadingCharacter = "") {
1834
2263
  e.ed = e.ed + leadingCharacterLength;
1835
2264
  e.st = e.st + leadingCharacterLength;
1836
2265
  });
1837
- cloneBody.textRuns = [{
2266
+ const highlightDataStream = getFormulaHighlightDataStream(_leadingCharacter, sequenceNodes, sourceText);
2267
+ const highlightTextRuns = [{
1838
2268
  st: 0,
1839
2269
  ed: 1,
1840
2270
  ts: { fs: 11 }
1841
2271
  }, ...textRuns];
1842
- cloneBody.dataStream = `${_leadingCharacter}${sequenceNodes.reduce((pre, cur) => {
1843
- if (typeof cur === "string") return `${pre}${cur}`;
1844
- return `${pre}${cur.token}`;
1845
- }, "")}\r\n`;
1846
2272
  let selections;
1847
2273
  if (isNeedResetSelection) {
1848
2274
  selections = editor.getSelectionRanges();
1849
- const maxOffset = cloneBody.dataStream.length - 2 + leadingCharacterLength;
2275
+ const maxOffset = highlightDataStream.length - 2 + leadingCharacterLength;
1850
2276
  selections.forEach((selection) => {
1851
2277
  selection.startOffset = Math.max(0, Math.min(selection.startOffset, maxOffset));
1852
2278
  selection.endOffset = Math.max(0, Math.min(selection.endOffset, maxOffset));
@@ -1854,13 +2280,30 @@ function useDocHight(_leadingCharacter = "") {
1854
2280
  }
1855
2281
  commandService.syncExecuteCommand(_univerjs_docs_ui.ReplaceTextRunsCommand.id, {
1856
2282
  unitId: editorId,
1857
- body: (0, _univerjs_core.getBodySlice)(cloneBody, 0, cloneBody.dataStream.length - 2),
2283
+ body: createFormulaHighlightBody(highlightDataStream.slice(0, -2), highlightTextRuns),
1858
2284
  textRanges: newSelections !== null && newSelections !== void 0 ? newSelections : selections
1859
2285
  });
1860
2286
  return refSelections;
1861
2287
  }
1862
2288
  });
1863
2289
  }
2290
+ /**
2291
+ * ReplaceTextRunsCommand shifts the editor's existing structural metadata when text changes.
2292
+ * Its replacement body must therefore contain only inline formula data; carrying paragraphs
2293
+ * or section breaks copied from the old snapshot would leave their indexes stale.
2294
+ */
2295
+ function createFormulaHighlightBody(dataStream, textRuns) {
2296
+ return {
2297
+ dataStream,
2298
+ textRuns
2299
+ };
2300
+ }
2301
+ function getFormulaHighlightDataStream(leadingCharacter, sequenceNodes, sourceText) {
2302
+ return `${leadingCharacter}${sourceText !== null && sourceText !== void 0 ? sourceText : sequenceNodes.reduce((pre, cur) => {
2303
+ if (typeof cur === "string") return `${pre}${cur}`;
2304
+ return `${pre}${cur.token}`;
2305
+ }, "")}\r\n`;
2306
+ }
1864
2307
  function useColor() {
1865
2308
  const themeService = (0, _univerjs_ui.useDependency)(_univerjs_core.ThemeService);
1866
2309
  return (0, react.useMemo)(() => {
@@ -1963,17 +2406,41 @@ function buildTextRuns(descriptionService, colorMap, sequenceNodes) {
1963
2406
 
1964
2407
  //#endregion
1965
2408
  //#region src/views/formula-editor/hooks/use-left-and-right-arrow.ts
1966
- const useLeftAndRightArrow = (isNeed, shouldMoveSelection, editor, onMoveInEditor) => {
2409
+ function shouldMoveFormulaSelectionFromCurrentSelection(selectingType, refSelectionCount) {
2410
+ if (selectingType === 1) return refSelectionCount === 0;
2411
+ return selectingType === 3;
2412
+ }
2413
+ function isFormulaEditorInteractionOwner(focusEditorId, editorId, options) {
2414
+ var _options$formulaBarEd, _options$normalEditor;
2415
+ if (focusEditorId === editorId) return true;
2416
+ if (!(options === null || options === void 0 ? void 0 : options.fxBarFocused)) return false;
2417
+ return editorId === ((_options$formulaBarEd = options.formulaBarEditorId) !== null && _options$formulaBarEd !== void 0 ? _options$formulaBarEd : _univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY) && focusEditorId === ((_options$normalEditor = options.normalEditorId) !== null && _options$normalEditor !== void 0 ? _options$normalEditor : _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
2418
+ }
2419
+ const useLeftAndRightArrow = (isNeed, shouldMoveSelection, editor, onMoveInEditor, getRefSelectionCount) => {
1967
2420
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
1968
2421
  const shortcutService = (0, _univerjs_ui.useDependency)(_univerjs_ui.IShortcutService);
2422
+ const editorService = (0, _univerjs_ui.useDependency)(_univerjs_docs_ui.IEditorService);
2423
+ const contextService = (0, _univerjs_ui.useDependency)(_univerjs_core.IContextService);
2424
+ const operationNamespace = (0, react.useMemo)(() => (0, _univerjs_core.generateRandomId)(4), []);
1969
2425
  const shouldMoveSelectionRef = (0, react.useRef)(shouldMoveSelection);
1970
2426
  shouldMoveSelectionRef.current = shouldMoveSelection;
1971
2427
  const onMoveInEditorRef = (0, react.useRef)(onMoveInEditor);
1972
2428
  onMoveInEditorRef.current = onMoveInEditor;
2429
+ const getRefSelectionCountRef = (0, react.useRef)(getRefSelectionCount);
2430
+ getRefSelectionCountRef.current = getRefSelectionCount;
1973
2431
  (0, react.useEffect)(() => {
1974
2432
  if (!editor || !isNeed) return;
1975
- const operationId = `sheet.formula-embedding-editor.${editor.getEditorId()}`;
2433
+ const editorId = editor.getEditorId();
2434
+ const operationId = `sheet.formula-embedding-editor.${editorId}.${operationNamespace}`;
1976
2435
  const d = new _univerjs_core.DisposableCollection();
2436
+ const shouldHandleShortcut = () => {
2437
+ try {
2438
+ const fxBarFocused = contextService.getContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR);
2439
+ return isFormulaEditorInteractionOwner(editorService.getFocusId(), editorId, { fxBarFocused }) && (editor.docSelectionRenderService.isFocusing || fxBarFocused);
2440
+ } catch {
2441
+ return false;
2442
+ }
2443
+ };
1977
2444
  const handleMoveInEditor = (keycode, metaKey) => {
1978
2445
  if (onMoveInEditorRef.current) {
1979
2446
  onMoveInEditorRef.current(keycode, metaKey);
@@ -1992,27 +2459,30 @@ const useLeftAndRightArrow = (isNeed, shouldMoveSelection, editor, onMoveInEdito
1992
2459
  else if (keycode === _univerjs_ui.KeyCode.ARROW_UP) direction = _univerjs_core.Direction.UP;
1993
2460
  else if (keycode === _univerjs_ui.KeyCode.ARROW_LEFT) direction = _univerjs_core.Direction.LEFT;
1994
2461
  else if (keycode === _univerjs_ui.KeyCode.ARROW_RIGHT) direction = _univerjs_core.Direction.RIGHT;
1995
- if (shouldMoveSelectionRef.current) if (metaKey === _univerjs_ui.MetaKeys.CTRL_COMMAND) commandService.executeCommand(_univerjs_sheets_ui.MoveSelectionCommand.id, {
1996
- direction,
1997
- jumpOver: _univerjs_sheets_ui.JumpOver.moveGap,
1998
- extra: "formula-editor",
1999
- fromCurrentSelection: shouldMoveSelectionRef.current === 1 || shouldMoveSelectionRef.current === 3
2000
- });
2001
- else if (metaKey === _univerjs_ui.MetaKeys.SHIFT) commandService.executeCommand(_univerjs_sheets_ui.ExpandSelectionCommand.id, {
2002
- direction,
2003
- extra: "formula-editor"
2004
- });
2005
- else if (metaKey === (_univerjs_ui.MetaKeys.CTRL_COMMAND | _univerjs_ui.MetaKeys.SHIFT)) commandService.executeCommand(_univerjs_sheets_ui.ExpandSelectionCommand.id, {
2006
- direction,
2007
- jumpOver: _univerjs_sheets_ui.JumpOver.moveGap,
2008
- extra: "formula-editor"
2009
- });
2010
- else commandService.executeCommand(_univerjs_sheets_ui.MoveSelectionCommand.id, {
2011
- direction,
2012
- extra: "formula-editor",
2013
- fromCurrentSelection: shouldMoveSelectionRef.current === 1 || shouldMoveSelectionRef.current === 3
2014
- });
2015
- else handleMoveInEditor(keycode, metaKey);
2462
+ if (shouldMoveSelectionRef.current) {
2463
+ var _getRefSelectionCount, _getRefSelectionCount2;
2464
+ const fromCurrentSelection = shouldMoveFormulaSelectionFromCurrentSelection(shouldMoveSelectionRef.current, (_getRefSelectionCount = (_getRefSelectionCount2 = getRefSelectionCountRef.current) === null || _getRefSelectionCount2 === void 0 ? void 0 : _getRefSelectionCount2.call(getRefSelectionCountRef)) !== null && _getRefSelectionCount !== void 0 ? _getRefSelectionCount : 0);
2465
+ if (metaKey === _univerjs_ui.MetaKeys.CTRL_COMMAND) commandService.executeCommand(_univerjs_sheets_ui.MoveSelectionCommand.id, {
2466
+ direction,
2467
+ jumpOver: _univerjs_sheets_ui.JumpOver.moveGap,
2468
+ extra: "formula-editor",
2469
+ fromCurrentSelection
2470
+ });
2471
+ else if (metaKey === _univerjs_ui.MetaKeys.SHIFT) commandService.executeCommand(_univerjs_sheets_ui.ExpandSelectionCommand.id, {
2472
+ direction,
2473
+ extra: "formula-editor"
2474
+ });
2475
+ else if (metaKey === (_univerjs_ui.MetaKeys.CTRL_COMMAND | _univerjs_ui.MetaKeys.SHIFT)) commandService.executeCommand(_univerjs_sheets_ui.ExpandSelectionCommand.id, {
2476
+ direction,
2477
+ jumpOver: _univerjs_sheets_ui.JumpOver.moveGap,
2478
+ extra: "formula-editor"
2479
+ });
2480
+ else commandService.executeCommand(_univerjs_sheets_ui.MoveSelectionCommand.id, {
2481
+ direction,
2482
+ extra: "formula-editor",
2483
+ fromCurrentSelection
2484
+ });
2485
+ } else handleMoveInEditor(keycode, metaKey);
2016
2486
  };
2017
2487
  d.add(commandService.registerCommand({
2018
2488
  id: operationId,
@@ -2079,7 +2549,7 @@ const useLeftAndRightArrow = (isNeed, shouldMoveSelection, editor, onMoveInEdito
2079
2549
  return {
2080
2550
  id: operationId,
2081
2551
  binding: metaKey ? keyCode | metaKey : keyCode,
2082
- preconditions: () => true,
2552
+ preconditions: shouldHandleShortcut,
2083
2553
  priority: 900,
2084
2554
  staticParameters: {
2085
2555
  eventType: _univerjs_engine_render.DeviceInputEventType.Keyboard,
@@ -2095,8 +2565,11 @@ const useLeftAndRightArrow = (isNeed, shouldMoveSelection, editor, onMoveInEdito
2095
2565
  };
2096
2566
  }, [
2097
2567
  commandService,
2568
+ contextService,
2098
2569
  editor,
2570
+ editorService,
2099
2571
  isNeed,
2572
+ operationNamespace,
2100
2573
  shortcutService
2101
2574
  ]);
2102
2575
  };
@@ -2132,7 +2605,7 @@ const useRefactorEffect = (isNeed, selecting, unitId, editorId, disableContextMe
2132
2605
  editorId
2133
2606
  ]);
2134
2607
  (0, react.useLayoutEffect)(() => {
2135
- if (isNeed && selecting) {
2608
+ if (isNeed && Boolean(selecting)) {
2136
2609
  const d1 = refSelectionsRenderService === null || refSelectionsRenderService === void 0 ? void 0 : refSelectionsRenderService.enableSelectionChanging();
2137
2610
  contextService.setContextValue(_univerjs_sheets.REF_SELECTIONS_ENABLED, true);
2138
2611
  return () => {
@@ -2203,18 +2676,45 @@ const prepareSelectionChangeContext = (opts) => {
2203
2676
  var _editor$getDocumentDa, _editor$getDocumentDa2, _lexerTreeBuilder$seq;
2204
2677
  const { editor, lexerTreeBuilder } = opts;
2205
2678
  const currentDocSelections = editor === null || editor === void 0 ? void 0 : editor.getSelectionRanges();
2206
- if ((currentDocSelections === null || currentDocSelections === void 0 ? void 0 : currentDocSelections.length) !== 1) return;
2207
- const offset = currentDocSelections[0].startOffset - 1;
2208
2679
  const dataStream = ((_editor$getDocumentDa = editor === null || editor === void 0 || (_editor$getDocumentDa2 = editor.getDocumentData().body) === null || _editor$getDocumentDa2 === void 0 ? void 0 : _editor$getDocumentDa2.dataStream) !== null && _editor$getDocumentDa !== void 0 ? _editor$getDocumentDa : "\r\n").slice(0, -2);
2209
2680
  const sequenceNodes = (_lexerTreeBuilder$seq = lexerTreeBuilder.sequenceNodesBuilder(dataStream.slice(1))) !== null && _lexerTreeBuilder$seq !== void 0 ? _lexerTreeBuilder$seq : [];
2681
+ let offset;
2682
+ if ((currentDocSelections === null || currentDocSelections === void 0 ? void 0 : currentDocSelections.length) === 1) offset = currentDocSelections[0].startOffset - 1;
2683
+ else if (dataStream.startsWith("=")) offset = Math.max(dataStream.length - 1, 0);
2684
+ else return;
2210
2685
  const nodeIndex = findIndexFromSequenceNodes(sequenceNodes, offset, false);
2211
2686
  return {
2212
2687
  nodeIndex,
2213
2688
  updatingRefIndex: findRefSequenceIndex(sequenceNodes, nodeIndex),
2689
+ formulaText: dataStream.slice(1),
2214
2690
  sequenceNodes,
2215
2691
  offset
2216
2692
  };
2217
2693
  };
2694
+ function getSequenceNodeCharAtOffset(sequenceNodes, offset) {
2695
+ let currentOffset = 0;
2696
+ for (const node of sequenceNodes) {
2697
+ const text = typeof node === "string" ? node : node.token;
2698
+ const nextOffset = currentOffset + text.length;
2699
+ if (offset > currentOffset && offset <= nextOffset) return text[offset - currentOffset - 1];
2700
+ currentOffset = nextOffset;
2701
+ }
2702
+ }
2703
+ function isFormulaReferenceAddingContext(sequenceNodes, offset) {
2704
+ const char = getSequenceNodeCharAtOffset(sequenceNodes, offset);
2705
+ return Boolean(char && (0, _univerjs_engine_formula.matchRefDrawToken)(char));
2706
+ }
2707
+ function isFormulaReferenceAddingTextContext(formulaText, offset) {
2708
+ const char = formulaText[offset - 1];
2709
+ const nextChar = formulaText[offset];
2710
+ return Boolean(char && (0, _univerjs_engine_formula.matchRefDrawToken)(char) && (!nextChar || (0, _univerjs_engine_formula.isFormulaLexerToken)(nextChar) && nextChar !== _univerjs_engine_formula.matchToken.OPEN_BRACKET));
2711
+ }
2712
+ function insertFormulaReferenceText(formulaText, refText, offset) {
2713
+ return `${formulaText.slice(0, offset)}${refText}${formulaText.slice(offset)}`;
2714
+ }
2715
+ function shouldSkipFormulaReferenceUpdate(isAdd, selectionCount) {
2716
+ return !isAdd && selectionCount === 0;
2717
+ }
2218
2718
  function getSelectionsForFormulaRefUpdate(selections, updatingRefIndex, isCtrlAddMode) {
2219
2719
  const orderedSelections = [...selections];
2220
2720
  if (updatingRefIndex === -1) return { orderedSelections };
@@ -2226,17 +2726,78 @@ function getSelectionsForFormulaRefUpdate(selections, updatingRefIndex, isCtrlAd
2226
2726
  insertedSelection
2227
2727
  };
2228
2728
  }
2729
+ function getLastFormulaSelection(selections) {
2730
+ return selections[selections.length - 1];
2731
+ }
2732
+ function getFormulaSelectionIdentityKey(selection) {
2733
+ var _ref, _item$rangeWithCoord, _range$startRow, _range$endRow, _range$startColumn, _range$endColumn;
2734
+ const item = selection;
2735
+ const range = (_ref = (_item$rangeWithCoord = item.rangeWithCoord) !== null && _item$rangeWithCoord !== void 0 ? _item$rangeWithCoord : item.range) !== null && _ref !== void 0 ? _ref : item;
2736
+ return [
2737
+ (_range$startRow = range.startRow) !== null && _range$startRow !== void 0 ? _range$startRow : "",
2738
+ (_range$endRow = range.endRow) !== null && _range$endRow !== void 0 ? _range$endRow : "",
2739
+ (_range$startColumn = range.startColumn) !== null && _range$startColumn !== void 0 ? _range$startColumn : "",
2740
+ (_range$endColumn = range.endColumn) !== null && _range$endColumn !== void 0 ? _range$endColumn : ""
2741
+ ].join(":");
2742
+ }
2743
+ function isSameFormulaSelection(first, second) {
2744
+ return getFormulaSelectionIdentityKey(first) === getFormulaSelectionIdentityKey(second);
2745
+ }
2746
+ const SHARED_SELECTION_CHANGE_DUPLICATE_END_GUARDS = /* @__PURE__ */ new Map();
2747
+ function getSharedSelectionChangeDuplicateEndGuard(key) {
2748
+ let guard = SHARED_SELECTION_CHANGE_DUPLICATE_END_GUARDS.get(key);
2749
+ if (!guard) {
2750
+ guard = createSelectionChangeDuplicateEndGuard();
2751
+ SHARED_SELECTION_CHANGE_DUPLICATE_END_GUARDS.set(key, guard);
2752
+ }
2753
+ return guard;
2754
+ }
2755
+ function createSelectionChangeDuplicateEndGuard() {
2756
+ let lastTransientSelectionsKey;
2757
+ const getSelectionsKey = (selections) => selections.map(getFormulaSelectionIdentityKey).join("|");
2758
+ return {
2759
+ shouldSkip(selections, isEnd) {
2760
+ const selectionsKey = getSelectionsKey(selections);
2761
+ if (selectionsKey === lastTransientSelectionsKey) return true;
2762
+ if (isEnd) {
2763
+ lastTransientSelectionsKey = void 0;
2764
+ return false;
2765
+ }
2766
+ lastTransientSelectionsKey = selectionsKey;
2767
+ return false;
2768
+ },
2769
+ reset() {
2770
+ lastTransientSelectionsKey = void 0;
2771
+ }
2772
+ };
2773
+ }
2229
2774
  function createSelectionChangeHandler(opts) {
2775
+ var _opts$duplicateEndGua;
2230
2776
  let prevSelectionsCount = opts.initialSelectionsCount;
2231
2777
  let pendingCtrlAddCount = 0;
2778
+ const duplicateEndGuard = (_opts$duplicateEndGua = opts.duplicateEndGuard) !== null && _opts$duplicateEndGua !== void 0 ? _opts$duplicateEndGua : createSelectionChangeDuplicateEndGuard();
2232
2779
  return (selections, isEnd, options) => {
2233
2780
  if (options === null || options === void 0 ? void 0 : options.initial) return;
2234
- const isCtrlAddMode = selections.length > prevSelectionsCount;
2781
+ if (selections.length === 0) return;
2782
+ const isCtrlAddMode = !(options === null || options === void 0 ? void 0 : options.initial) && prevSelectionsCount > 0 && selections.length > prevSelectionsCount;
2235
2783
  if (isCtrlAddMode && !isEnd) {
2236
2784
  pendingCtrlAddCount = selections.length;
2785
+ if (duplicateEndGuard.shouldSkip(selections, false)) return;
2786
+ opts.onSelectionsChange(selections, false, true);
2787
+ prevSelectionsCount = selections.length;
2788
+ pendingCtrlAddCount = 0;
2237
2789
  return;
2238
2790
  }
2239
2791
  const shouldApplyPendingCtrlAdd = isEnd && selections.length === pendingCtrlAddCount;
2792
+ if (duplicateEndGuard.shouldSkip(selections, isEnd)) {
2793
+ if (isEnd) {
2794
+ var _opts$onDuplicateEnd;
2795
+ (_opts$onDuplicateEnd = opts.onDuplicateEnd) === null || _opts$onDuplicateEnd === void 0 || _opts$onDuplicateEnd.call(opts, selections);
2796
+ }
2797
+ prevSelectionsCount = selections.length;
2798
+ pendingCtrlAddCount = 0;
2799
+ return;
2800
+ }
2240
2801
  if (isEnd) {
2241
2802
  prevSelectionsCount = selections.length;
2242
2803
  pendingCtrlAddCount = 0;
@@ -2244,12 +2805,29 @@ function createSelectionChangeHandler(opts) {
2244
2805
  opts.onSelectionsChange(selections, isEnd, isCtrlAddMode || shouldApplyPendingCtrlAdd);
2245
2806
  };
2246
2807
  }
2808
+ function replaceFormulaControlSelection(selections, index, newRange) {
2809
+ const current = selections[index];
2810
+ if (!current) return;
2811
+ const nextRange = {
2812
+ ...newRange,
2813
+ sheetId: current.sheetId,
2814
+ unitId: current.unitId
2815
+ };
2816
+ const nextSelections = [...selections];
2817
+ nextSelections[index] = nextRange;
2818
+ return nextSelections;
2819
+ }
2820
+ function getInitialFormulaReferenceSelectionCount(renderSelectionCount, formulaReferenceCount, selectingType) {
2821
+ return Math.max(renderSelectionCount, formulaReferenceCount);
2822
+ }
2247
2823
  const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUnitId, getRefSelections, isSupportAcrossSheet, listenSelectionSet, editor, handleRangeChange = _univerjs_core.noop) => {
2248
- var _currentUnit$getUnitI;
2824
+ var _activeWorkbook$getUn;
2249
2825
  const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
2250
2826
  const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
2251
2827
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
2828
+ const contextService = (0, _univerjs_ui.useDependency)(_univerjs_core.IContextService);
2252
2829
  const docSelectionManagerService = (0, _univerjs_ui.useDependency)(_univerjs_docs.DocSelectionManagerService);
2830
+ const editorService = (0, _univerjs_ui.useDependency)(_univerjs_docs_ui.IEditorService);
2253
2831
  const themeService = (0, _univerjs_ui.useDependency)(_univerjs_core.ThemeService);
2254
2832
  const lexerTreeBuilder = (0, _univerjs_ui.useDependency)(_univerjs_engine_formula.LexerTreeBuilder);
2255
2833
  const workbook = univerInstanceService.getUnit(unitId);
@@ -2267,32 +2845,39 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2267
2845
  activeSheet,
2268
2846
  sheetName
2269
2847
  });
2270
- const currentUnit = (0, _univerjs_ui.useObservable)((0, react.useMemo)(() => univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET), [univerInstanceService]));
2271
- const render = renderManagerService.getRenderById((_currentUnit$getUnitI = currentUnit === null || currentUnit === void 0 ? void 0 : currentUnit.getUnitId()) !== null && _currentUnit$getUnitI !== void 0 ? _currentUnit$getUnitI : "");
2848
+ const activeWorkbook = resolveFormulaSelectionWorkbook((0, _univerjs_ui.useObservable)((0, react.useMemo)(() => univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET), [univerInstanceService])), workbook);
2849
+ const render = renderManagerService.getRenderById((_activeWorkbook$getUn = activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== null && _activeWorkbook$getUn !== void 0 ? _activeWorkbook$getUn : unitId);
2272
2850
  const refSelectionsRenderService = render === null || render === void 0 ? void 0 : render.with(RefSelectionsRenderService);
2273
2851
  const sheetSkeletonManagerService = render === null || render === void 0 ? void 0 : render.with(_univerjs_sheets_ui.SheetSkeletonManagerService);
2274
2852
  const refSelectionsService = (0, _univerjs_ui.useDependency)(_univerjs_sheets.IRefSelectionsService);
2853
+ const duplicateEndGuard = (0, react.useMemo)(() => getSharedSelectionChangeDuplicateEndGuard(`${unitId}:${subUnitId}`), [subUnitId, unitId]);
2275
2854
  const onSelectionsChange = (0, _univerjs_ui.useEvent)((selections, isEnd, isCtrlAddMode) => {
2855
+ if (!editor || !isFormulaEditorInteractionOwner(editorService.getFocusId(), editor.getEditorId(), { fxBarFocused: contextService.getContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR) })) return;
2276
2856
  const ctx = prepareSelectionChangeContext({
2277
2857
  editor,
2278
2858
  lexerTreeBuilder
2279
2859
  });
2280
2860
  if (!ctx) return;
2281
- const { nodeIndex, updatingRefIndex, sequenceNodes, offset } = ctx;
2282
- if (isSelectingRef.current === 1) if (offset !== 0) {
2861
+ const { nodeIndex, updatingRefIndex, formulaText, sequenceNodes, offset } = ctx;
2862
+ if (isSelectingRef.current === 1 || isFormulaReferenceAddingContext(sequenceNodes, offset) || isFormulaReferenceAddingTextContext(formulaText, offset)) if (offset !== 0) {
2283
2863
  var _range$sheetId, _range$unitId, _range$unitId2;
2284
2864
  if (nodeIndex === -1 && sequenceNodes.length) return;
2285
- const range = selections[selections.length - 1];
2865
+ const range = getLastFormulaSelection(selections);
2866
+ if (!range) return;
2286
2867
  const lastNodes = sequenceNodes.splice(nodeIndex + 1);
2287
2868
  const rangeSheetId = (_range$sheetId = range.sheetId) !== null && _range$sheetId !== void 0 ? _range$sheetId : subUnitId;
2288
2869
  const unitRangeName = {
2289
2870
  range,
2290
- unitId: (_range$unitId = range.unitId) !== null && _range$unitId !== void 0 ? _range$unitId : currentUnit.getUnitId(),
2291
- sheetName: getSheetNameById((_range$unitId2 = range.unitId) !== null && _range$unitId2 !== void 0 ? _range$unitId2 : currentUnit.getUnitId(), rangeSheetId)
2871
+ unitId: (_range$unitId = range.unitId) !== null && _range$unitId !== void 0 ? _range$unitId : activeWorkbook.getUnitId(),
2872
+ sheetName: getSheetNameById((_range$unitId2 = range.unitId) !== null && _range$unitId2 !== void 0 ? _range$unitId2 : activeWorkbook.getUnitId(), rangeSheetId)
2292
2873
  };
2293
2874
  const isAcrossSheet = rangeSheetId !== subUnitId;
2294
- const isAcrossWorkbook = (currentUnit === null || currentUnit === void 0 ? void 0 : currentUnit.getUnitId()) !== unitId;
2875
+ const isAcrossWorkbook = (activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== unitId;
2295
2876
  const refRanges = unitRangesToText([unitRangeName], isSupportAcrossSheet && (isAcrossSheet || isAcrossWorkbook), sheetName, isAcrossWorkbook);
2877
+ if (isFormulaReferenceAddingTextContext(formulaText, offset)) {
2878
+ handleRangeChange(insertFormulaReferenceText(formulaText, refRanges[0], offset), offset + refRanges[0].length, isEnd);
2879
+ return;
2880
+ }
2296
2881
  sequenceNodes.push({
2297
2882
  token: refRanges[0],
2298
2883
  nodeType: _univerjs_engine_formula.sequenceNodeType.REFERENCE
@@ -2300,15 +2885,16 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2300
2885
  handleRangeChange(sequenceNodeToText([...sequenceNodes, ...lastNodes]), getOffsetFromSequenceNodes(sequenceNodes), isEnd);
2301
2886
  } else {
2302
2887
  var _range$sheetId2, _range$unitId3, _range$unitId4;
2303
- const range = selections[selections.length - 1];
2888
+ const range = getLastFormulaSelection(selections);
2889
+ if (!range) return;
2304
2890
  const rangeSheetId = (_range$sheetId2 = range.sheetId) !== null && _range$sheetId2 !== void 0 ? _range$sheetId2 : subUnitId;
2305
2891
  const unitRangeName = {
2306
2892
  range,
2307
- unitId: (_range$unitId3 = range.unitId) !== null && _range$unitId3 !== void 0 ? _range$unitId3 : currentUnit.getUnitId(),
2308
- sheetName: getSheetNameById((_range$unitId4 = range.unitId) !== null && _range$unitId4 !== void 0 ? _range$unitId4 : currentUnit.getUnitId(), rangeSheetId)
2893
+ unitId: (_range$unitId3 = range.unitId) !== null && _range$unitId3 !== void 0 ? _range$unitId3 : activeWorkbook.getUnitId(),
2894
+ sheetName: getSheetNameById((_range$unitId4 = range.unitId) !== null && _range$unitId4 !== void 0 ? _range$unitId4 : activeWorkbook.getUnitId(), rangeSheetId)
2309
2895
  };
2310
2896
  const isAcrossSheet = rangeSheetId !== subUnitId;
2311
- const isAcrossWorkbook = (currentUnit === null || currentUnit === void 0 ? void 0 : currentUnit.getUnitId()) !== unitId;
2897
+ const isAcrossWorkbook = (activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== unitId;
2312
2898
  const refRanges = unitRangesToText([unitRangeName], isSupportAcrossSheet && (isAcrossSheet || isAcrossWorkbook), sheetName, isAcrossWorkbook);
2313
2899
  sequenceNodes.unshift({
2314
2900
  token: refRanges[0],
@@ -2322,9 +2908,9 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2322
2908
  const node = sequenceNodes[nodeIndex];
2323
2909
  if (typeof node === "object" && node.nodeType === _univerjs_engine_formula.sequenceNodeType.REFERENCE) {
2324
2910
  const oldToken = node.token;
2325
- if ((currentUnit === null || currentUnit === void 0 ? void 0 : currentUnit.getUnitId()) !== unitId) {
2326
- var _currentUnit$getUnitI2;
2327
- node.token = (0, _univerjs_engine_formula.serializeRangeWithSpreadsheet)((_currentUnit$getUnitI2 = currentUnit === null || currentUnit === void 0 ? void 0 : currentUnit.getUnitId()) !== null && _currentUnit$getUnitI2 !== void 0 ? _currentUnit$getUnitI2 : "", sheetName, last);
2911
+ if ((activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== unitId) {
2912
+ var _activeWorkbook$getUn2;
2913
+ node.token = (0, _univerjs_engine_formula.serializeRangeWithSpreadsheet)((_activeWorkbook$getUn2 = activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== null && _activeWorkbook$getUn2 !== void 0 ? _activeWorkbook$getUn2 : "", sheetName, last);
2328
2914
  } else node.token = sheetName === (activeSheet === null || activeSheet === void 0 ? void 0 : activeSheet.getName()) ? (0, _univerjs_engine_formula.serializeRange)(last) : (0, _univerjs_engine_formula.serializeRangeWithSheet)(activeSheet.getName(), last);
2329
2915
  const newOffset = offset + (node.token.length - oldToken.length);
2330
2916
  handleRangeChange((0, _univerjs_engine_formula.generateStringWithSequence)(sequenceNodes), newOffset, isEnd);
@@ -2336,10 +2922,10 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2336
2922
  const rangeSheetId = (_range$sheetId3 = range.sheetId) !== null && _range$sheetId3 !== void 0 ? _range$sheetId3 : subUnitId;
2337
2923
  const unitRangeName = {
2338
2924
  range,
2339
- unitId: (_range$unitId5 = range.unitId) !== null && _range$unitId5 !== void 0 ? _range$unitId5 : currentUnit.getUnitId(),
2340
- sheetName: getSheetNameById((_range$unitId6 = range.unitId) !== null && _range$unitId6 !== void 0 ? _range$unitId6 : currentUnit.getUnitId(), rangeSheetId)
2925
+ unitId: (_range$unitId5 = range.unitId) !== null && _range$unitId5 !== void 0 ? _range$unitId5 : activeWorkbook.getUnitId(),
2926
+ sheetName: getSheetNameById((_range$unitId6 = range.unitId) !== null && _range$unitId6 !== void 0 ? _range$unitId6 : activeWorkbook.getUnitId(), rangeSheetId)
2341
2927
  };
2342
- const isAcrossWorkbook = (currentUnit === null || currentUnit === void 0 ? void 0 : currentUnit.getUnitId()) !== unitId;
2928
+ const isAcrossWorkbook = (activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== unitId;
2343
2929
  return unitRangesToText([unitRangeName], isSupportAcrossSheet && (rangeSheetId !== subUnitId || isAcrossWorkbook), sheetName, isAcrossWorkbook)[0];
2344
2930
  };
2345
2931
  let currentRefIndex = 0;
@@ -2348,7 +2934,7 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2348
2934
  if (item.nodeType === _univerjs_engine_formula.sequenceNodeType.REFERENCE) {
2349
2935
  const nodeRange = (0, _univerjs_engine_formula.deserializeRangeWithSheet)(item.token);
2350
2936
  if (!nodeRange.sheetName) nodeRange.sheetName = sheetName;
2351
- if ((nodeRange.unitId || unitId) !== (currentUnit === null || currentUnit === void 0 ? void 0 : currentUnit.getUnitId())) return item.token;
2937
+ if ((nodeRange.unitId || unitId) !== (activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId())) return item.token;
2352
2938
  if (isSupportAcrossSheet) {
2353
2939
  var _contextRef$current$a;
2354
2940
  if (((_contextRef$current$a = contextRef.current.activeSheet) === null || _contextRef$current$a === void 0 ? void 0 : _contextRef$current$a.getName()) !== nodeRange.sheetName) return item.token;
@@ -2383,13 +2969,28 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2383
2969
  (0, react.useEffect)(() => {
2384
2970
  if (refSelectionsRenderService && isNeed) {
2385
2971
  const handleSelectionsChange = createSelectionChangeHandler({
2386
- initialSelectionsCount: Math.max(refSelectionsRenderService.getSelectionDataWithStyle().length, refSelectionsService.getCurrentSelections().length, getRefSelections().length),
2972
+ initialSelectionsCount: getInitialFormulaReferenceSelectionCount(refSelectionsRenderService.getSelectionDataWithStyle().length, getRefSelections().length, isSelectingRef.current),
2973
+ duplicateEndGuard: {
2974
+ shouldSkip: (selections, isEnd) => duplicateEndGuard.shouldSkip(selections.map((i) => i.rangeWithCoord), isEnd),
2975
+ reset: duplicateEndGuard.reset
2976
+ },
2387
2977
  onSelectionsChange: (selections, isEnd, isCtrlAddMode) => {
2388
2978
  onSelectionsChange(selections.map((i) => i.rangeWithCoord), isEnd, isCtrlAddMode);
2979
+ },
2980
+ onDuplicateEnd: () => {
2981
+ const ctx = prepareSelectionChangeContext({
2982
+ editor,
2983
+ lexerTreeBuilder
2984
+ });
2985
+ if (!ctx) return;
2986
+ handleRangeChange(ctx.formulaText, ctx.offset, true);
2389
2987
  }
2390
2988
  });
2391
2989
  let isInitialMoveEnd = true;
2392
2990
  const disposableCollection = new _univerjs_core.DisposableCollection();
2991
+ disposableCollection.add(refSelectionsRenderService.selectionMoveStart$.subscribe((selections) => {
2992
+ handleSelectionsChange(selections, false);
2993
+ }));
2393
2994
  disposableCollection.add(refSelectionsRenderService.selectionMoving$.subscribe((selections) => {
2394
2995
  handleSelectionsChange(selections, false);
2395
2996
  }));
@@ -2415,20 +3016,12 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2415
3016
  disposableCollection.dispose();
2416
3017
  refSelectionsRenderService.getSelectionControls().forEach((control, index) => {
2417
3018
  disposableCollection.add(control.selectionScaling$.subscribe((newRange) => {
2418
- const selections = refSelectionsRenderService.getSelectionDataWithStyle().map((i) => i.rangeWithCoord);
2419
- const current = selections[index];
2420
- newRange.sheetId = current.sheetId;
2421
- newRange.unitId = current.unitId;
2422
- selections[index] = newRange;
2423
- onSelectionsChange(selections, false);
3019
+ const nextSelections = replaceFormulaControlSelection(refSelectionsRenderService.getSelectionDataWithStyle().map((i) => i.rangeWithCoord), index, newRange);
3020
+ if (nextSelections) onSelectionsChange(nextSelections, false);
2424
3021
  }));
2425
3022
  disposableCollection.add(control.selectionMoving$.subscribe((newRange) => {
2426
- const selections = refSelectionsRenderService.getSelectionDataWithStyle().map((i) => i.rangeWithCoord);
2427
- const current = selections[index];
2428
- newRange.sheetId = current.sheetId;
2429
- newRange.unitId = current.unitId;
2430
- selections[index] = newRange;
2431
- onSelectionsChange(selections, true);
3023
+ const nextSelections = replaceFormulaControlSelection(refSelectionsRenderService.getSelectionDataWithStyle().map((i) => i.rangeWithCoord), index, newRange);
3024
+ if (nextSelections) onSelectionsChange(nextSelections, true);
2432
3025
  }));
2433
3026
  });
2434
3027
  };
@@ -2452,6 +3045,7 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2452
3045
  if (listenSelectionSet) {
2453
3046
  const d = commandService.onCommandExecuted((commandInfo) => {
2454
3047
  if (commandInfo.id !== _univerjs_sheets.SetSelectionsOperation.id) return;
3048
+ if (!editor || !isFormulaEditorInteractionOwner(editorService.getFocusId(), editor.getEditorId(), { fxBarFocused: contextService.getContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR) })) return;
2455
3049
  const params = commandInfo.params;
2456
3050
  if (params.extra !== "formula-editor") return;
2457
3051
  if (params.selections.length) {
@@ -2467,10 +3061,20 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2467
3061
  }
2468
3062
  range.unitId = params.unitId;
2469
3063
  range.sheetId = params.subUnitId;
2470
- const isAdd = isSelectingRef.current === 1;
3064
+ const ctx = prepareSelectionChangeContext({
3065
+ editor,
3066
+ lexerTreeBuilder
3067
+ });
3068
+ const isAdd = isSelectingRef.current === 1 || Boolean(ctx && (isFormulaReferenceAddingContext(ctx.sequenceNodes, ctx.offset) || isFormulaReferenceAddingTextContext(ctx.formulaText, ctx.offset)));
2471
3069
  const selections = ((_refSelectionsRenderS = refSelectionsRenderService === null || refSelectionsRenderService === void 0 ? void 0 : refSelectionsRenderService.getSelectionDataWithStyle()) !== null && _refSelectionsRenderS !== void 0 ? _refSelectionsRenderS : []).map((i) => i.rangeWithCoord);
2472
- if (isAdd) selections.push(range);
2473
- else selections[selections.length - 1] = range;
3070
+ if (isAdd) {
3071
+ if (selections.length > 0 && isSameFormulaSelection(selections[selections.length - 1], range)) return;
3072
+ selections.push(range);
3073
+ } else {
3074
+ if (shouldSkipFormulaReferenceUpdate(isAdd, selections.length)) return;
3075
+ selections[selections.length - 1] = range;
3076
+ }
3077
+ if (duplicateEndGuard.shouldSkip(selections, true)) return;
2474
3078
  onSelectionsChange(selections, true);
2475
3079
  }
2476
3080
  }
@@ -2481,7 +3085,10 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2481
3085
  }
2482
3086
  }, [
2483
3087
  commandService,
3088
+ contextService,
3089
+ duplicateEndGuard,
2484
3090
  editor,
3091
+ editorService,
2485
3092
  isSelectingRef,
2486
3093
  lexerTreeBuilder,
2487
3094
  listenSelectionSet,
@@ -2502,7 +3109,7 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
2502
3109
  sheetSkeletonManagerService,
2503
3110
  themeService,
2504
3111
  univerInstanceService,
2505
- currentWorkbook: currentUnit
3112
+ currentWorkbook: activeWorkbook
2506
3113
  });
2507
3114
  });
2508
3115
  return () => sub.unsubscribe();
@@ -2864,18 +3471,22 @@ const getFormulaText = (formula) => {
2864
3471
 
2865
3472
  //#endregion
2866
3473
  //#region src/views/formula-editor/index.tsx
3474
+ function shouldApplyFormulaSelectionChange(selectingMode, isFocusing, hasActiveInteraction) {
3475
+ return Boolean(selectingMode) || Boolean(isFocusing) || hasActiveInteraction;
3476
+ }
2867
3477
  function syncCounterpartFormulaEditorSelection(editorService, editorId, selections) {
2868
3478
  var _editorService$getEdi;
2869
3479
  if (!(selections === null || selections === void 0 ? void 0 : selections.length)) return;
2870
3480
  const syncEditorId = editorId === _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY ? _univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY : editorId === _univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY ? _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY : null;
2871
3481
  if (!syncEditorId) return;
2872
- (_editorService$getEdi = editorService.getEditor(syncEditorId)) === null || _editorService$getEdi === void 0 || _editorService$getEdi.setSelectionRanges(selections);
3482
+ (_editorService$getEdi = editorService.getEditor(syncEditorId)) === null || _editorService$getEdi === void 0 || _editorService$getEdi.setSelectionRanges(selections, false);
2873
3483
  }
2874
3484
  const FormulaEditor = (0, react.forwardRef)((props, ref) => {
2875
3485
  var _document$getBody$dat, _document$getBody, _configService$getCon, _configService$getCon2;
2876
3486
  const { errorText, initValue, unitId, subUnitId, isFocus: _isFocus = true, isSupportAcrossSheet = false, onFocus = _univerjs_core.noop, onBlur = _univerjs_core.noop, onChange: propOnChange, onVerify, className, editorId: propEditorId, moveCursor = true, onFormulaSelectingChange: propOnFormulaSelectingChange, keyboardEventConfig, onMoveInEditor, resetSelectionOnBlur = true, autoScrollbar = true, isSingle = true, disableSelectionOnClick = false, autofocus = true, disableContextMenu, style, borderless = false, canvasStyle } = props;
2877
3487
  const editorService = (0, _univerjs_ui.useDependency)(_univerjs_docs_ui.IEditorService);
2878
3488
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
3489
+ const injector = (0, _univerjs_ui.useDependency)(_univerjs_core.Injector);
2879
3490
  const sheetEmbeddingRef = (0, react.useRef)(null);
2880
3491
  const onChange = (0, _univerjs_ui.useEvent)(propOnChange);
2881
3492
  (0, react.useImperativeHandle)(ref, () => ({ isClickOutSide: (e) => {
@@ -2885,7 +3496,7 @@ const FormulaEditor = (0, react.forwardRef)((props, ref) => {
2885
3496
  const onFormulaSelectingChange = (0, _univerjs_ui.useEvent)(propOnFormulaSelectingChange);
2886
3497
  const searchFunctionRef = (0, react.useRef)(null);
2887
3498
  const editorRef = (0, react.useRef)(void 0);
2888
- const editor = editorRef.current;
3499
+ const [editor, setEditor] = (0, react.useState)();
2889
3500
  const [isFocus, setIsFocus] = (0, react.useState)(_isFocus);
2890
3501
  const formulaEditorContainerRef = (0, react.useRef)(null);
2891
3502
  const editorId = (0, react.useMemo)(() => propEditorId !== null && propEditorId !== void 0 ? propEditorId : (0, _univerjs_core.createInternalEditorID)(`${_univerjs_sheets_ui.EMBEDDING_FORMULA_EDITOR}-${(0, _univerjs_core.generateRandomId)(4)}`), []);
@@ -2901,6 +3512,7 @@ const FormulaEditor = (0, react.forwardRef)((props, ref) => {
2901
3512
  const { isSelecting, isSelectingRef } = useFormulaSelecting({
2902
3513
  unitId,
2903
3514
  subUnitId,
3515
+ editor,
2904
3516
  editorId,
2905
3517
  isFocus,
2906
3518
  disableOnClick: disableSelectionOnClick
@@ -2913,11 +3525,33 @@ const FormulaEditor = (0, react.forwardRef)((props, ref) => {
2913
3525
  const docFocusing = (currentDoc === null || currentDoc === void 0 ? void 0 : currentDoc.getUnitId()) === editorId;
2914
3526
  const refSelections = (0, react.useRef)([]);
2915
3527
  const getRefSelections = (0, _univerjs_ui.useEvent)(() => refSelections.current);
3528
+ const getRefSelectionCount = (0, _univerjs_ui.useEvent)(() => getRefSelections().length);
2916
3529
  const selectingMode = isSelecting;
2917
3530
  const functionScreenTips = (_configService$getCon = (_configService$getCon2 = (0, _univerjs_ui.useDependency)(_univerjs_core.IConfigService).getConfig("sheets-formula-ui.base.config")) === null || _configService$getCon2 === void 0 ? void 0 : _configService$getCon2.functionScreenTips) !== null && _configService$getCon !== void 0 ? _configService$getCon : true;
2918
3531
  (0, _univerjs_ui.useUpdateEffect)(() => {
2919
3532
  onChange(formulaText);
2920
3533
  }, [formulaText, onChange]);
3534
+ (0, react.useEffect)(() => {
3535
+ if (!isFocus || !editor) return;
3536
+ const subscription = editor.input$.subscribe(({ content, isComposing }) => {
3537
+ if (isComposing) return;
3538
+ queueMicrotask(() => {
3539
+ var _editor$getSelectionR, _editor$getDocumentDa, _editor$getDocumentDa2;
3540
+ const selection = (_editor$getSelectionR = editor.getSelectionRanges()) === null || _editor$getSelectionR === void 0 ? void 0 : _editor$getSelectionR[0];
3541
+ const normalizedSelection = getSelectionAfterLaggingFormulaInput((_editor$getDocumentDa = (_editor$getDocumentDa2 = editor.getDocumentData().body) === null || _editor$getDocumentDa2 === void 0 ? void 0 : _editor$getDocumentDa2.dataStream) !== null && _editor$getDocumentDa !== void 0 ? _editor$getDocumentDa : "", selection, content);
3542
+ if (!normalizedSelection) return;
3543
+ const selections = [normalizedSelection];
3544
+ editor.setSelectionRanges(selections, false);
3545
+ syncCounterpartFormulaEditorSelection(editorService, editorId, selections);
3546
+ });
3547
+ });
3548
+ return () => subscription.unsubscribe();
3549
+ }, [
3550
+ editor,
3551
+ editorId,
3552
+ editorService,
3553
+ isFocus
3554
+ ]);
2921
3555
  const highlightDoc = useDocHight("=");
2922
3556
  const highlightSheet = useSheetHighlight(unitId, subUnitId);
2923
3557
  const highlight = (0, _univerjs_ui.useEvent)((text, isNeedResetSelection = true, isEnd, newSelections) => {
@@ -2925,18 +3559,18 @@ const FormulaEditor = (0, react.forwardRef)((props, ref) => {
2925
3559
  highTextRef.current = text;
2926
3560
  const formulaStr = text[0] === "=" ? text.slice(1) : "";
2927
3561
  const sequenceNodes = getFormulaToken(formulaStr);
2928
- const parsedFormula = sequenceNodes.reduce((pre, cur) => typeof cur === "object" ? `${pre}${cur.token}` : `${pre}${cur}`, "");
2929
- const ranges = highlightDoc(editorRef.current, parsedFormula === formulaStr ? sequenceNodes : [], isNeedResetSelection, newSelections);
3562
+ const ranges = highlightDoc(editorRef.current, sequenceNodes, isNeedResetSelection, newSelections, formulaStr);
2930
3563
  refSelections.current = ranges;
2931
3564
  if (isEnd) {
2932
3565
  const currentDocSelections = newSelections !== null && newSelections !== void 0 ? newSelections : editor === null || editor === void 0 ? void 0 : editor.getSelectionRanges();
2933
- if ((currentDocSelections === null || currentDocSelections === void 0 ? void 0 : currentDocSelections.length) !== 1) return;
2934
- const refIndex = findRefSequenceIndex(sequenceNodes, findIndexFromSequenceNodes(sequenceNodes, currentDocSelections[0].startOffset - 1, false));
2935
- if (refIndex >= 0) {
2936
- const target = ranges.splice(refIndex, 1)[0];
2937
- target && ranges.push(target);
3566
+ if ((currentDocSelections === null || currentDocSelections === void 0 ? void 0 : currentDocSelections.length) === 1) {
3567
+ const refIndex = findRefSequenceIndex(sequenceNodes, findIndexFromSequenceNodes(sequenceNodes, currentDocSelections[0].startOffset - 1, false));
3568
+ if (refIndex >= 0) {
3569
+ const target = ranges.splice(refIndex, 1)[0];
3570
+ target && ranges.push(target);
3571
+ }
2938
3572
  }
2939
- highlightSheet(isFocus ? ranges : [], editorRef.current);
3573
+ highlightSheet(isFocus ? ranges : [], editorRef.current, isEnd);
2940
3574
  }
2941
3575
  });
2942
3576
  (0, react.useEffect)(() => {
@@ -3001,13 +3635,52 @@ const FormulaEditor = (0, react.forwardRef)((props, ref) => {
3001
3635
  },
3002
3636
  canvasStyle
3003
3637
  }, formulaEditorContainerRef.current);
3004
- editorRef.current = editorService.getEditor(editorId);
3638
+ const registeredEditor = editorService.getEditor(editorId);
3639
+ editorRef.current = registeredEditor;
3640
+ setEditor(registeredEditor);
3005
3641
  highlight(initValue, false, true);
3006
3642
  }
3007
3643
  return () => {
3644
+ editorRef.current = void 0;
3008
3645
  dispose === null || dispose === void 0 || dispose.dispose();
3009
3646
  };
3010
3647
  }, []);
3648
+ (0, react.useEffect)(() => {
3649
+ var _ref, _resolveFormulaEmbedR;
3650
+ const formulaEditorContainer = formulaEditorContainerRef.current;
3651
+ if (!isFocus || !formulaEditorContainer || !injector.has(IFormulaEmbedRuntimeFocusCoordinator)) return;
3652
+ const focusCoordinator = injector.get(IFormulaEmbedRuntimeFocusCoordinator);
3653
+ const scope = (_ref = (_resolveFormulaEmbedR = resolveFormulaEmbedRuntimeDomScope(formulaEditorContainer)) !== null && _resolveFormulaEmbedR !== void 0 ? _resolveFormulaEmbedR : focusCoordinator.resolveRuntimeScopeByChildUnitId(editorId)) !== null && _ref !== void 0 ? _ref : resolveActiveFormulaEmbedRuntimeDomScope(formulaEditorContainer.ownerDocument);
3654
+ if (!scope) return;
3655
+ const collection = new _univerjs_core.DisposableCollection();
3656
+ const interactionBoundaryService = injector.has(IFormulaEmbedInteractionBoundaryService) ? injector.get(IFormulaEmbedInteractionBoundaryService) : void 0;
3657
+ collection.add(focusCoordinator.acquireLease({
3658
+ embedId: scope.embedId,
3659
+ role: "child-editor",
3660
+ owner: "sheet-formula-editor",
3661
+ hostUnitId: scope.hostUnitId,
3662
+ childUnitId: scope.childUnitId,
3663
+ associatedChildUnitIds: [editorId]
3664
+ }));
3665
+ if (interactionBoundaryService) collection.add(interactionBoundaryService.registerOwnedElement(scope.embedId, formulaEditorContainer));
3666
+ collection.add(focusCoordinator.registerElement({
3667
+ embedId: scope.embedId,
3668
+ role: "child-editor",
3669
+ element: formulaEditorContainer
3670
+ }));
3671
+ collection.add(registerFormulaEditorRuntimePortal({
3672
+ embedId: scope.embedId,
3673
+ editorId,
3674
+ ownerDocument: formulaEditorContainer.ownerDocument,
3675
+ interactionBoundaryService,
3676
+ focusCoordinator
3677
+ }));
3678
+ return () => collection.dispose();
3679
+ }, [
3680
+ editorId,
3681
+ injector,
3682
+ isFocus
3683
+ ]);
3011
3684
  (0, react.useLayoutEffect)(() => {
3012
3685
  let focusRetryFrame = 0;
3013
3686
  let finalFocusRetryFrame = 0;
@@ -3041,10 +3714,10 @@ const FormulaEditor = (0, react.forwardRef)((props, ref) => {
3041
3714
  resetSelectionOnBlur
3042
3715
  ]);
3043
3716
  const { checkScrollBar } = (0, _univerjs_docs_ui.useResize)(editor, isSingle, autoScrollbar);
3044
- useRefactorEffect(isFocus, Boolean(isSelecting && docFocusing), unitId, editorId, disableContextMenu);
3045
- useLeftAndRightArrow(Boolean(isFocus && isFocusing && moveCursor), selectingMode, editor, onMoveInEditor);
3717
+ useRefactorEffect(isFocus, isSelecting, unitId, editorId, disableContextMenu);
3718
+ useLeftAndRightArrow(Boolean(isFocus && isFocusing && moveCursor), selectingMode, editor, onMoveInEditor, getRefSelectionCount);
3046
3719
  const handleSelectionChange = (0, _univerjs_ui.useEvent)((refString, offset, isEnd) => {
3047
- if (!isFocusing) return;
3720
+ if (!shouldApplyFormulaSelectionChange(selectingMode, isFocusing, hasActiveFormulaEmbedInteraction(formulaEditorContainerRef.current))) return;
3048
3721
  const newSelections = offset !== -1 ? [{
3049
3722
  startOffset: offset + 1,
3050
3723
  endOffset: offset + 1,
@@ -3068,7 +3741,7 @@ const FormulaEditor = (0, react.forwardRef)((props, ref) => {
3068
3741
  checkScrollBar();
3069
3742
  }
3070
3743
  });
3071
- useSheetSelectionChange(isFocus && Boolean(isSelecting && docFocusing), isFocus, isSelectingRef, unitId, subUnitId, getRefSelections, isSupportAcrossSheet, Boolean(selectingMode), editor, handleSelectionChange);
3744
+ useSheetSelectionChange(isFocus && Boolean(isSelecting), isFocus, isSelectingRef, unitId, subUnitId, getRefSelections, isSupportAcrossSheet, Boolean(selectingMode), editor, handleSelectionChange);
3072
3745
  useSwitchSheet(isFocus && Boolean(isSelecting && docFocusing), unitId, isSupportAcrossSheet, setIsFocus, onBlur, () => {
3073
3746
  highlight(formulaTextRef.current, false, true);
3074
3747
  });
@@ -3091,7 +3764,13 @@ const FormulaEditor = (0, react.forwardRef)((props, ref) => {
3091
3764
  highlight(`=${res.text}`);
3092
3765
  }
3093
3766
  };
3094
- const handleMouseUp = () => {
3767
+ const handleMouseUp = (event) => {
3768
+ if (hasActiveFormulaEmbedInteraction(formulaEditorContainerRef.current)) return;
3769
+ if (!shouldRefocusFormulaEditorOnMouseUp({
3770
+ target: event.target,
3771
+ isFocusing,
3772
+ isPointerSelecting: docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isOnPointerEvent
3773
+ })) return;
3095
3774
  setIsFocus(true);
3096
3775
  onFocus();
3097
3776
  focus();
@@ -3108,6 +3787,7 @@ const FormulaEditor = (0, react.forwardRef)((props, ref) => {
3108
3787
  }),
3109
3788
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3110
3789
  ref: formulaEditorContainerRef,
3790
+ "data-u-comp": "formula-editor",
3111
3791
  className: "univer-relative univer-size-full",
3112
3792
  onMouseUp: handleMouseUp
3113
3793
  })
@@ -3629,7 +4309,7 @@ function RangeSelectorDialog(props) {
3629
4309
  mask: false,
3630
4310
  maskClosable: false,
3631
4311
  footer: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("footer", {
3632
- className: "univer-flex univer-gap-2",
4312
+ className: "univer-flex univer-gap-2 rtl:univer-flex-row-reverse",
3633
4313
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
3634
4314
  onClick: onClose,
3635
4315
  children: localeService.t("sheets-formula-ui.rangeSelector.cancel")
@@ -3652,7 +4332,7 @@ function RangeSelectorDialog(props) {
3652
4332
  ref: scrollbarRef,
3653
4333
  className: (0, _univerjs_design.clsx)("-univer-mx-6 univer-max-h-60 univer-overflow-y-auto univer-px-6", _univerjs_design.scrollbarClassName),
3654
4334
  children: [ranges.map((text, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3655
- className: "univer-mb-2 univer-flex univer-items-center univer-gap-4",
4335
+ className: "univer-mb-2 univer-flex univer-items-center univer-gap-4 rtl:univer-flex-row-reverse",
3656
4336
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
3657
4337
  className: (0, _univerjs_design.clsx)("univer-w-full", { "univer-border-primary-600": focusIndex === index }),
3658
4338
  placeholder: localeService.t("sheets-formula-ui.rangeSelector.placeHolder"),
@@ -4550,227 +5230,6 @@ ImageFormulaRenderController = __decorate([
4550
5230
  __decorateParam(2, _univerjs_core.IUniverInstanceService)
4551
5231
  ], ImageFormulaRenderController);
4552
5232
 
4553
- //#endregion
4554
- //#region src/menu/menu.ts
4555
- function InsertCommonFunctionMenuItemFactory(accessor) {
4556
- const commonFunctions = [
4557
- "SUMIF",
4558
- "SUM",
4559
- "AVERAGE",
4560
- "IF",
4561
- "COUNT",
4562
- "SIN",
4563
- "MAX"
4564
- ];
4565
- let selections = commonFunctions.map((name) => ({
4566
- label: {
4567
- name,
4568
- selectable: false
4569
- },
4570
- value: name
4571
- }));
4572
- try {
4573
- const descriptionService = accessor.get(_univerjs_sheets_formula.IDescriptionService);
4574
- const filtered = commonFunctions.filter((name) => Boolean(descriptionService.getFunctionInfo(name)));
4575
- if (filtered.length > 0) selections = filtered.map((name) => ({
4576
- label: {
4577
- name,
4578
- selectable: false
4579
- },
4580
- value: name
4581
- }));
4582
- } catch {}
4583
- return {
4584
- id: `${InsertFunctionOperation.id}.common`,
4585
- commandId: InsertFunctionOperation.id,
4586
- title: "sheets-formula-ui.insert.common",
4587
- tooltip: "sheets-formula-ui.insert.tooltip",
4588
- icon: "FunctionIcon",
4589
- type: _univerjs_ui.MenuItemType.SELECTOR,
4590
- selections,
4591
- hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET)
4592
- };
4593
- }
4594
- function createInsertFunctionCategoryMenuItemFactory(functionType, categoryKey, icon) {
4595
- return function insertFunctionCategoryMenuItemFactory(accessor) {
4596
- let selections = [];
4597
- try {
4598
- selections = accessor.get(_univerjs_sheets_formula.IDescriptionService).getSearchListByType(functionType).map(({ name }) => ({
4599
- label: {
4600
- name,
4601
- selectable: false
4602
- },
4603
- value: name
4604
- }));
4605
- } catch {
4606
- selections = [];
4607
- }
4608
- return {
4609
- id: `${InsertFunctionOperation.id}.${categoryKey}`,
4610
- commandId: InsertFunctionOperation.id,
4611
- title: `sheets-formula-ui.functionType.${categoryKey}`,
4612
- tooltip: "sheets-formula-ui.insert.tooltip",
4613
- icon,
4614
- type: _univerjs_ui.MenuItemType.SELECTOR,
4615
- selections,
4616
- hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET)
4617
- };
4618
- };
4619
- }
4620
- const InsertFinancialFunctionMenuItemFactory = createInsertFunctionCategoryMenuItemFactory(_univerjs_engine_formula.FunctionType.Financial, "financial");
4621
- const InsertLogicalFunctionMenuItemFactory = createInsertFunctionCategoryMenuItemFactory(_univerjs_engine_formula.FunctionType.Logical, "logical");
4622
- const InsertTextFunctionMenuItemFactory = createInsertFunctionCategoryMenuItemFactory(_univerjs_engine_formula.FunctionType.Text, "text");
4623
- const InsertDateFunctionMenuItemFactory = createInsertFunctionCategoryMenuItemFactory(_univerjs_engine_formula.FunctionType.Date, "date");
4624
- const InsertLookupFunctionMenuItemFactory = createInsertFunctionCategoryMenuItemFactory(_univerjs_engine_formula.FunctionType.Lookup, "lookup");
4625
- const InsertMathFunctionMenuItemFactory = createInsertFunctionCategoryMenuItemFactory(_univerjs_engine_formula.FunctionType.Math, "math");
4626
- const InsertStatisticalFunctionMenuItemFactory = createInsertFunctionCategoryMenuItemFactory(_univerjs_engine_formula.FunctionType.Statistical, "statistical");
4627
- const InsertEngineeringFunctionMenuItemFactory = createInsertFunctionCategoryMenuItemFactory(_univerjs_engine_formula.FunctionType.Engineering, "engineering");
4628
- const InsertInformationFunctionMenuItemFactory = createInsertFunctionCategoryMenuItemFactory(_univerjs_engine_formula.FunctionType.Information, "information");
4629
- const InsertDatabaseFunctionMenuItemFactory = createInsertFunctionCategoryMenuItemFactory(_univerjs_engine_formula.FunctionType.Database, "database");
4630
- function AllFunctionsMenuItemFactory(accessor) {
4631
- return {
4632
- id: MoreFunctionsOperation.id,
4633
- title: "sheets-formula-ui.moreFunctions.allFunctions",
4634
- tooltip: "sheets-formula-ui.insert.tooltip",
4635
- type: _univerjs_ui.MenuItemType.BUTTON,
4636
- hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET),
4637
- disabled$: (0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
4638
- workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
4639
- worksheetTypes: [_univerjs_sheets.WorksheetEditPermission, _univerjs_sheets.WorksheetSetCellValuePermission],
4640
- rangeTypes: [_univerjs_sheets.RangeProtectionPermissionEditPoint]
4641
- })
4642
- };
4643
- }
4644
- function CopyFormulaOnlyMenuItemFactory(accessor) {
4645
- return {
4646
- id: SheetCopyFormulaOnlyCommand.id,
4647
- type: _univerjs_ui.MenuItemType.BUTTON,
4648
- title: "sheets-formula-ui.operation.copyFormulaOnly",
4649
- disabled$: (0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
4650
- workbookTypes: [_univerjs_sheets.WorkbookCopyPermission],
4651
- worksheetTypes: [_univerjs_sheets.WorksheetCopyPermission],
4652
- rangeTypes: [_univerjs_sheets.RangeProtectionPermissionViewPoint]
4653
- }),
4654
- hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET)
4655
- };
4656
- }
4657
- function PasteFormulaMenuItemFactory(accessor) {
4658
- return {
4659
- id: SheetOnlyPasteFormulaCommand.id,
4660
- type: _univerjs_ui.MenuItemType.BUTTON,
4661
- title: "sheets-formula-ui.operation.pasteFormula",
4662
- disabled$: (0, _univerjs_sheets_ui.menuClipboardDisabledObservable)(accessor).pipe((0, rxjs.combineLatestWith)((0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
4663
- workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
4664
- rangeTypes: [_univerjs_sheets.RangeProtectionPermissionEditPoint],
4665
- worksheetTypes: [_univerjs_sheets.WorksheetSetCellValuePermission, _univerjs_sheets.WorksheetEditPermission]
4666
- })), (0, rxjs.map)(([d1, d2]) => d1 || d2)),
4667
- hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET)
4668
- };
4669
- }
4670
-
4671
- //#endregion
4672
- //#region src/menu/schema.ts
4673
- const menuSchema = {
4674
- [_univerjs_ui.RibbonFormulasGroup.BASIC]: {
4675
- [`${InsertFunctionOperation.id}.common`]: {
4676
- order: 0,
4677
- menuItemFactory: InsertCommonFunctionMenuItemFactory,
4678
- [MoreFunctionsOperation.id]: {
4679
- order: 0,
4680
- menuItemFactory: AllFunctionsMenuItemFactory
4681
- }
4682
- },
4683
- [`${InsertFunctionOperation.id}.financial`]: {
4684
- order: 1,
4685
- menuItemFactory: InsertFinancialFunctionMenuItemFactory,
4686
- [MoreFunctionsOperation.id]: {
4687
- order: 0,
4688
- menuItemFactory: AllFunctionsMenuItemFactory
4689
- }
4690
- },
4691
- [`${InsertFunctionOperation.id}.logical`]: {
4692
- order: 2,
4693
- menuItemFactory: InsertLogicalFunctionMenuItemFactory,
4694
- [MoreFunctionsOperation.id]: {
4695
- order: 0,
4696
- menuItemFactory: AllFunctionsMenuItemFactory
4697
- }
4698
- },
4699
- [`${InsertFunctionOperation.id}.text`]: {
4700
- order: 3,
4701
- menuItemFactory: InsertTextFunctionMenuItemFactory,
4702
- [MoreFunctionsOperation.id]: {
4703
- order: 0,
4704
- menuItemFactory: AllFunctionsMenuItemFactory
4705
- }
4706
- },
4707
- [`${InsertFunctionOperation.id}.date`]: {
4708
- order: 4,
4709
- menuItemFactory: InsertDateFunctionMenuItemFactory,
4710
- [MoreFunctionsOperation.id]: {
4711
- order: 0,
4712
- menuItemFactory: AllFunctionsMenuItemFactory
4713
- }
4714
- },
4715
- [`${InsertFunctionOperation.id}.lookup`]: {
4716
- order: 5,
4717
- menuItemFactory: InsertLookupFunctionMenuItemFactory,
4718
- [MoreFunctionsOperation.id]: {
4719
- order: 0,
4720
- menuItemFactory: AllFunctionsMenuItemFactory
4721
- }
4722
- },
4723
- [`${InsertFunctionOperation.id}.math`]: {
4724
- order: 6,
4725
- menuItemFactory: InsertMathFunctionMenuItemFactory,
4726
- [MoreFunctionsOperation.id]: {
4727
- order: 0,
4728
- menuItemFactory: AllFunctionsMenuItemFactory
4729
- }
4730
- },
4731
- [`${InsertFunctionOperation.id}.statistical`]: {
4732
- order: 7,
4733
- menuItemFactory: InsertStatisticalFunctionMenuItemFactory,
4734
- [MoreFunctionsOperation.id]: {
4735
- order: 0,
4736
- menuItemFactory: AllFunctionsMenuItemFactory
4737
- }
4738
- },
4739
- [`${InsertFunctionOperation.id}.engineering`]: {
4740
- order: 8,
4741
- menuItemFactory: InsertEngineeringFunctionMenuItemFactory,
4742
- [MoreFunctionsOperation.id]: {
4743
- order: 0,
4744
- menuItemFactory: AllFunctionsMenuItemFactory
4745
- }
4746
- },
4747
- [`${InsertFunctionOperation.id}.information`]: {
4748
- order: 9,
4749
- menuItemFactory: InsertInformationFunctionMenuItemFactory,
4750
- [MoreFunctionsOperation.id]: {
4751
- order: 0,
4752
- menuItemFactory: AllFunctionsMenuItemFactory
4753
- }
4754
- },
4755
- [`${InsertFunctionOperation.id}.database`]: {
4756
- order: 10,
4757
- menuItemFactory: InsertDatabaseFunctionMenuItemFactory,
4758
- [MoreFunctionsOperation.id]: {
4759
- order: 0,
4760
- menuItemFactory: AllFunctionsMenuItemFactory
4761
- }
4762
- }
4763
- },
4764
- [_univerjs_sheets_ui.COPY_SPECIAL_MENU_ID]: { [SheetCopyFormulaOnlyCommand.id]: {
4765
- order: 0,
4766
- menuItemFactory: CopyFormulaOnlyMenuItemFactory
4767
- } },
4768
- [_univerjs_sheets_ui.PASTE_SPECIAL_MENU_ID]: { [SheetOnlyPasteFormulaCommand.id]: {
4769
- order: 4,
4770
- menuItemFactory: PasteFormulaMenuItemFactory
4771
- } }
4772
- };
4773
-
4774
5233
  //#endregion
4775
5234
  //#region src/views/formula-progress/FormulaProgress.tsx
4776
5235
  /**
@@ -5013,6 +5472,7 @@ exports.ReferenceAbsoluteOperation = ReferenceAbsoluteOperation;
5013
5472
  exports.SearchFunctionOperation = SearchFunctionOperation;
5014
5473
  exports.SheetCopyFormulaOnlyCommand = SheetCopyFormulaOnlyCommand;
5015
5474
  exports.SheetOnlyPasteFormulaCommand = SheetOnlyPasteFormulaCommand;
5475
+ exports.SheetsFormulaUIMenuSchema = menuSchema;
5016
5476
  Object.defineProperty(exports, 'UniverSheetsFormulaUIPlugin', {
5017
5477
  enumerable: true,
5018
5478
  get: function () {