@fileverse-dev/fortune-react 1.3.10 → 1.3.11-input-ref-1

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.
Files changed (29) hide show
  1. package/es/components/ContextMenu/index.js +1 -1
  2. package/es/components/FxEditor/index.js +200 -52
  3. package/es/components/SheetOverlay/InputBox.js +318 -150
  4. package/es/components/SheetOverlay/drag_and_drop/column-helpers.js +25 -1
  5. package/es/components/SheetOverlay/drag_and_drop/row-helpers.js +26 -2
  6. package/es/components/SheetOverlay/helper.d.ts +7 -0
  7. package/es/components/SheetOverlay/helper.js +95 -0
  8. package/es/components/SheetOverlay/index.css +1 -1
  9. package/es/components/Workbook/index.js +141 -11
  10. package/es/hooks/useFormulaEditorHistory.d.ts +24 -0
  11. package/es/hooks/useFormulaEditorHistory.js +119 -0
  12. package/es/hooks/useRerenderOnFormulaCaret.d.ts +2 -0
  13. package/es/hooks/useRerenderOnFormulaCaret.js +26 -0
  14. package/es/utils/convertCellsToCrypto.js +17 -0
  15. package/lib/components/ContextMenu/index.js +1 -1
  16. package/lib/components/FxEditor/index.js +198 -50
  17. package/lib/components/SheetOverlay/InputBox.js +316 -148
  18. package/lib/components/SheetOverlay/drag_and_drop/column-helpers.js +25 -1
  19. package/lib/components/SheetOverlay/drag_and_drop/row-helpers.js +26 -2
  20. package/lib/components/SheetOverlay/helper.d.ts +7 -0
  21. package/lib/components/SheetOverlay/helper.js +99 -0
  22. package/lib/components/SheetOverlay/index.css +1 -1
  23. package/lib/components/Workbook/index.js +142 -12
  24. package/lib/hooks/useFormulaEditorHistory.d.ts +24 -0
  25. package/lib/hooks/useFormulaEditorHistory.js +126 -0
  26. package/lib/hooks/useRerenderOnFormulaCaret.d.ts +2 -0
  27. package/lib/hooks/useRerenderOnFormulaCaret.js +32 -0
  28. package/lib/utils/convertCellsToCrypto.js +17 -0
  29. package/package.json +2 -2
@@ -129,7 +129,7 @@ import "./index.css";
129
129
  import Menu from "./Menu";
130
130
  import "tippy.js/dist/tippy.css";
131
131
  import SVGIcon from "../SVGIcon";
132
- import { LucideIcon as LocalLucidIcon } from "../../components/SheetOverlay/LucideIcon";
132
+ import { LucideIcon as LocalLucidIcon } from "../SheetOverlay/LucideIcon";
133
133
  var ContextMenu = function ContextMenu() {
134
134
  var showDialog = useDialog().showDialog;
135
135
  var containerRef = useRef(null);
@@ -1,47 +1,73 @@
1
- import { getFlowdata, cancelNormalSelected, getCellValue, updateCell, getInlineStringNoStyle, isInlineStringCell, escapeScriptTag, moveHighlightCell, handleFormulaInput, rangeHightlightselected, valueShowEs, isShowHidenCR, escapeHTMLTag, isAllowEdit } from "@fileverse-dev/fortune-core";
2
- import React, { useContext, useState, useCallback, useEffect, useRef, useMemo } from "react";
1
+ import { getFlowdata, cancelNormalSelected, getCellValue, updateCell, getInlineStringNoStyle, isInlineStringCell, escapeScriptTag, moveHighlightCell, handleFormulaInput, getFormulaRangeIndexAtCaret, isCaretAtValidFormulaRangeInsertionPoint, markRangeSelectionDirty, rangeHightlightselected, getFormulaEditorOwner, setFormulaEditorOwner, valueShowEs, isShowHidenCR, escapeHTMLTag, functionHTMLGenerate, isAllowEdit } from "@fileverse-dev/fortune-core";
2
+ import React, { useContext, useState, useCallback, useEffect, useLayoutEffect, useRef, useMemo } from "react";
3
3
  import "./index.css";
4
4
  import _ from "lodash";
5
+ import { Tooltip } from "@fileverse/ui";
5
6
  import WorkbookContext from "../../context";
6
7
  import ContentEditable from "../SheetOverlay/ContentEditable";
7
8
  import NameBox from "./NameBox";
8
- import FormulaSearch from "../../components/SheetOverlay/FormulaSearch";
9
- import FormulaHint from "../../components/SheetOverlay/FormulaHint";
9
+ import FormulaSearch from "../SheetOverlay/FormulaSearch";
10
+ import FormulaHint from "../SheetOverlay/FormulaHint";
10
11
  import usePrevious from "../../hooks/usePrevious";
11
- import { LucideIcon } from "../../components/SheetOverlay/LucideIcon";
12
- import { countCommasBeforeCursor, isLetterNumberPattern, moveCursorToEnd } from "../../components/SheetOverlay/helper";
12
+ import { useFormulaEditorHistory } from "../../hooks/useFormulaEditorHistory";
13
+ import { useRerenderOnFormulaCaret } from "../../hooks/useRerenderOnFormulaCaret";
14
+ import { LucideIcon } from "../SheetOverlay/LucideIcon";
15
+ import { countCommasBeforeCursor, getCursorPosition, getFunctionNameFromFormulaCaretSpans, isLetterNumberPattern, setCursorPosition, buildFormulaSuggestionText, shouldShowFormulaFunctionList } from "../SheetOverlay/helper";
13
16
  var FxEditor = function FxEditor() {
14
- var _a;
17
+ var _a, _b, _c;
15
18
  var hideFormulaHintLocal = localStorage.getItem("formulaMore") === "true";
16
- var _b = useState(false),
17
- showSearchHint = _b[0],
18
- setShowSearchHint = _b[1];
19
- var _c = useState(!hideFormulaHintLocal),
20
- showFormulaHint = _c[0],
21
- setShowFormulaHint = _c[1];
22
- var _d = useState(0),
23
- commaCount = _d[0],
24
- setCommaCount = _d[1];
25
- var _e = useContext(WorkbookContext),
26
- context = _e.context,
27
- setContext = _e.setContext,
28
- refs = _e.refs;
19
+ var _d = useState(false),
20
+ showSearchHint = _d[0],
21
+ setShowSearchHint = _d[1];
22
+ var _e = useState(!hideFormulaHintLocal),
23
+ showFormulaHint = _e[0],
24
+ setShowFormulaHint = _e[1];
25
+ var _f = useState(0),
26
+ commaCount = _f[0],
27
+ setCommaCount = _f[1];
28
+ var _g = useContext(WorkbookContext),
29
+ context = _g.context,
30
+ setContext = _g.setContext,
31
+ refs = _g.refs;
29
32
  var lastKeyDownEventRef = useRef(null);
33
+ var _h = useFormulaEditorHistory(refs.fxInput, refs.cellInput, refs.fxInput, setContext, "fx"),
34
+ formulaHistoryRef = _h.formulaHistoryRef,
35
+ preTextRef = _h.preTextRef,
36
+ resetFormulaHistory = _h.resetFormulaHistory,
37
+ handleFormulaHistoryUndoRedo = _h.handleFormulaHistoryUndoRedo,
38
+ capturePreFormulaState = _h.capturePreFormulaState,
39
+ appendFormulaHistoryFromPrimaryEditor = _h.appendFormulaHistoryFromPrimaryEditor;
30
40
  var inputContainerRef = useRef(null);
31
- var _f = useState(false),
32
- isHidenRC = _f[0],
33
- setIsHidenRC = _f[1];
41
+ var _j = useState(false),
42
+ isHidenRC = _j[0],
43
+ setIsHidenRC = _j[1];
34
44
  var firstSelection = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0];
35
45
  var prevFirstSelection = usePrevious(firstSelection);
46
+ var prevCellUpdate = usePrevious(context.luckysheetCellUpdate);
36
47
  var prevSheetId = usePrevious(context.currentSheetId);
37
48
  var recentText = useRef("");
38
49
  var handleShowFormulaHint = function handleShowFormulaHint() {
39
50
  localStorage.setItem("formulaMore", String(showFormulaHint));
40
51
  setShowFormulaHint(!showFormulaHint);
41
52
  };
53
+ useEffect(function () {
54
+ var handleKeyDown = function handleKeyDown(event) {
55
+ if (event.key === "F10") {
56
+ event.preventDefault();
57
+ handleShowFormulaHint();
58
+ }
59
+ };
60
+ window.addEventListener("keydown", handleKeyDown);
61
+ return function () {
62
+ return window.removeEventListener("keydown", handleKeyDown);
63
+ };
64
+ }, [showFormulaHint]);
42
65
  useEffect(function () {
43
66
  var _a;
44
67
  setIsHidenRC(isShowHidenCR(context));
68
+ if (context.luckysheetCellUpdate.length > 0) {
69
+ return;
70
+ }
45
71
  if (_.isEqual(prevFirstSelection, firstSelection) && context.currentSheetId === prevSheetId) {
46
72
  return;
47
73
  }
@@ -65,7 +91,55 @@ var FxEditor = function FxEditor() {
65
91
  } else {
66
92
  refs.fxInput.current.innerHTML = "";
67
93
  }
68
- }, [context.luckysheetfile, context.currentSheetId, context.luckysheet_select_save]);
94
+ }, [context.luckysheetfile, context.currentSheetId, context.luckysheet_select_save, context.luckysheetCellUpdate.length]);
95
+ useLayoutEffect(function () {
96
+ var _a;
97
+ var fxInput = refs.fxInput.current;
98
+ if (context.luckysheetCellUpdate.length === 0 || !fxInput) {
99
+ return;
100
+ }
101
+ if (refs.globalCache.doNotUpdateCell) {
102
+ delete refs.globalCache.doNotUpdateCell;
103
+ return;
104
+ }
105
+ if (_.isEqual(prevCellUpdate, context.luckysheetCellUpdate) && prevSheetId === context.currentSheetId) {
106
+ return;
107
+ }
108
+ var _b = context.luckysheetCellUpdate,
109
+ rowIndex = _b[0],
110
+ colIndex = _b[1];
111
+ if (_.isNil(rowIndex) || _.isNil(colIndex)) {
112
+ return;
113
+ }
114
+ var flowdata = getFlowdata(context);
115
+ if (!flowdata) {
116
+ return;
117
+ }
118
+ var cell = (_a = flowdata === null || flowdata === void 0 ? void 0 : flowdata[rowIndex]) === null || _a === void 0 ? void 0 : _a[colIndex];
119
+ var value = "";
120
+ if (cell && !refs.globalCache.overwriteCell) {
121
+ if (isInlineStringCell(cell)) {
122
+ value = getInlineStringNoStyle(rowIndex, colIndex, flowdata);
123
+ } else if (cell.f) {
124
+ value = getCellValue(rowIndex, colIndex, flowdata, "f");
125
+ } else {
126
+ value = valueShowEs(rowIndex, colIndex, flowdata);
127
+ }
128
+ }
129
+ refs.globalCache.overwriteCell = false;
130
+ if (!refs.globalCache.ignoreWriteCell && value) {
131
+ fxInput.innerHTML = escapeHTMLTag(escapeScriptTag(value));
132
+ } else if (!refs.globalCache.ignoreWriteCell) {
133
+ var valueD = getCellValue(rowIndex, colIndex, flowdata, "f");
134
+ fxInput.innerText = valueD;
135
+ }
136
+ refs.globalCache.ignoreWriteCell = false;
137
+ }, [context.luckysheetCellUpdate, context.luckysheetfile, context.currentSheetId, prevCellUpdate, prevSheetId, refs.fxInput, refs.globalCache]);
138
+ useEffect(function () {
139
+ if (_.isEmpty(context.luckysheetCellUpdate)) {
140
+ resetFormulaHistory();
141
+ }
142
+ }, [context.luckysheetCellUpdate, resetFormulaHistory]);
69
143
  var onFocus = useCallback(function () {
70
144
  var _a, _b;
71
145
  if (context.allowEdit === false) {
@@ -73,6 +147,7 @@ var FxEditor = function FxEditor() {
73
147
  }
74
148
  if (((_b = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0 && !context.luckysheet_cell_selected_move && isAllowEdit(context, context.luckysheet_select_save)) {
75
149
  setContext(function (draftCtx) {
150
+ setFormulaEditorOwner(draftCtx, "fx");
76
151
  var last = draftCtx.luckysheet_select_save[draftCtx.luckysheet_select_save.length - 1];
77
152
  var row_index = last.row_focus;
78
153
  var col_index = last.column_focus;
@@ -80,24 +155,34 @@ var FxEditor = function FxEditor() {
80
155
  refs.globalCache.doNotFocus = true;
81
156
  });
82
157
  }
158
+ setContext(function (draftCtx) {
159
+ setFormulaEditorOwner(draftCtx, "fx");
160
+ });
83
161
  }, [context.config, context.luckysheet_select_save, context.luckysheetfile, context.currentSheetId, refs.globalCache, setContext]);
84
162
  var getActiveFormula = useCallback(function () {
85
163
  return document.querySelector(".luckysheet-formula-search-item-active");
86
164
  }, []);
87
165
  var insertSelectedFormula = useCallback(function (formulaName) {
88
- var ht = "<span dir=\"auto\" class=\"luckysheet-formula-text-color\">=</span><span dir=\"auto\" class=\"luckysheet-formula-text-func\">".concat(formulaName, "</span><span dir=\"auto\" class=\"luckysheet-formula-text-lpar\">(</span>");
89
- refs.fxInput.current.innerHTML = ht;
166
+ var fxEditor = refs.fxInput.current;
167
+ if (!fxEditor) return;
90
168
  var cellEditor = document.getElementById("luckysheet-rich-text-editor");
169
+ var _a = buildFormulaSuggestionText(fxEditor, formulaName),
170
+ text = _a.text,
171
+ caretOffset = _a.caretOffset;
172
+ var safeText = escapeScriptTag(text);
173
+ var html = safeText.startsWith("=") ? functionHTMLGenerate(safeText) : escapeHTMLTag(safeText);
174
+ fxEditor.innerHTML = html;
91
175
  if (cellEditor) {
92
- cellEditor.innerHTML = ht;
176
+ cellEditor.innerHTML = html;
93
177
  }
94
- moveCursorToEnd(refs.fxInput.current);
178
+ setCursorPosition(fxEditor, caretOffset);
179
+ setShowSearchHint(shouldShowFormulaFunctionList(fxEditor));
95
180
  setContext(function (draftCtx) {
96
181
  draftCtx.functionCandidates = [];
97
182
  draftCtx.defaultCandidates = [];
98
- draftCtx.functionHint = formulaName;
183
+ draftCtx.functionHint = (formulaName || "").toUpperCase();
99
184
  });
100
- }, [setContext]);
185
+ }, [refs.fxInput, setContext]);
101
186
  var clearSearchItemActiveClass = useCallback(function () {
102
187
  var activeFormula = getActiveFormula();
103
188
  if (activeFormula) {
@@ -113,10 +198,11 @@ var FxEditor = function FxEditor() {
113
198
  return lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText;
114
199
  };
115
200
  var selectActiveFormulaOnClick = useCallback(function (e) {
116
- var _a, _b, _c;
201
+ var _a, _b, _c, _d;
117
202
  if (e.target.className.includes("sign-fortune")) return;
118
- recentText.current = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current.innerText;
119
- var formulaName = (_c = (_b = getActiveFormula()) === null || _b === void 0 ? void 0 : _b.querySelector(".luckysheet-formula-search-func")) === null || _c === void 0 ? void 0 : _c.textContent;
203
+ preTextRef.current = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current.innerText;
204
+ recentText.current = (_b = refs.fxInput) === null || _b === void 0 ? void 0 : _b.current.innerText;
205
+ var formulaName = (_d = (_c = getActiveFormula()) === null || _c === void 0 ? void 0 : _c.querySelector(".luckysheet-formula-search-func")) === null || _d === void 0 ? void 0 : _d.textContent;
120
206
  var lastSpanText = getLastInputSpanText();
121
207
  if (formulaName && !isLetterNumberPattern(lastSpanText)) {
122
208
  insertSelectedFormula(formulaName);
@@ -125,18 +211,36 @@ var FxEditor = function FxEditor() {
125
211
  }
126
212
  }, [getActiveFormula, insertSelectedFormula]);
127
213
  var onKeyDown = useCallback(function (e) {
128
- var _a;
214
+ var _a, _b, _c;
129
215
  if (context.allowEdit === false) {
130
216
  return;
131
217
  }
218
+ setContext(function (draftCtx) {
219
+ setFormulaEditorOwner(draftCtx, "fx");
220
+ });
132
221
  var currentCommaCount = countCommasBeforeCursor((_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current);
133
222
  setCommaCount(currentCommaCount);
134
223
  lastKeyDownEventRef.current = new KeyboardEvent(e.type, e.nativeEvent);
135
- var key = e.key;
224
+ capturePreFormulaState();
136
225
  recentText.current = refs.fxInput.current.innerText;
226
+ var key = e.key;
227
+ var currentInputText = ((_c = (_b = refs.fxInput.current) === null || _b === void 0 ? void 0 : _b.innerText) === null || _c === void 0 ? void 0 : _c.trim()) || "";
137
228
  if (key === "ArrowLeft" || key === "ArrowRight") {
138
229
  e.stopPropagation();
139
230
  }
231
+ if ((e.metaKey || e.ctrlKey) && context.luckysheetCellUpdate.length > 0) {
232
+ if (e.code === "KeyZ" || e.code === "KeyY") {
233
+ var shouldUseFormulaHistory = currentInputText.startsWith("=") || formulaHistoryRef.current.active;
234
+ if (shouldUseFormulaHistory) {
235
+ var handledByFormulaHistory = handleFormulaHistoryUndoRedo(e.code === "KeyY" || e.code === "KeyZ" && e.shiftKey);
236
+ if (handledByFormulaHistory) {
237
+ e.preventDefault();
238
+ }
239
+ }
240
+ e.stopPropagation();
241
+ return;
242
+ }
243
+ }
140
244
  if ((e.key === "Enter" || e.key === "Tab") && context.luckysheetCellUpdate.length > 0) {
141
245
  if (e.altKey || e.metaKey) {
142
246
  document.execCommand("insertHTML", false, "\n ");
@@ -226,7 +330,7 @@ var FxEditor = function FxEditor() {
226
330
  }
227
331
  }
228
332
  });
229
- }, [context.allowEdit, context.luckysheetCellUpdate.length, refs.fxInput, setContext]);
333
+ }, [capturePreFormulaState, context.allowEdit, context.luckysheetCellUpdate.length, handleFormulaHistoryUndoRedo, refs.fxInput, setContext]);
230
334
  var handleHideShowHint = function handleHideShowHint() {
231
335
  var _a, _b, _c, _d;
232
336
  var el = (_a = document.getElementsByClassName("cell-hint")) === null || _a === void 0 ? void 0 : _a[0];
@@ -250,23 +354,44 @@ var FxEditor = function FxEditor() {
250
354
  var _a, _b, _c;
251
355
  if (context.isFlvReadOnly) return;
252
356
  handleHideShowHint();
253
- if (((_b = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.innerText.includes("=")) && /^=?[A-Za-z]*$/.test(getLastInputSpanText())) {
254
- setShowSearchHint(true);
255
- } else {
256
- setShowSearchHint(false);
257
- }
357
+ setShowSearchHint(shouldShowFormulaFunctionList((_b = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current) !== null && _b !== void 0 ? _b : null));
258
358
  var currentCommaCount = countCommasBeforeCursor((_c = refs.fxInput) === null || _c === void 0 ? void 0 : _c.current);
259
359
  setCommaCount(currentCommaCount);
260
360
  var e = lastKeyDownEventRef.current;
261
- if (!e) return;
361
+ if (!e) {
362
+ var fx = refs.fxInput.current;
363
+ var cell = refs.cellInput.current;
364
+ var isFormula = function isFormula(el) {
365
+ var _a, _b;
366
+ return !!(((_a = el === null || el === void 0 ? void 0 : el.innerText) === null || _a === void 0 ? void 0 : _a.trim().startsWith("=")) || ((_b = el === null || el === void 0 ? void 0 : el.textContent) === null || _b === void 0 ? void 0 : _b.trim().startsWith("=")));
367
+ };
368
+ var sel = window.getSelection();
369
+ var editor_1 = null;
370
+ if (sel === null || sel === void 0 ? void 0 : sel.rangeCount) {
371
+ var node = sel.getRangeAt(0).startContainer;
372
+ if ((fx === null || fx === void 0 ? void 0 : fx.contains(node)) && isFormula(fx)) editor_1 = fx;else if ((cell === null || cell === void 0 ? void 0 : cell.contains(node)) && isFormula(cell)) editor_1 = cell;
373
+ }
374
+ if (!editor_1 && isFormula(fx)) editor_1 = fx;else if (!editor_1 && isFormula(cell)) editor_1 = cell;
375
+ if (editor_1) {
376
+ setContext(function (draftCtx) {
377
+ if (!isAllowEdit(draftCtx, draftCtx.luckysheet_select_save)) return;
378
+ rangeHightlightselected(draftCtx, editor_1);
379
+ });
380
+ }
381
+ return;
382
+ }
262
383
  var kcode = e.keyCode;
263
384
  if (!kcode) return;
385
+ appendFormulaHistoryFromPrimaryEditor(function () {
386
+ return getCursorPosition(refs.fxInput.current);
387
+ });
264
388
  if (!(kcode >= 112 && kcode <= 123 || kcode <= 46 || kcode === 144 || kcode === 108 || e.ctrlKey || e.altKey || e.shiftKey && (kcode === 37 || kcode === 38 || kcode === 39 || kcode === 40)) || kcode === 8 || kcode === 32 || kcode === 46 || e.ctrlKey && kcode === 86) {
265
389
  setContext(function (draftCtx) {
266
390
  handleFormulaInput(draftCtx, refs.cellInput.current, refs.fxInput.current, kcode, recentText.current);
267
391
  });
268
392
  }
269
- }, [refs.cellInput, refs.fxInput, setContext]);
393
+ }, [appendFormulaHistoryFromPrimaryEditor, context.isFlvReadOnly, refs.cellInput, refs.fxInput, setContext]);
394
+ useRerenderOnFormulaCaret(refs.fxInput, context.luckysheetCellUpdate.length > 0);
270
395
  var getFunctionNameFromInput = useCallback(function () {
271
396
  var _a, _b, _c, _d;
272
397
  var inputText = ((_b = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.innerText) || "";
@@ -283,8 +408,9 @@ var FxEditor = function FxEditor() {
283
408
  }
284
409
  return null;
285
410
  }, []);
286
- var functionName = context.functionHint || getFunctionNameFromInput();
411
+ var functionName = (_c = (_b = getFunctionNameFromFormulaCaretSpans(refs.fxInput.current)) !== null && _b !== void 0 ? _b : context.functionHint) !== null && _c !== void 0 ? _c : getFunctionNameFromInput();
287
412
  var fn = functionName ? context.formulaCache.functionlistMap[functionName] : null;
413
+ var showFxFormulaChrome = context.luckysheetCellUpdate.length > 0 && getFormulaEditorOwner(context) === "fx";
288
414
  var allowEdit = useMemo(function () {
289
415
  if (context.allowEdit === false) {
290
416
  return false;
@@ -298,9 +424,9 @@ var FxEditor = function FxEditor() {
298
424
  return true;
299
425
  }, [context.config, context.luckysheet_select_save, context.luckysheetfile, context.currentSheetId, isHidenRC]);
300
426
  var divRef = useRef(null);
301
- var _g = useState(false),
302
- isResizing = _g[0],
303
- setIsResizing = _g[1];
427
+ var _k = useState(false),
428
+ isResizing = _k[0],
429
+ setIsResizing = _k[1];
304
430
  var startResize = function startResize(e) {
305
431
  e.preventDefault();
306
432
  setIsResizing(true);
@@ -346,8 +472,20 @@ var FxEditor = function FxEditor() {
346
472
  onMouseUp: function onMouseUp() {
347
473
  var _a;
348
474
  handleHideShowHint();
349
- var currentCommaCount = countCommasBeforeCursor((_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current);
475
+ setContext(function (draftCtx) {
476
+ setFormulaEditorOwner(draftCtx, "fx");
477
+ });
478
+ var editor = (_a = refs.fxInput) === null || _a === void 0 ? void 0 : _a.current;
479
+ var currentCommaCount = countCommasBeforeCursor(editor);
350
480
  setCommaCount(currentCommaCount);
481
+ setContext(function (draftCtx) {
482
+ if (draftCtx.formulaCache.rangeSelectionActive !== true) return;
483
+ var clickedInsideManagedRange = getFormulaRangeIndexAtCaret(editor) !== null;
484
+ var atValidInsertionPoint = isCaretAtValidFormulaRangeInsertionPoint(editor);
485
+ if (clickedInsideManagedRange || !atValidInsertionPoint) {
486
+ markRangeSelectionDirty(draftCtx);
487
+ }
488
+ });
351
489
  },
352
490
  innerRef: function innerRef(e) {
353
491
  refs.fxInput.current = e;
@@ -360,7 +498,7 @@ var FxEditor = function FxEditor() {
360
498
  onChange: onChange,
361
499
  tabIndex: 0,
362
500
  allowEdit: allowEdit && !context.isFlvReadOnly
363
- }), showSearchHint && (/*#__PURE__*/React.createElement(FormulaSearch, {
501
+ }), (context.functionCandidates.length > 0 || context.functionHint || context.defaultCandidates.length > 0 || fn) && showFxFormulaChrome && (/*#__PURE__*/React.createElement(React.Fragment, null, showSearchHint && (/*#__PURE__*/React.createElement(FormulaSearch, {
364
502
  from: "fx",
365
503
  onMouseMove: function onMouseMove(e) {
366
504
  if (document.getElementById("luckysheet-formula-search-c")) {
@@ -376,12 +514,22 @@ var FxEditor = function FxEditor() {
376
514
  }
377
515
  })), /*#__PURE__*/React.createElement("div", {
378
516
  className: "fx-hint"
379
- }, showFormulaHint && fn && (/*#__PURE__*/React.createElement(FormulaHint, {
517
+ }, showFormulaHint && fn && !showSearchHint && (/*#__PURE__*/React.createElement(FormulaHint, {
380
518
  handleShowFormulaHint: handleShowFormulaHint,
381
519
  showFormulaHint: showFormulaHint,
382
520
  commaCount: commaCount,
383
521
  functionName: functionName
384
- })), !showFormulaHint && fn && (/*#__PURE__*/React.createElement("div", {
522
+ })), !showFormulaHint && fn && !showSearchHint && (/*#__PURE__*/React.createElement(Tooltip, {
523
+ text: "Turn on formula suggestions (F10)",
524
+ placement: "top",
525
+ defaultOpen: true,
526
+ style: {
527
+ position: "absolute",
528
+ top: "-50px",
529
+ left: "-130px",
530
+ width: "210px"
531
+ }
532
+ }, /*#__PURE__*/React.createElement("div", {
385
533
  className: "luckysheet-hin absolute show-more-btn",
386
534
  onClick: function onClick() {
387
535
  handleShowFormulaHint();
@@ -395,7 +543,7 @@ var FxEditor = function FxEditor() {
395
543
  margin: "auto",
396
544
  marginTop: "1px"
397
545
  }
398
- })))))), /*#__PURE__*/React.createElement("div", {
546
+ }))))))))), /*#__PURE__*/React.createElement("div", {
399
547
  className: "resize-handle",
400
548
  onMouseDown: startResize,
401
549
  style: {