@fileverse-dev/fortune-core 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 (43) hide show
  1. package/es/api/range.js +20 -0
  2. package/es/api/sheet.js +30 -2
  3. package/es/events/keyboard.js +50 -15
  4. package/es/events/mouse.js +62 -40
  5. package/es/events/paste.js +77 -28
  6. package/es/modules/cell.js +60 -2
  7. package/es/modules/comment.js +129 -24
  8. package/es/modules/dataVerification.js +34 -1
  9. package/es/modules/dropCell.js +65 -1
  10. package/es/modules/formula.d.ts +11 -0
  11. package/es/modules/formula.js +390 -47
  12. package/es/modules/hyperlink.js +52 -5
  13. package/es/modules/merge.js +93 -1
  14. package/es/modules/moveCells.js +35 -9
  15. package/es/modules/rowcol.js +75 -2
  16. package/es/modules/searchReplace.js +58 -2
  17. package/es/modules/selection.js +152 -42
  18. package/es/modules/sort.js +74 -9
  19. package/es/modules/splitColumn.js +21 -0
  20. package/es/modules/toolbar.js +46 -3
  21. package/es/settings.d.ts +5 -0
  22. package/lib/api/range.js +20 -0
  23. package/lib/api/sheet.js +29 -1
  24. package/lib/events/keyboard.js +49 -14
  25. package/lib/events/mouse.js +61 -39
  26. package/lib/events/paste.js +77 -28
  27. package/lib/modules/cell.js +60 -2
  28. package/lib/modules/comment.js +129 -24
  29. package/lib/modules/dataVerification.js +34 -1
  30. package/lib/modules/dropCell.js +65 -1
  31. package/lib/modules/formula.d.ts +11 -0
  32. package/lib/modules/formula.js +399 -47
  33. package/lib/modules/hyperlink.js +52 -5
  34. package/lib/modules/merge.js +93 -1
  35. package/lib/modules/moveCells.js +35 -9
  36. package/lib/modules/rowcol.js +75 -2
  37. package/lib/modules/searchReplace.js +58 -2
  38. package/lib/modules/selection.js +152 -42
  39. package/lib/modules/sort.js +74 -9
  40. package/lib/modules/splitColumn.js +21 -0
  41. package/lib/modules/toolbar.js +46 -3
  42. package/lib/settings.d.ts +5 -0
  43. package/package.json +1 -1
package/es/api/range.js CHANGED
@@ -78,6 +78,7 @@ export function setSelection(ctx, range, options) {
78
78
  }
79
79
  }
80
80
  export function setCellValuesByRange(ctx, data, range, cellInput, options, callAfterUpdate) {
81
+ var _a, _b, _c, _d, _e;
81
82
  if (options === void 0) {
82
83
  options = {};
83
84
  }
@@ -95,13 +96,32 @@ export function setCellValuesByRange(ctx, data, range, cellInput, options, callA
95
96
  if (data.length !== rowCount || data[0].length !== columnCount) {
96
97
  throw new Error("data size does not match range");
97
98
  }
99
+ var sheet = getSheet(ctx, options);
100
+ var sheetId = sheet.id || ctx.currentSheetId;
101
+ var cellChanges = [];
98
102
  for (var i = 0; i < rowCount; i += 1) {
99
103
  for (var j = 0; j < columnCount; j += 1) {
100
104
  var row = range.row[0] + i;
101
105
  var column = range.column[0] + j;
102
106
  setCellValue(ctx, row, column, data[i][j], cellInput, options, callAfterUpdate);
107
+ if (((_a = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _a === void 0 ? void 0 : _a.updateCellYdoc) && sheet.data) {
108
+ cellChanges.push({
109
+ sheetId: sheetId,
110
+ path: ["celldata"],
111
+ value: {
112
+ r: row,
113
+ c: column,
114
+ v: (_d = (_c = (_b = sheet.data) === null || _b === void 0 ? void 0 : _b[row]) === null || _c === void 0 ? void 0 : _c[column]) !== null && _d !== void 0 ? _d : null
115
+ },
116
+ key: "".concat(row, "_").concat(column),
117
+ type: "update"
118
+ });
119
+ }
103
120
  }
104
121
  }
122
+ if (cellChanges.length > 0 && ((_e = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _e === void 0 ? void 0 : _e.updateCellYdoc)) {
123
+ ctx.hooks.updateCellYdoc(cellChanges);
124
+ }
105
125
  }
106
126
  export function setCellFormatByRange(ctx, attr, value, range, options) {
107
127
  if (options === void 0) {
package/es/api/sheet.js CHANGED
@@ -13,7 +13,7 @@ import _ from "lodash";
13
13
  import { v4 as uuidv4 } from "uuid";
14
14
  import { dataToCelldata, getSheet } from "./common";
15
15
  import { getSheetIndex } from "../utils";
16
- import { api, execfunction, getFlowdata, insertUpdateFunctionGroup, locale, spillSortResult } from "..";
16
+ import { api, changeSheet, execfunction, getFlowdata, insertUpdateFunctionGroup, locale, spillSortResult } from "..";
17
17
  function isCellReferenced(formulaString, cell) {
18
18
  function colToNumber(col) {
19
19
  var num = 0;
@@ -146,7 +146,7 @@ function generateCopySheetName(ctx, sheetId) {
146
146
  return sheetCopyName;
147
147
  }
148
148
  export function copySheet(ctx, sheetId) {
149
- var _a, _b, _c;
149
+ var _a, _b, _c, _d, _e;
150
150
  var index = getSheetIndex(ctx, sheetId);
151
151
  var order = ctx.luckysheetfile[index].order + 1;
152
152
  var sheetName = generateCopySheetName(ctx, sheetId);
@@ -183,6 +183,34 @@ export function copySheet(ctx, sheetId) {
183
183
  var sheetOrderList = {};
184
184
  sheetOrderList[newSheetId] = order;
185
185
  api.setSheetOrder(ctx, sheetOrderList);
186
+ changeSheet(ctx, newSheetId, undefined, true, true);
187
+ if ((_d = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _d === void 0 ? void 0 : _d.updateAllCell) {
188
+ ctx.hooks.updateAllCell(newSheetId);
189
+ } else if ((_e = ctx === null || ctx === void 0 ? void 0 : ctx.hooks) === null || _e === void 0 ? void 0 : _e.updateCellYdoc) {
190
+ var changes_1 = [];
191
+ var celldata = newSheet.celldata || dataToCelldata(newSheet.data);
192
+ if (Array.isArray(celldata)) {
193
+ celldata.forEach(function (d) {
194
+ var _a;
195
+ if (d == null) return;
196
+ var r = d.r;
197
+ var c = d.c;
198
+ if (!_.isNumber(r) || !_.isNumber(c)) return;
199
+ changes_1.push({
200
+ sheetId: newSheetId,
201
+ path: ["celldata"],
202
+ key: "".concat(r, "_").concat(c),
203
+ value: {
204
+ r: r,
205
+ c: c,
206
+ v: (_a = d.v) !== null && _a !== void 0 ? _a : null
207
+ },
208
+ type: d.v == null ? "delete" : "update"
209
+ });
210
+ });
211
+ }
212
+ if (changes_1.length > 0) ctx.hooks.updateCellYdoc(changes_1);
213
+ }
186
214
  }
187
215
  export function calculateSheetFromula(ctx, id) {
188
216
  var _a, _b, _c;
@@ -117,13 +117,16 @@ import _ from "lodash";
117
117
  import { hideCRCount, removeActiveImage } from "..";
118
118
  import { getFlowdata } from "../context";
119
119
  import { updateCell, cancelNormalSelected } from "../modules/cell";
120
- import { handleFormulaInput } from "../modules/formula";
120
+ import { handleFormulaInput, israngeseleciton, maybeRecoverDirtyRangeSelection, markRangeSelectionDirty } from "../modules/formula";
121
121
  import { copy, deleteSelectedCellText, deleteSelectedCellFormat, textFormat, fillDate, fillTime, fillRightData, fillDownData, moveHighlightCell, moveHighlightRange, selectAll, selectionCache } from "../modules/selection";
122
122
  import { cancelPaintModel, handleBold, handleItalic, handleUnderline, handleLink } from "../modules/toolbar";
123
123
  import { hasPartMC } from "../modules/validation";
124
124
  import { getNowDateTime, getSheetIndex, isAllowEdit } from "../utils";
125
125
  import { handleCopy } from "./copy";
126
126
  import { jfrefreshgrid } from "../modules/refresh";
127
+ function isLegacyFormulaRangeMode(ctx) {
128
+ return !!ctx.formulaCache.rangestart || !!ctx.formulaCache.rangedrag_column_start || !!ctx.formulaCache.rangedrag_row_start || ctx.formulaCache.rangeSelectionActive === true || israngeseleciton(ctx);
129
+ }
127
130
  export function handleGlobalEnter(ctx, cellInput, e, canvas) {
128
131
  var _a, _b, _c;
129
132
  if ((e.altKey || e.metaKey) && ctx.luckysheetCellUpdate.length > 0) {
@@ -169,11 +172,20 @@ function moveToEdge(sheetData, key, curr, rowDelta, colDelta, startR, endR, star
169
172
  return colDelta === 0 ? r : c;
170
173
  }
171
174
  function handleControlPlusArrowKey(ctx, e, shiftPressed) {
172
- if (ctx.luckysheetCellUpdate.length > 0) return;
175
+ if (ctx.formulaCache.rangeSelectionActive === false && !maybeRecoverDirtyRangeSelection(ctx)) {
176
+ return;
177
+ }
178
+ var isFormulaRefMode = isLegacyFormulaRangeMode(ctx);
179
+ if (isFormulaRefMode) {
180
+ ctx.formulaCache.rangeSelectionActive = true;
181
+ }
182
+ if (ctx.luckysheetCellUpdate.length > 0 && !isFormulaRefMode) {
183
+ return;
184
+ }
173
185
  var idx = getSheetIndex(ctx, ctx.currentSheetId);
174
186
  if (_.isNil(idx)) return;
175
187
  var file = ctx.luckysheetfile[idx];
176
- if (!file || !file.row || !file.column) return;
188
+ if (!file || _.isNil(file.row) || _.isNil(file.column)) return;
177
189
  var maxRow = file.row;
178
190
  var maxCol = file.column;
179
191
  var last;
@@ -324,7 +336,14 @@ export function handleWithCtrlOrMetaKey(ctx, cache, e, cellInput, fxInput, handl
324
336
  }
325
337
  function handleShiftWithArrowKey(ctx, e) {
326
338
  var _a;
327
- if (ctx.luckysheetCellUpdate.length > 0) {
339
+ if (ctx.formulaCache.rangeSelectionActive === false && !maybeRecoverDirtyRangeSelection(ctx)) {
340
+ return;
341
+ }
342
+ var isFormulaMode = isLegacyFormulaRangeMode(ctx);
343
+ if (isFormulaMode) {
344
+ ctx.formulaCache.rangeSelectionActive = true;
345
+ }
346
+ if (ctx.luckysheetCellUpdate.length > 0 && !isFormulaMode) {
328
347
  return;
329
348
  }
330
349
  ctx.luckysheet_shiftpositon = _.cloneDeep((_a = ctx.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[ctx.luckysheet_select_save.length - 1]);
@@ -348,17 +367,15 @@ function handleShiftWithArrowKey(ctx, e) {
348
367
  e.preventDefault();
349
368
  }
350
369
  export function handleArrowKey(ctx, e) {
351
- var _a, _b;
352
- if (ctx.luckysheetCellUpdate.length > 0 || ctx.luckysheet_cell_selected_move || ctx.luckysheet_cell_selected_extend) {
353
- var parser = new DOMParser();
354
- var doc = parser.parseFromString("<div>".concat((_a = document.getElementById("luckysheet-rich-text-editor")) === null || _a === void 0 ? void 0 : _a.innerHTML, "</div>"), "text/html");
355
- var spans = doc.querySelectorAll("span");
356
- var lastSpan = spans[spans.length - 1];
357
- var notFunctionInit = !((_b = document.getElementById("luckysheet-rich-text-editor")) === null || _b === void 0 ? void 0 : _b.innerText.includes("("));
358
- if ((lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText.includes(")")) || (lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText.includes('"')) || notFunctionInit && /^[a-zA-Z]+$/.test(lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText) && !_.includes(["="], lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText) || /^[a-zA-Z]+$/.test(lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText)) {
359
- return;
360
- }
370
+ if (ctx.formulaCache.rangeSelectionActive === false && !maybeRecoverDirtyRangeSelection(ctx)) {
371
+ return;
361
372
  }
373
+ var isFormulaRefMode = isLegacyFormulaRangeMode(ctx);
374
+ if (isFormulaRefMode) ctx.formulaCache.rangeSelectionActive = true;
375
+ if (ctx.luckysheetCellUpdate.length > 0 && !isFormulaRefMode) {
376
+ return;
377
+ }
378
+ if (ctx.luckysheetCellUpdate.length > 0 || ctx.luckysheet_cell_selected_move || ctx.luckysheet_cell_selected_extend) {}
362
379
  var moveCount = hideCRCount(ctx, e.key);
363
380
  switch (e.key) {
364
381
  case "ArrowUp":
@@ -376,11 +393,12 @@ export function handleArrowKey(ctx, e) {
376
393
  default:
377
394
  break;
378
395
  }
396
+ e.preventDefault();
379
397
  }
380
398
  export function handleGlobalKeyDown(ctx, cellInput, fxInput, e, cache, handleUndo, handleRedo, canvas) {
381
399
  var _a, _b, _c;
382
400
  return __awaiter(this, void 0, void 0, function () {
383
- var kcode, kstr, allowEdit, isFxInput, ignoredKeys, restCod, last, row_index, col_index, last, row_index, col_index;
401
+ var handledFlvShortcut, kcode, kstr, allowEdit, isFxInput, ignoredKeys, restCod, last, row_index, col_index, last, row_index, col_index;
384
402
  return __generator(this, function (_d) {
385
403
  if (e.shiftKey && e.code === "Space") {
386
404
  e.stopImmediatePropagation();
@@ -388,27 +406,41 @@ export function handleGlobalKeyDown(ctx, cellInput, fxInput, e, cache, handleUnd
388
406
  e.preventDefault();
389
407
  return [2];
390
408
  }
409
+ handledFlvShortcut = false;
391
410
  if ((e.ctrlKey || e.metaKey && e.shiftKey) && e.code === "KeyE") {
392
411
  textFormat(ctx, "center");
412
+ handledFlvShortcut = true;
393
413
  } else if ((e.ctrlKey || e.metaKey && e.shiftKey) && e.code === "KeyL") {
394
414
  textFormat(ctx, "left");
415
+ handledFlvShortcut = true;
395
416
  } else if ((e.ctrlKey || e.metaKey && e.shiftKey) && e.code === "KeyR") {
396
417
  textFormat(ctx, "right");
418
+ handledFlvShortcut = true;
397
419
  }
398
420
  if ((e.metaKey || e.ctrlKey) && e.code === "KeyK") {
399
421
  handleLink(ctx, cellInput);
400
422
  }
401
423
  if ((e.metaKey || e.ctrlKey) && !e.shiftKey && e.code === "Semicolon") {
402
424
  fillDate(ctx);
425
+ handledFlvShortcut = true;
403
426
  }
404
427
  if ((e.metaKey || e.ctrlKey) && e.shiftKey && e.code === "Semicolon") {
405
428
  fillTime(ctx);
429
+ handledFlvShortcut = true;
406
430
  }
407
431
  if ((e.metaKey || e.ctrlKey) && !e.shiftKey && e.code === "KeyR") {
408
432
  fillRightData(ctx);
433
+ handledFlvShortcut = true;
409
434
  }
410
435
  if ((e.metaKey || e.ctrlKey) && e.code === "KeyD") {
411
436
  fillDownData(ctx);
437
+ handledFlvShortcut = true;
438
+ }
439
+ if (handledFlvShortcut) {
440
+ jfrefreshgrid(ctx, null, undefined);
441
+ e.stopPropagation();
442
+ e.preventDefault();
443
+ return [2];
412
444
  }
413
445
  ctx.luckysheet_select_status = false;
414
446
  kcode = e.keyCode;
@@ -470,6 +502,9 @@ export function handleGlobalKeyDown(ctx, cellInput, fxInput, e, cache, handleUnd
470
502
  if (ctx.activeImg != null) {
471
503
  removeActiveImage(ctx);
472
504
  } else {
505
+ if (ctx.formulaCache.rangeSelectionActive === true) {
506
+ markRangeSelectionDirty(ctx);
507
+ }
473
508
  deleteSelectedCellText(ctx);
474
509
  }
475
510
  jfrefreshgrid(ctx, null, undefined);
@@ -1,6 +1,6 @@
1
1
  import _ from "lodash";
2
2
  import { getFlowdata } from "../context";
3
- import { cancelActiveImgItem, cancelPaintModel, functionHTMLGenerate, israngeseleciton, rangeHightlightselected, rangeSetValue, onCommentBoxMove, onCommentBoxMoveEnd, onCommentBoxResize, onCommentBoxResizeEnd, onImageMove, onImageMoveEnd, onImageResize, onImageResizeEnd, removeEditingComment, removeOverShowComment, rangeDrag, onFormulaRangeDragEnd, createFormulaRangeSelect, createRangeHightlight, onCellsMoveEnd, onCellsMove, cellFocus, editComment, onIframeMoveEnd, onIframeResizeEnd, overShowError } from "../modules";
3
+ import { cancelActiveImgItem, cancelPaintModel, functionHTMLGenerate, israngeseleciton, maybeRecoverDirtyRangeSelection, rangeHightlightselected, rangeSetValue, getFormulaEditorOwner, onCommentBoxMove, onCommentBoxMoveEnd, onCommentBoxResize, onCommentBoxResizeEnd, onImageMove, onImageMoveEnd, onImageResize, onImageResizeEnd, removeEditingComment, removeOverShowComment, rangeDrag, onFormulaRangeDragEnd, createFormulaRangeSelect, createRangeHightlight, onCellsMoveEnd, onCellsMove, cellFocus, editComment, onIframeMoveEnd, onIframeResizeEnd, overShowError } from "../modules";
4
4
  import { getFrozenHandleLeft, getFrozenHandleTop, scrollToFrozenRowCol } from "../modules/freeze";
5
5
  import { cancelFunctionrangeSelected, mergeBorder, mergeMoveMain, updateCell, luckysheetUpdateCell } from "../modules/cell";
6
6
  import { colLocation, colLocationByIndex, rowLocation, rowLocationByIndex } from "../modules/location";
@@ -106,7 +106,7 @@ export function fixPositionOnFrozenCells(freeze, x, y, mouseX, mouseY) {
106
106
  }
107
107
  export function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, container, fxInput, canvas) {
108
108
  var _a, _b;
109
- var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
109
+ var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
110
110
  if (!(fxInput === null || fxInput === void 0 ? void 0 : fxInput.innerHTML) && ctx) {
111
111
  ctx.defaultCandidates = [];
112
112
  }
@@ -125,11 +125,11 @@ export function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, containe
125
125
  return;
126
126
  }
127
127
  var freeze = (_c = globalCache.freezen) === null || _c === void 0 ? void 0 : _c[ctx.currentSheetId];
128
- var _q = fixPositionOnFrozenCells(freeze, _x, _y, mouseX, mouseY),
129
- x = _q.x,
130
- y = _q.y,
131
- inHorizontalFreeze = _q.inHorizontalFreeze,
132
- inVerticalFreeze = _q.inVerticalFreeze;
128
+ var _p = fixPositionOnFrozenCells(freeze, _x, _y, mouseX, mouseY),
129
+ x = _p.x,
130
+ y = _p.y,
131
+ inHorizontalFreeze = _p.inHorizontalFreeze,
132
+ inVerticalFreeze = _p.inVerticalFreeze;
133
133
  var row_location = rowLocation(y, ctx.visibledatarow);
134
134
  var row = row_location[1];
135
135
  var row_pre = row_location[0];
@@ -174,12 +174,7 @@ export function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, containe
174
174
  }
175
175
  ctx.luckysheet_scroll_status = true;
176
176
  if (ctx.luckysheetCellUpdate.length > 0) {
177
- var parser = new DOMParser();
178
- var doc = parser.parseFromString("<div>".concat((_g = document.getElementById("luckysheet-rich-text-editor")) === null || _g === void 0 ? void 0 : _g.innerHTML, "</div>"), "text/html");
179
- var spans = doc.querySelectorAll("span");
180
- var firstSpan = spans[0];
181
- var lastSpan = spans[spans.length - 1];
182
- if ((ctx.formulaCache.rangestart || ctx.formulaCache.rangedrag_column_start || ctx.formulaCache.rangedrag_row_start || israngeseleciton(ctx) || (firstSpan === null || firstSpan === void 0 ? void 0 : firstSpan.innerText.includes("=")) && !(lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText.includes(")"))) && lastSpan && ctx.luckysheetCellUpdate.length === 2) {
177
+ if (ctx.formulaCache.rangestart || ctx.formulaCache.rangedrag_column_start || ctx.formulaCache.rangedrag_row_start || israngeseleciton(ctx)) {
183
178
  var rowseleted = [row_index, row_index_ed];
184
179
  var columnseleted = [col_index, col_index_ed];
185
180
  var left = col_pre;
@@ -246,7 +241,7 @@ export function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, containe
246
241
  last.top_move = top_1;
247
242
  last.height_move = height;
248
243
  ctx.formulaCache.func_selectedrange = last;
249
- } else if (e.ctrlKey && ((_h = _.last(cellInput.querySelectorAll("span"))) === null || _h === void 0 ? void 0 : _h.innerText) !== ",") {
244
+ } else if (e.ctrlKey && ((_g = _.last(cellInput.querySelectorAll("span"))) === null || _g === void 0 ? void 0 : _g.innerText) !== ",") {
250
245
  var vText = cellInput.innerText;
251
246
  if (vText[vText.length - 1] === ")") {
252
247
  vText = vText.substring(0, vText.length - 1);
@@ -262,7 +257,7 @@ export function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, containe
262
257
  if (window.getSelection) {
263
258
  var currSelection = window.getSelection();
264
259
  if (currSelection == null) return;
265
- ctx.formulaCache.functionRangeIndex = [_.indexOf((_l = (_k = (_j = currSelection.anchorNode) === null || _j === void 0 ? void 0 : _j.parentNode) === null || _k === void 0 ? void 0 : _k.parentNode) === null || _l === void 0 ? void 0 : _l.childNodes, (_m = currSelection.anchorNode) === null || _m === void 0 ? void 0 : _m.parentNode), currSelection.anchorOffset];
260
+ ctx.formulaCache.functionRangeIndex = [_.indexOf((_k = (_j = (_h = currSelection.anchorNode) === null || _h === void 0 ? void 0 : _h.parentNode) === null || _j === void 0 ? void 0 : _j.parentNode) === null || _k === void 0 ? void 0 : _k.childNodes, (_l = currSelection.anchorNode) === null || _l === void 0 ? void 0 : _l.parentNode), currSelection.anchorOffset];
266
261
  } else {
267
262
  var textRange = document.selection.createRange();
268
263
  ctx.formulaCache.functionRangeIndex = textRange;
@@ -307,13 +302,14 @@ export function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, containe
307
302
  column_focus: col_index
308
303
  };
309
304
  }
305
+ ctx.formulaCache.rangestart = true;
306
+ ctx.formulaCache.rangedrag_column_start = false;
307
+ ctx.formulaCache.rangedrag_row_start = false;
310
308
  rangeSetValue(ctx, cellInput, {
311
309
  row: rowseleted,
312
310
  column: columnseleted
313
311
  }, fxInput);
314
- ctx.formulaCache.rangestart = true;
315
- ctx.formulaCache.rangedrag_column_start = false;
316
- ctx.formulaCache.rangedrag_row_start = false;
312
+ rangeHightlightselected(ctx, cellInput);
317
313
  ctx.formulaCache.selectingRangeIndex = ctx.formulaCache.rangechangeindex;
318
314
  if (ctx.formulaCache.rangechangeindex > ctx.formulaRangeHighlight.length) {
319
315
  createRangeHightlight(ctx, cellInput.innerHTML, ctx.formulaCache.rangechangeindex);
@@ -336,7 +332,7 @@ export function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, containe
336
332
  }
337
333
  if (ctx.luckysheet_select_status) {
338
334
  if (e.shiftKey) {
339
- var last = (_o = ctx.luckysheet_select_save) === null || _o === void 0 ? void 0 : _o[ctx.luckysheet_select_save.length - 1];
335
+ var last = (_m = ctx.luckysheet_select_save) === null || _m === void 0 ? void 0 : _m[ctx.luckysheet_select_save.length - 1];
340
336
  if (last && last.top != null && last.left != null && last.height != null && last.width != null && last.row_focus != null && last.column_focus != null) {
341
337
  var top_2 = 0;
342
338
  var height = 0;
@@ -395,7 +391,7 @@ export function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, containe
395
391
  ctx.luckysheet_select_save[ctx.luckysheet_select_save.length - 1] = last;
396
392
  }
397
393
  } else if (e.ctrlKey || e.metaKey) {
398
- (_p = ctx.luckysheet_select_save) === null || _p === void 0 ? void 0 : _p.push({
394
+ (_o = ctx.luckysheet_select_save) === null || _o === void 0 ? void 0 : _o.push({
399
395
  left: col_pre,
400
396
  width: col - col_pre - 1,
401
397
  top: row_pre,
@@ -827,10 +823,28 @@ export function mouseRender(ctx, globalCache, e, cellInput, scrollX, scrollY, co
827
823
  ctx.luckysheet_select_save[ctx.luckysheet_select_save.length - 1] = last;
828
824
  scrollToFrozenRowCol(ctx, (_d = globalCache.freezen) === null || _d === void 0 ? void 0 : _d[ctx.currentSheetId]);
829
825
  } else if (ctx.formulaCache.rangestart) {
826
+ if (ctx.formulaCache.rangeSelectionActive === false && !maybeRecoverDirtyRangeSelection(ctx)) {
827
+ if (ctx.luckysheetCellUpdate.length > 0) {
828
+ updateCell(ctx, ctx.luckysheetCellUpdate[0], ctx.luckysheetCellUpdate[1], cellInput);
829
+ }
830
+ return;
831
+ }
830
832
  rangeDrag(ctx, e, cellInput, scrollX.scrollLeft, scrollY.scrollTop, container, fxInput);
831
833
  } else if (ctx.formulaCache.rangedrag_row_start) {
834
+ if (ctx.formulaCache.rangeSelectionActive === false && !maybeRecoverDirtyRangeSelection(ctx)) {
835
+ if (ctx.luckysheetCellUpdate.length > 0) {
836
+ updateCell(ctx, ctx.luckysheetCellUpdate[0], ctx.luckysheetCellUpdate[1], cellInput);
837
+ }
838
+ return;
839
+ }
832
840
  rangeDragRow(ctx, e, cellInput, scrollX.scrollLeft, scrollY.scrollTop, container, fxInput);
833
841
  } else if (ctx.formulaCache.rangedrag_column_start) {
842
+ if (ctx.formulaCache.rangeSelectionActive === false && !maybeRecoverDirtyRangeSelection(ctx)) {
843
+ if (ctx.luckysheetCellUpdate.length > 0) {
844
+ updateCell(ctx, ctx.luckysheetCellUpdate[0], ctx.luckysheetCellUpdate[1], cellInput);
845
+ }
846
+ return;
847
+ }
834
848
  rangeDragColumn(ctx, e, cellInput, scrollX.scrollLeft, scrollY.scrollTop, container, fxInput);
835
849
  } else if (ctx.luckysheet_rows_selected_status) {} else if (ctx.luckysheet_cols_selected_status) {} else if (ctx.luckysheet_cell_selected_move) {} else if (ctx.luckysheet_cell_selected_extend) {
836
850
  onDropCellSelect(ctx, e, scrollX, scrollY, container);
@@ -936,7 +950,7 @@ export function handleOverlayMouseMove(ctx, globalCache, e, cellInput, scrollX,
936
950
  }
937
951
  }
938
952
  export function handleOverlayMouseUp(ctx, globalCache, settings, e, scrollbarX, scrollbarY, container, cellInput, fxInput) {
939
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
953
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
940
954
  var rect = container.getBoundingClientRect();
941
955
  onImageMoveEnd(ctx, globalCache);
942
956
  onImageResizeEnd(ctx, globalCache);
@@ -949,11 +963,17 @@ export function handleOverlayMouseUp(ctx, globalCache, settings, e, scrollbarX,
949
963
  onRangeSelectionModalMoveEnd(globalCache);
950
964
  onCellsMoveEnd(ctx, globalCache, e, scrollbarX, scrollbarY, container);
951
965
  if (ctx.formulaCache.rangestart || ctx.formulaCache.rangedrag_column_start || ctx.formulaCache.rangedrag_row_start) {
952
- if (((_a = document.activeElement) === null || _a === void 0 ? void 0 : _a.id) === "luckysheet-functionbox-cell") {
966
+ if (getFormulaEditorOwner(ctx) === "fx") {
953
967
  handleFormulaInput(ctx, cellInput, fxInput, 0, undefined, false);
954
968
  } else {
955
969
  handleFormulaInput(ctx, fxInput, cellInput, 0, undefined, false);
956
970
  }
971
+ ctx.luckysheet_select_status = false;
972
+ ctx.luckysheet_scroll_status = false;
973
+ ctx.luckysheet_rows_selected_status = false;
974
+ ctx.luckysheet_cols_selected_status = false;
975
+ e.preventDefault();
976
+ return;
957
977
  }
958
978
  if (ctx.luckysheet_select_status) {
959
979
  if (ctx.luckysheetPaintModelOn) {
@@ -995,10 +1015,10 @@ export function handleOverlayMouseUp(ctx, globalCache, settings, e, scrollbarX,
995
1015
  cfg_1.customHeight[ctx.luckysheet_rows_change_size_start[1]] = 1;
996
1016
  var changeRowIndex_1 = ctx.luckysheet_rows_change_size_start[1];
997
1017
  var changeRowSelected_1 = false;
998
- if (((_c = (_b = ctx.luckysheet_select_save) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) > 0) {
999
- (_e = (_d = ctx.luckysheet_select_save) === null || _d === void 0 ? void 0 : _d.filter(function (select) {
1018
+ if (((_b = (_a = ctx.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0) {
1019
+ (_d = (_c = ctx.luckysheet_select_save) === null || _c === void 0 ? void 0 : _c.filter(function (select) {
1000
1020
  return select.row_select;
1001
- })) === null || _e === void 0 ? void 0 : _e.some(function (select) {
1021
+ })) === null || _d === void 0 ? void 0 : _d.some(function (select) {
1002
1022
  if (changeRowIndex_1 >= select.row[0] && changeRowIndex_1 <= select.row[1]) {
1003
1023
  changeRowSelected_1 = true;
1004
1024
  }
@@ -1007,9 +1027,9 @@ export function handleOverlayMouseUp(ctx, globalCache, settings, e, scrollbarX,
1007
1027
  }
1008
1028
  if (changeRowSelected_1) {
1009
1029
  cfg_1.rowlen || (cfg_1.rowlen = {});
1010
- (_g = (_f = ctx.luckysheet_select_save) === null || _f === void 0 ? void 0 : _f.filter(function (select) {
1030
+ (_f = (_e = ctx.luckysheet_select_save) === null || _e === void 0 ? void 0 : _e.filter(function (select) {
1011
1031
  return select.row_select;
1012
- })) === null || _g === void 0 ? void 0 : _g.forEach(function (select) {
1032
+ })) === null || _f === void 0 ? void 0 : _f.forEach(function (select) {
1013
1033
  for (var r = select.row[0]; r <= select.row[1]; r += 1) {
1014
1034
  cfg_1.rowlen[r] = Math.ceil(size_1 / ctx.zoomRatio);
1015
1035
  }
@@ -1053,10 +1073,10 @@ export function handleOverlayMouseUp(ctx, globalCache, settings, e, scrollbarX,
1053
1073
  cfg_2.customWidth[ctx.luckysheet_cols_change_size_start[1]] = 1;
1054
1074
  var changeColumnIndex_1 = ctx.luckysheet_cols_change_size_start[1];
1055
1075
  var changeColumnSelected_1 = false;
1056
- if (((_j = (_h = ctx.luckysheet_select_save) === null || _h === void 0 ? void 0 : _h.length) !== null && _j !== void 0 ? _j : 0) > 0) {
1057
- (_l = (_k = ctx.luckysheet_select_save) === null || _k === void 0 ? void 0 : _k.filter(function (select) {
1076
+ if (((_h = (_g = ctx.luckysheet_select_save) === null || _g === void 0 ? void 0 : _g.length) !== null && _h !== void 0 ? _h : 0) > 0) {
1077
+ (_k = (_j = ctx.luckysheet_select_save) === null || _j === void 0 ? void 0 : _j.filter(function (select) {
1058
1078
  return select.column_select;
1059
- })) === null || _l === void 0 ? void 0 : _l.some(function (select) {
1079
+ })) === null || _k === void 0 ? void 0 : _k.some(function (select) {
1060
1080
  if (changeColumnIndex_1 >= select.column[0] && changeColumnIndex_1 <= select.column[1]) {
1061
1081
  changeColumnSelected_1 = true;
1062
1082
  }
@@ -1065,9 +1085,9 @@ export function handleOverlayMouseUp(ctx, globalCache, settings, e, scrollbarX,
1065
1085
  }
1066
1086
  if (changeColumnSelected_1) {
1067
1087
  cfg_2.columnlen || (cfg_2.columnlen = {});
1068
- (_o = (_m = ctx.luckysheet_select_save) === null || _m === void 0 ? void 0 : _m.filter(function (select) {
1088
+ (_m = (_l = ctx.luckysheet_select_save) === null || _l === void 0 ? void 0 : _l.filter(function (select) {
1069
1089
  return select.column_select;
1070
- })) === null || _o === void 0 ? void 0 : _o.forEach(function (select) {
1090
+ })) === null || _m === void 0 ? void 0 : _m.forEach(function (select) {
1071
1091
  for (var r = select.column[0]; r <= select.column[1]; r += 1) {
1072
1092
  cfg_2.columnlen[r] = Math.ceil(size_2 / ctx.zoomRatio);
1073
1093
  }
@@ -1084,10 +1104,10 @@ export function handleOverlayMouseUp(ctx, globalCache, settings, e, scrollbarX,
1084
1104
  ctx.luckysheet_cols_freeze_drag = false;
1085
1105
  var scrollLeft = ctx.scrollLeft;
1086
1106
  var x = e.pageX - rect.left - ctx.rowHeaderWidth + scrollLeft - window.scrollX;
1087
- var _p = colLocation(x, ctx.visibledatacolumn),
1088
- col_pre = _p[0],
1089
- col_curr = _p[1],
1090
- col_index_curr = _p[2];
1107
+ var _o = colLocation(x, ctx.visibledatacolumn),
1108
+ col_pre = _o[0],
1109
+ col_curr = _o[1],
1110
+ col_index_curr = _o[2];
1091
1111
  var col_index = x > (col_curr + col_pre) / 2 ? col_index_curr : col_index_curr - 1;
1092
1112
  var idx = getSheetIndex(ctx, ctx.currentSheetId);
1093
1113
  if (idx == null) return;
@@ -1135,10 +1155,10 @@ export function handleOverlayMouseUp(ctx, globalCache, settings, e, scrollbarX,
1135
1155
  ctx.luckysheet_rows_freeze_drag = false;
1136
1156
  var scrollTop = ctx.scrollTop;
1137
1157
  var y = e.pageY - rect.top - ctx.columnHeaderHeight + scrollTop - window.scrollY;
1138
- var _q = rowLocation(y, ctx.visibledatarow),
1139
- row_pre = _q[0],
1140
- row_curr = _q[1],
1141
- row_index_curr = _q[2];
1158
+ var _p = rowLocation(y, ctx.visibledatarow),
1159
+ row_pre = _p[0],
1160
+ row_curr = _p[1],
1161
+ row_index_curr = _p[2];
1142
1162
  var row_index = y > (row_curr + row_pre) / 2 ? row_index_curr : row_index_curr - 1;
1143
1163
  var idx = getSheetIndex(ctx, ctx.currentSheetId);
1144
1164
  if (idx == null) return;
@@ -1317,6 +1337,7 @@ export function handleRowHeaderMouseDown(ctx, globalCache, e, container, cellInp
1317
1337
  row: rowseleted,
1318
1338
  column: [null, null]
1319
1339
  }, fxInput);
1340
+ rangeHightlightselected(ctx, cellInput);
1320
1341
  }
1321
1342
  ctx.formulaCache.rangedrag_row_start = true;
1322
1343
  ctx.formulaCache.rangestart = false;
@@ -1548,6 +1569,7 @@ export function handleColumnHeaderMouseDown(ctx, globalCache, e, container, cell
1548
1569
  row: [null, null],
1549
1570
  column: columnseleted
1550
1571
  }, fxInput);
1572
+ rangeHightlightselected(ctx, cellInput);
1551
1573
  }
1552
1574
  ctx.formulaCache.rangedrag_column_start = true;
1553
1575
  ctx.formulaCache.rangestart = false;