@fileverse-dev/fortune-core 1.3.12 → 1.3.13-create-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.
- package/es/events/keyboard.d.ts +2 -2
- package/es/events/keyboard.js +204 -30
- package/es/events/mouse.js +79 -44
- package/es/events/paste.js +177 -56
- package/es/locale/en.d.ts +3 -0
- package/es/locale/en.js +3 -0
- package/es/locale/es.d.ts +3 -0
- package/es/locale/es.js +3 -0
- package/es/locale/hi.d.ts +3 -0
- package/es/locale/hi.js +3 -0
- package/es/locale/index.d.ts +3 -0
- package/es/locale/zh.d.ts +3 -0
- package/es/locale/zh.js +3 -0
- package/es/locale/zh_tw.d.ts +3 -0
- package/es/locale/zh_tw.js +3 -0
- package/es/modules/ConditionFormat.js +26 -0
- package/es/modules/cell.d.ts +4 -1
- package/es/modules/cell.js +124 -15
- package/es/modules/clipboard.js +111 -2
- package/es/modules/format.js +12 -7
- package/es/modules/formula.d.ts +23 -0
- package/es/modules/formula.js +610 -51
- package/es/modules/hyperlink.js +18 -6
- package/es/modules/inline-string.js +21 -4
- package/es/modules/moveCells.js +52 -9
- package/es/modules/selection.d.ts +1 -0
- package/es/modules/selection.js +102 -16
- package/es/modules/validation.js +6 -3
- package/es/paste-helpers/calculate-range-cell-size.js +5 -4
- package/es/paste-table-helpers.d.ts +1 -1
- package/es/paste-table-helpers.js +170 -21
- package/es/types.d.ts +3 -0
- package/lib/events/keyboard.d.ts +2 -2
- package/lib/events/keyboard.js +203 -29
- package/lib/events/mouse.js +78 -43
- package/lib/events/paste.js +175 -54
- package/lib/locale/en.d.ts +3 -0
- package/lib/locale/en.js +3 -0
- package/lib/locale/es.d.ts +3 -0
- package/lib/locale/es.js +3 -0
- package/lib/locale/hi.d.ts +3 -0
- package/lib/locale/hi.js +3 -0
- package/lib/locale/index.d.ts +3 -0
- package/lib/locale/zh.d.ts +3 -0
- package/lib/locale/zh.js +3 -0
- package/lib/locale/zh_tw.d.ts +3 -0
- package/lib/locale/zh_tw.js +3 -0
- package/lib/modules/ConditionFormat.js +26 -0
- package/lib/modules/cell.d.ts +4 -1
- package/lib/modules/cell.js +123 -14
- package/lib/modules/clipboard.js +111 -2
- package/lib/modules/format.js +12 -7
- package/lib/modules/formula.d.ts +23 -0
- package/lib/modules/formula.js +623 -51
- package/lib/modules/hyperlink.js +18 -6
- package/lib/modules/inline-string.js +21 -4
- package/lib/modules/moveCells.js +52 -9
- package/lib/modules/selection.d.ts +1 -0
- package/lib/modules/selection.js +101 -15
- package/lib/modules/validation.js +6 -3
- package/lib/paste-helpers/calculate-range-cell-size.js +5 -4
- package/lib/paste-table-helpers.d.ts +1 -1
- package/lib/paste-table-helpers.js +170 -21
- package/lib/types.d.ts +3 -0
- package/package.json +1 -1
package/es/events/keyboard.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Context } from "../context";
|
|
2
2
|
import { GlobalCache } from "../types";
|
|
3
|
-
export declare function handleGlobalEnter(ctx: Context, cellInput: HTMLDivElement, e: KeyboardEvent, canvas?: CanvasRenderingContext2D): void;
|
|
4
|
-
export declare function handleWithCtrlOrMetaKey(ctx: Context, cache: GlobalCache, e: KeyboardEvent, cellInput: HTMLDivElement, fxInput: HTMLDivElement | null | undefined, handleUndo: () => void, handleRedo: () => void): void;
|
|
3
|
+
export declare function handleGlobalEnter(ctx: Context, cellInput: HTMLDivElement, e: KeyboardEvent, cache: GlobalCache, canvas?: CanvasRenderingContext2D): void;
|
|
4
|
+
export declare function handleWithCtrlOrMetaKey(ctx: Context, cache: GlobalCache, e: KeyboardEvent, cellInput: HTMLDivElement, fxInput: HTMLDivElement | null | undefined, handleUndo: () => void, handleRedo: () => void, canvas?: CanvasRenderingContext2D): void;
|
|
5
5
|
export declare function handleArrowKey(ctx: Context, e: KeyboardEvent): void;
|
|
6
6
|
export declare function handleGlobalKeyDown(ctx: Context, cellInput: HTMLDivElement, fxInput: HTMLDivElement | null | undefined, e: KeyboardEvent, cache: GlobalCache, handleUndo: () => void, handleRedo: () => void, canvas?: CanvasRenderingContext2D): Promise<void>;
|
package/es/events/keyboard.js
CHANGED
|
@@ -117,15 +117,30 @@ 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, setFormulaEditorOwner, getFormulaEditorOwner, suppressFormulaRangeSelectionForInitialEdit } from "../modules/formula";
|
|
121
|
+
import { isInlineStringCell } from "../modules/inline-string";
|
|
121
122
|
import { copy, deleteSelectedCellText, deleteSelectedCellFormat, textFormat, fillDate, fillTime, fillRightData, fillDownData, moveHighlightCell, moveHighlightRange, selectAll, selectionCache } from "../modules/selection";
|
|
122
123
|
import { cancelPaintModel, handleBold, handleItalic, handleUnderline, handleLink } from "../modules/toolbar";
|
|
123
124
|
import { hasPartMC } from "../modules/validation";
|
|
124
125
|
import { getNowDateTime, getSheetIndex, isAllowEdit } from "../utils";
|
|
125
126
|
import { handleCopy } from "./copy";
|
|
126
127
|
import { jfrefreshgrid } from "../modules/refresh";
|
|
127
|
-
|
|
128
|
-
|
|
128
|
+
import { moveToEnd } from "../modules/cursor";
|
|
129
|
+
function clearTypeOverPending(cache) {
|
|
130
|
+
delete cache.pendingTypeOverCell;
|
|
131
|
+
}
|
|
132
|
+
function getTypeOverInitialContent(e) {
|
|
133
|
+
if (e.keyCode === 229) return undefined;
|
|
134
|
+
if (e.ctrlKey || e.metaKey || e.altKey) return undefined;
|
|
135
|
+
if (e.key === "Backspace" || e.key === "Delete") return "";
|
|
136
|
+
if (e.key.length === 1) return e.key;
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
function isLegacyFormulaRangeMode(ctx) {
|
|
140
|
+
return !!ctx.formulaCache.rangestart || !!ctx.formulaCache.rangedrag_column_start || !!ctx.formulaCache.rangedrag_row_start || ctx.formulaCache.rangeSelectionActive === true || israngeseleciton(ctx);
|
|
141
|
+
}
|
|
142
|
+
export function handleGlobalEnter(ctx, cellInput, e, cache, canvas) {
|
|
143
|
+
var _a, _b, _c, _d;
|
|
129
144
|
if ((e.altKey || e.metaKey) && ctx.luckysheetCellUpdate.length > 0) {
|
|
130
145
|
var last = (_a = ctx.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[ctx.luckysheet_select_save.length - 1];
|
|
131
146
|
if (last && !_.isNil(last.row_focus) && !_.isNil(last.column_focus)) {}
|
|
@@ -133,33 +148,61 @@ export function handleGlobalEnter(ctx, cellInput, e, canvas) {
|
|
|
133
148
|
} else if (ctx.luckysheetCellUpdate.length > 0) {
|
|
134
149
|
var lastCellUpdate = _.clone(ctx.luckysheetCellUpdate);
|
|
135
150
|
updateCell(ctx, ctx.luckysheetCellUpdate[0], ctx.luckysheetCellUpdate[1], cellInput, undefined, canvas);
|
|
151
|
+
cache.enteredEditByTyping = false;
|
|
152
|
+
clearTypeOverPending(cache);
|
|
136
153
|
ctx.luckysheet_select_save = [{
|
|
137
154
|
row: [lastCellUpdate[0], lastCellUpdate[0]],
|
|
138
155
|
column: [lastCellUpdate[1], lastCellUpdate[1]],
|
|
139
156
|
row_focus: lastCellUpdate[0],
|
|
140
157
|
column_focus: lastCellUpdate[1]
|
|
141
158
|
}];
|
|
142
|
-
|
|
159
|
+
var rowStep = e.shiftKey ? -hideCRCount(ctx, "ArrowUp") : hideCRCount(ctx, "ArrowDown");
|
|
160
|
+
moveHighlightCell(ctx, "down", rowStep, "rangeOfSelect");
|
|
143
161
|
e.preventDefault();
|
|
144
162
|
} else {
|
|
145
163
|
if (((_c = (_b = ctx.luckysheet_select_save) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) > 0) {
|
|
146
164
|
var last = ctx.luckysheet_select_save[ctx.luckysheet_select_save.length - 1];
|
|
147
165
|
var row_index = last.row_focus;
|
|
148
166
|
var col_index = last.column_focus;
|
|
167
|
+
if (!_.isNil(row_index) && !_.isNil(col_index)) {
|
|
168
|
+
var flowdata = getFlowdata(ctx);
|
|
169
|
+
var cellAt = (_d = flowdata === null || flowdata === void 0 ? void 0 : flowdata[row_index]) === null || _d === void 0 ? void 0 : _d[col_index];
|
|
170
|
+
if ((cellAt === null || cellAt === void 0 ? void 0 : cellAt.f) != null && String(cellAt.f).trim() !== "") {
|
|
171
|
+
suppressFormulaRangeSelectionForInitialEdit(ctx);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
149
174
|
ctx.luckysheetCellUpdate = [row_index, col_index];
|
|
175
|
+
cache.enteredEditByTyping = false;
|
|
176
|
+
clearTypeOverPending(cache);
|
|
150
177
|
e.preventDefault();
|
|
151
178
|
}
|
|
152
179
|
}
|
|
153
180
|
}
|
|
181
|
+
function cellCountsForDataEdge(cell) {
|
|
182
|
+
var _a, _b;
|
|
183
|
+
if (cell == null) return false;
|
|
184
|
+
if (!_.isPlainObject(cell)) return !_.isNil(cell);
|
|
185
|
+
if (cell.f != null && String(cell.f) !== "") return true;
|
|
186
|
+
if (!_.isNil(cell.v)) return true;
|
|
187
|
+
if (isInlineStringCell(cell)) {
|
|
188
|
+
return ((_b = (_a = cell.ct) === null || _a === void 0 ? void 0 : _a.s) !== null && _b !== void 0 ? _b : []).some(function (seg) {
|
|
189
|
+
return (seg === null || seg === void 0 ? void 0 : seg.v) != null && String(seg.v).length > 0;
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
154
194
|
function moveToEdge(sheetData, key, curr, rowDelta, colDelta, startR, endR, startC, endC, maxRow, maxCol) {
|
|
155
|
-
var _a, _b, _c
|
|
195
|
+
var _a, _b, _c;
|
|
156
196
|
var selectedLimit = -1;
|
|
157
197
|
if (key === "ArrowUp") selectedLimit = startR - 1;else if (key === "ArrowDown") selectedLimit = endR + 1;else if (key === "ArrowLeft") selectedLimit = startC - 1;else if (key === "ArrowRight") selectedLimit = endC + 1;
|
|
158
198
|
var maxRowCol = colDelta === 0 ? maxRow : maxCol;
|
|
159
199
|
var r = colDelta === 0 ? selectedLimit : curr;
|
|
160
200
|
var c = colDelta === 0 ? curr : selectedLimit;
|
|
161
201
|
while (r >= 0 && c >= 0 && (colDelta === 0 ? r : c) < maxRowCol - 1) {
|
|
162
|
-
|
|
202
|
+
var here = (_a = sheetData === null || sheetData === void 0 ? void 0 : sheetData[r]) === null || _a === void 0 ? void 0 : _a[c];
|
|
203
|
+
var behind = (_b = sheetData === null || sheetData === void 0 ? void 0 : sheetData[r - rowDelta]) === null || _b === void 0 ? void 0 : _b[c - colDelta];
|
|
204
|
+
var ahead = (_c = sheetData === null || sheetData === void 0 ? void 0 : sheetData[r + rowDelta]) === null || _c === void 0 ? void 0 : _c[c + colDelta];
|
|
205
|
+
if (cellCountsForDataEdge(here) && (!cellCountsForDataEdge(behind) || !cellCountsForDataEdge(ahead))) {
|
|
163
206
|
break;
|
|
164
207
|
} else {
|
|
165
208
|
r += 1 * rowDelta;
|
|
@@ -168,12 +211,51 @@ function moveToEdge(sheetData, key, curr, rowDelta, colDelta, startR, endR, star
|
|
|
168
211
|
}
|
|
169
212
|
return colDelta === 0 ? r : c;
|
|
170
213
|
}
|
|
214
|
+
function isPlainTextCellOrFxEdit(ctx, cellInput, fxInput) {
|
|
215
|
+
var _a, _b, _c;
|
|
216
|
+
if (ctx.luckysheetCellUpdate.length === 0) return false;
|
|
217
|
+
var cellT = ((_a = cellInput === null || cellInput === void 0 ? void 0 : cellInput.innerText) !== null && _a !== void 0 ? _a : "").trim();
|
|
218
|
+
var fxT = ((_b = fxInput === null || fxInput === void 0 ? void 0 : fxInput.innerText) !== null && _b !== void 0 ? _b : "").trim();
|
|
219
|
+
var owner = getFormulaEditorOwner(ctx);
|
|
220
|
+
if (owner === "fx" && fxInput) {
|
|
221
|
+
return !fxT.startsWith("=");
|
|
222
|
+
}
|
|
223
|
+
if (owner === "cell") {
|
|
224
|
+
return !cellT.startsWith("=");
|
|
225
|
+
}
|
|
226
|
+
var aid = (_c = document.activeElement) === null || _c === void 0 ? void 0 : _c.id;
|
|
227
|
+
if (aid === "luckysheet-functionbox-cell" && fxInput) {
|
|
228
|
+
return !fxT.startsWith("=");
|
|
229
|
+
}
|
|
230
|
+
if (aid === "luckysheet-rich-text-editor") {
|
|
231
|
+
return !cellT.startsWith("=");
|
|
232
|
+
}
|
|
233
|
+
if (cellT.startsWith("=") || fxT.startsWith("=")) return false;
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
function isDirectPlainTextCellEdit(ctx, cache, cellInput, fxInput) {
|
|
237
|
+
return (cache === null || cache === void 0 ? void 0 : cache.enteredEditByTyping) === true && ctx.luckysheetCellUpdate.length > 0 && isPlainTextCellOrFxEdit(ctx, cellInput, fxInput);
|
|
238
|
+
}
|
|
239
|
+
function commitDirectPlainCellEdit(ctx, cache, cellInput, canvas) {
|
|
240
|
+
if (ctx.luckysheetCellUpdate.length === 0) return;
|
|
241
|
+
updateCell(ctx, ctx.luckysheetCellUpdate[0], ctx.luckysheetCellUpdate[1], cellInput, undefined, canvas);
|
|
242
|
+
if (cache) {
|
|
243
|
+
cache.enteredEditByTyping = false;
|
|
244
|
+
clearTypeOverPending(cache);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
171
247
|
function handleControlPlusArrowKey(ctx, e, shiftPressed) {
|
|
172
|
-
|
|
248
|
+
var isFormulaRefMode = isLegacyFormulaRangeMode(ctx);
|
|
249
|
+
if (isFormulaRefMode) {
|
|
250
|
+
ctx.formulaCache.rangeSelectionActive = true;
|
|
251
|
+
}
|
|
252
|
+
if (ctx.luckysheetCellUpdate.length > 0 && !isFormulaRefMode) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
173
255
|
var idx = getSheetIndex(ctx, ctx.currentSheetId);
|
|
174
256
|
if (_.isNil(idx)) return;
|
|
175
257
|
var file = ctx.luckysheetfile[idx];
|
|
176
|
-
if (!file ||
|
|
258
|
+
if (!file || _.isNil(file.row) || _.isNil(file.column)) return;
|
|
177
259
|
var maxRow = file.row;
|
|
178
260
|
var maxCol = file.column;
|
|
179
261
|
var last;
|
|
@@ -232,10 +314,17 @@ function handleControlPlusArrowKey(ctx, e, shiftPressed) {
|
|
|
232
314
|
break;
|
|
233
315
|
}
|
|
234
316
|
}
|
|
235
|
-
export function handleWithCtrlOrMetaKey(ctx, cache, e, cellInput, fxInput, handleUndo, handleRedo) {
|
|
236
|
-
var _a, _b, _c, _d;
|
|
317
|
+
export function handleWithCtrlOrMetaKey(ctx, cache, e, cellInput, fxInput, handleUndo, handleRedo, canvas) {
|
|
318
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
237
319
|
var flowdata = getFlowdata(ctx);
|
|
238
320
|
if (!flowdata) return;
|
|
321
|
+
if ((e.ctrlKey || e.metaKey) && ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].includes(e.key) && isPlainTextCellOrFxEdit(ctx, cellInput, fxInput)) {
|
|
322
|
+
if (isDirectPlainTextCellEdit(ctx, cache, cellInput, fxInput)) {
|
|
323
|
+
commitDirectPlainCellEdit(ctx, cache, cellInput, canvas);
|
|
324
|
+
} else {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
239
328
|
if (e.shiftKey) {
|
|
240
329
|
ctx.luckysheet_shiftpositon = _.cloneDeep((_a = ctx.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[ctx.luckysheet_select_save.length - 1]);
|
|
241
330
|
ctx.luckysheet_shiftkeydown = true;
|
|
@@ -248,6 +337,8 @@ export function handleWithCtrlOrMetaKey(ctx, cache, e, cellInput, fxInput, handl
|
|
|
248
337
|
var col_index = last.column_focus;
|
|
249
338
|
updateCell(ctx, row_index, col_index, cellInput);
|
|
250
339
|
ctx.luckysheetCellUpdate = [row_index, col_index];
|
|
340
|
+
cache.enteredEditByTyping = false;
|
|
341
|
+
clearTypeOverPending(cache);
|
|
251
342
|
cache.ignoreWriteCell = true;
|
|
252
343
|
var value = getNowDateTime(2);
|
|
253
344
|
cellInput.innerText = value;
|
|
@@ -256,6 +347,14 @@ export function handleWithCtrlOrMetaKey(ctx, cache, e, cellInput, fxInput, handl
|
|
|
256
347
|
handleRedo();
|
|
257
348
|
e.stopPropagation();
|
|
258
349
|
return;
|
|
350
|
+
} else if (e.code === "KeyV") {
|
|
351
|
+
if (((_d = (_c = ctx.luckysheet_select_save) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0) > 1) {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
selectionCache.isPasteAction = true;
|
|
355
|
+
selectionCache.isPasteValuesOnly = true;
|
|
356
|
+
e.stopPropagation();
|
|
357
|
+
return;
|
|
259
358
|
}
|
|
260
359
|
} else if (["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].includes(e.key)) {
|
|
261
360
|
handleControlPlusArrowKey(ctx, e, false);
|
|
@@ -268,7 +367,14 @@ export function handleWithCtrlOrMetaKey(ctx, cache, e, cellInput, fxInput, handl
|
|
|
268
367
|
} else if (e.code === "Backslash") {
|
|
269
368
|
deleteSelectedCellFormat(ctx);
|
|
270
369
|
} else if (e.code === "KeyC") {
|
|
271
|
-
|
|
370
|
+
if (ctx.luckysheetCellUpdate.length > 0) {
|
|
371
|
+
e.preventDefault();
|
|
372
|
+
var sel = window.getSelection();
|
|
373
|
+
var text = sel && !sel.isCollapsed ? sel.toString() : cellInput.innerText;
|
|
374
|
+
(_e = navigator.clipboard) === null || _e === void 0 ? void 0 : _e.writeText(text).catch(function () {});
|
|
375
|
+
} else {
|
|
376
|
+
handleCopy(ctx);
|
|
377
|
+
}
|
|
272
378
|
e.stopPropagation();
|
|
273
379
|
return;
|
|
274
380
|
} else if (e.code === "KeyF") {
|
|
@@ -276,7 +382,7 @@ export function handleWithCtrlOrMetaKey(ctx, cache, e, cellInput, fxInput, handl
|
|
|
276
382
|
} else if (e.code === "KeyH") {
|
|
277
383
|
ctx.showReplace = true;
|
|
278
384
|
} else if (e.code === "KeyV") {
|
|
279
|
-
if (((
|
|
385
|
+
if (((_g = (_f = ctx.luckysheet_select_save) === null || _f === void 0 ? void 0 : _f.length) !== null && _g !== void 0 ? _g : 0) > 1) {
|
|
280
386
|
return;
|
|
281
387
|
}
|
|
282
388
|
selectionCache.isPasteAction = true;
|
|
@@ -324,7 +430,17 @@ export function handleWithCtrlOrMetaKey(ctx, cache, e, cellInput, fxInput, handl
|
|
|
324
430
|
}
|
|
325
431
|
function handleShiftWithArrowKey(ctx, e) {
|
|
326
432
|
var _a;
|
|
327
|
-
if (ctx.
|
|
433
|
+
if (ctx.formulaCache.keyboardRangeSelectionLock === true) {
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
if (ctx.formulaCache.rangeSelectionActive === false && !maybeRecoverDirtyRangeSelection(ctx)) {
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
var isFormulaMode = isLegacyFormulaRangeMode(ctx);
|
|
440
|
+
if (isFormulaMode) {
|
|
441
|
+
ctx.formulaCache.rangeSelectionActive = true;
|
|
442
|
+
}
|
|
443
|
+
if (ctx.luckysheetCellUpdate.length > 0 && !isFormulaMode) {
|
|
328
444
|
return;
|
|
329
445
|
}
|
|
330
446
|
ctx.luckysheet_shiftpositon = _.cloneDeep((_a = ctx.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[ctx.luckysheet_select_save.length - 1]);
|
|
@@ -348,17 +464,18 @@ function handleShiftWithArrowKey(ctx, e) {
|
|
|
348
464
|
e.preventDefault();
|
|
349
465
|
}
|
|
350
466
|
export function handleArrowKey(ctx, e) {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
467
|
+
if (ctx.formulaCache.keyboardRangeSelectionLock === true) {
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
if (ctx.formulaCache.rangeSelectionActive === false && !maybeRecoverDirtyRangeSelection(ctx)) {
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
var isFormulaRefMode = isLegacyFormulaRangeMode(ctx);
|
|
474
|
+
if (isFormulaRefMode) ctx.formulaCache.rangeSelectionActive = true;
|
|
475
|
+
if (ctx.luckysheetCellUpdate.length > 0 && !isFormulaRefMode) {
|
|
476
|
+
return;
|
|
361
477
|
}
|
|
478
|
+
if (ctx.luckysheetCellUpdate.length > 0 || ctx.luckysheet_cell_selected_move || ctx.luckysheet_cell_selected_extend) {}
|
|
362
479
|
var moveCount = hideCRCount(ctx, e.key);
|
|
363
480
|
switch (e.key) {
|
|
364
481
|
case "ArrowUp":
|
|
@@ -376,12 +493,13 @@ export function handleArrowKey(ctx, e) {
|
|
|
376
493
|
default:
|
|
377
494
|
break;
|
|
378
495
|
}
|
|
496
|
+
e.preventDefault();
|
|
379
497
|
}
|
|
380
498
|
export function handleGlobalKeyDown(ctx, cellInput, fxInput, e, cache, handleUndo, handleRedo, canvas) {
|
|
381
|
-
var _a, _b, _c;
|
|
499
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
382
500
|
return __awaiter(this, void 0, void 0, function () {
|
|
383
|
-
var handledFlvShortcut, kcode, kstr, allowEdit, isFxInput, ignoredKeys, restCod, last, row_index, col_index, last, row_index, col_index;
|
|
384
|
-
return __generator(this, function (
|
|
501
|
+
var handledFlvShortcut, kcode, kstr, allowEdit, isFxInput, ignoredKeys, restCod, last, row_index, col_index, flowdataF2, cellF2, isEditing, inlineText, fxText, isFormulaEdit, enteredByTyping, last, row_index, col_index, flowdata, cellAt, existingFormula, initial;
|
|
502
|
+
return __generator(this, function (_h) {
|
|
385
503
|
if (e.shiftKey && e.code === "Space") {
|
|
386
504
|
e.stopImmediatePropagation();
|
|
387
505
|
e.stopPropagation();
|
|
@@ -442,10 +560,12 @@ export function handleGlobalKeyDown(ctx, cellInput, fxInput, e, cache, handleUnd
|
|
|
442
560
|
}
|
|
443
561
|
if (kstr === "Enter") {
|
|
444
562
|
if (!allowEdit) return [2];
|
|
445
|
-
handleGlobalEnter(ctx, cellInput, e, canvas);
|
|
563
|
+
handleGlobalEnter(ctx, cellInput, e, cache, canvas);
|
|
446
564
|
} else if (kstr === "Tab") {
|
|
447
565
|
if (ctx.luckysheetCellUpdate.length > 0) {
|
|
448
566
|
updateCell(ctx, ctx.luckysheetCellUpdate[0], ctx.luckysheetCellUpdate[1], cellInput, undefined, canvas);
|
|
567
|
+
cache.enteredEditByTyping = false;
|
|
568
|
+
clearTypeOverPending(cache);
|
|
449
569
|
}
|
|
450
570
|
if (e.shiftKey) {
|
|
451
571
|
moveHighlightCell(ctx, "right", -hideCRCount(ctx, "ArrowLeft"), "rangeOfSelect");
|
|
@@ -462,20 +582,34 @@ export function handleGlobalKeyDown(ctx, cellInput, fxInput, e, cache, handleUnd
|
|
|
462
582
|
if (!last) return [2];
|
|
463
583
|
row_index = last.row_focus;
|
|
464
584
|
col_index = last.column_focus;
|
|
585
|
+
if (!_.isNil(row_index) && !_.isNil(col_index)) {
|
|
586
|
+
flowdataF2 = getFlowdata(ctx);
|
|
587
|
+
cellF2 = (_d = flowdataF2 === null || flowdataF2 === void 0 ? void 0 : flowdataF2[row_index]) === null || _d === void 0 ? void 0 : _d[col_index];
|
|
588
|
+
if ((cellF2 === null || cellF2 === void 0 ? void 0 : cellF2.f) != null && String(cellF2.f).trim() !== "") {
|
|
589
|
+
suppressFormulaRangeSelectionForInitialEdit(ctx);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
cache.enteredEditByTyping = false;
|
|
593
|
+
clearTypeOverPending(cache);
|
|
465
594
|
ctx.luckysheetCellUpdate = [row_index, col_index];
|
|
466
595
|
e.preventDefault();
|
|
467
596
|
} else if (kstr === "F4" && ctx.luckysheetCellUpdate.length > 0) {
|
|
468
597
|
e.preventDefault();
|
|
469
598
|
} else if (kstr === "Escape" && ctx.luckysheetCellUpdate.length > 0) {
|
|
599
|
+
cache.enteredEditByTyping = false;
|
|
600
|
+
clearTypeOverPending(cache);
|
|
470
601
|
cancelNormalSelected(ctx);
|
|
471
602
|
moveHighlightCell(ctx, "down", 0, "rangeOfSelect");
|
|
472
603
|
e.preventDefault();
|
|
473
604
|
} else {
|
|
474
605
|
if (e.ctrlKey || e.metaKey) {
|
|
475
|
-
handleWithCtrlOrMetaKey(ctx, cache, e, cellInput, fxInput, handleUndo, handleRedo);
|
|
606
|
+
handleWithCtrlOrMetaKey(ctx, cache, e, cellInput, fxInput, handleUndo, handleRedo, canvas);
|
|
476
607
|
return [2];
|
|
477
608
|
}
|
|
478
609
|
if (e.shiftKey && (kstr === "ArrowUp" || kstr === "ArrowDown" || kstr === "ArrowLeft" || kstr === "ArrowRight")) {
|
|
610
|
+
if (isDirectPlainTextCellEdit(ctx, cache, cellInput, fxInput)) {
|
|
611
|
+
commitDirectPlainCellEdit(ctx, cache, cellInput, canvas);
|
|
612
|
+
}
|
|
479
613
|
handleShiftWithArrowKey(ctx, e);
|
|
480
614
|
} else if (kstr === "Escape") {
|
|
481
615
|
ctx.contextMenu = {};
|
|
@@ -484,21 +618,61 @@ export function handleGlobalKeyDown(ctx, cellInput, fxInput, e, cache, handleUnd
|
|
|
484
618
|
if (ctx.activeImg != null) {
|
|
485
619
|
removeActiveImage(ctx);
|
|
486
620
|
} else {
|
|
621
|
+
if (ctx.formulaCache.rangeSelectionActive === true) {
|
|
622
|
+
markRangeSelectionDirty(ctx);
|
|
623
|
+
}
|
|
487
624
|
deleteSelectedCellText(ctx);
|
|
488
625
|
}
|
|
489
626
|
jfrefreshgrid(ctx, null, undefined);
|
|
490
627
|
e.preventDefault();
|
|
491
628
|
} else if (kstr === "ArrowUp" || kstr === "ArrowDown" || kstr === "ArrowLeft" || kstr === "ArrowRight") {
|
|
492
|
-
|
|
629
|
+
isEditing = ctx.luckysheetCellUpdate.length > 0;
|
|
630
|
+
inlineText = (_e = cellInput === null || cellInput === void 0 ? void 0 : cellInput.innerText) !== null && _e !== void 0 ? _e : "";
|
|
631
|
+
fxText = (_f = fxInput === null || fxInput === void 0 ? void 0 : fxInput.innerText) !== null && _f !== void 0 ? _f : "";
|
|
632
|
+
isFormulaEdit = isEditing && (inlineText.trim().startsWith("=") || fxText.trim().startsWith("="));
|
|
633
|
+
enteredByTyping = cache.enteredEditByTyping === true;
|
|
634
|
+
if (isEditing && !isFormulaEdit && enteredByTyping && !e.shiftKey) {
|
|
635
|
+
updateCell(ctx, ctx.luckysheetCellUpdate[0], ctx.luckysheetCellUpdate[1], cellInput, undefined, canvas);
|
|
636
|
+
cache.enteredEditByTyping = false;
|
|
637
|
+
clearTypeOverPending(cache);
|
|
638
|
+
handleArrowKey(ctx, e);
|
|
639
|
+
e.preventDefault();
|
|
640
|
+
} else {
|
|
641
|
+
handleArrowKey(ctx, e);
|
|
642
|
+
}
|
|
493
643
|
} else 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 || kcode === 0 || e.ctrlKey && kcode === 86) {
|
|
494
644
|
if (!allowEdit) return [2];
|
|
495
645
|
if (String.fromCharCode(kcode) != null && !_.isEmpty(ctx.luckysheet_select_save) && kstr !== "CapsLock" && kstr !== "Win" && kcode !== 18) {
|
|
496
646
|
last = ctx.luckysheet_select_save[ctx.luckysheet_select_save.length - 1];
|
|
497
647
|
row_index = last.row_focus;
|
|
498
648
|
col_index = last.column_focus;
|
|
649
|
+
if (_.isNil(row_index) || _.isNil(col_index)) return [2];
|
|
650
|
+
flowdata = getFlowdata(ctx);
|
|
651
|
+
cellAt = (_g = flowdata === null || flowdata === void 0 ? void 0 : flowdata[row_index]) === null || _g === void 0 ? void 0 : _g[col_index];
|
|
652
|
+
existingFormula = (cellAt === null || cellAt === void 0 ? void 0 : cellAt.f) != null && String(cellAt.f).trim() !== "" ? String(cellAt.f).replace(/[\r\n]/g, "") : null;
|
|
653
|
+
if (existingFormula != null) {
|
|
654
|
+
suppressFormulaRangeSelectionForInitialEdit(ctx);
|
|
655
|
+
}
|
|
499
656
|
ctx.luckysheetCellUpdate = [row_index, col_index];
|
|
500
657
|
cache.overwriteCell = true;
|
|
501
|
-
|
|
658
|
+
cache.pendingTypeOverCell = [row_index, col_index];
|
|
659
|
+
setFormulaEditorOwner(ctx, "cell");
|
|
660
|
+
cache.enteredEditByTyping = true;
|
|
661
|
+
cellInput.focus();
|
|
662
|
+
initial = getTypeOverInitialContent(e);
|
|
663
|
+
if (initial !== undefined) {
|
|
664
|
+
cellInput.textContent = initial;
|
|
665
|
+
if (fxInput) fxInput.textContent = initial;
|
|
666
|
+
handleFormulaInput(ctx, fxInput, cellInput, kcode);
|
|
667
|
+
e.preventDefault();
|
|
668
|
+
} else {
|
|
669
|
+
cellInput.textContent = "";
|
|
670
|
+
if (fxInput) fxInput.textContent = "";
|
|
671
|
+
handleFormulaInput(ctx, fxInput, cellInput, kcode);
|
|
672
|
+
}
|
|
673
|
+
queueMicrotask(function () {
|
|
674
|
+
moveToEnd(cellInput);
|
|
675
|
+
});
|
|
502
676
|
}
|
|
503
677
|
}
|
|
504
678
|
}
|