all files / spreadsheet/actions/ edit.js

69.58% Statements 629/904
57.47% Branches 477/830
88.89% Functions 40/45
69.53% Lines 623/896
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380   122× 122× 122× 122× 122× 122× 122× 122× 122× 122× 122× 122× 122× 122× 122× 122×                                         122× 122×   122×   122× 122× 122×   122× 122× 122× 122× 122× 122× 122× 122× 122× 122× 122× 122× 122×   122× 122×     18525×   3852× 3852×   147× 147×   696× 696×     696×   24× 24× 24×                     24×   11× 10×   11×       1450× 1450× 711×   1450×   101× 101×   713× 713×         707× 707×                                 52× 52× 52× 52× 52× 52×   51× 48× 16× 16× 16× 16×           16×   16×     16×   16× 16×   10×     10×     10×                   10×               32× 28× 28× 28× 28×   28× 28×   28×   28× 28× 28×                       28×                                                     147× 147× 147× 147× 147×   147× 147×     147× 147×   147×   798× 798×       798×   798× 798× 769×   798× 26×   798×         75× 75× 74×   75× 75× 75× 75×             75× 75× 75× 75× 75× 75× 75×     75× 75× 75× 23× 23× 23× 23× 23× 23×   75×                                                                                                                                             10× 10×                                                                                                                                                                                                                                     75× 75× 75× 75×       75×           75× 75× 75×       75×             75× 75× 75× 75× 75× 75× 75×                       75× 75× 75× 75× 75× 75× 75× 75× 25×   75× 75× 54×     21×   75× 47×     28×   75× 73×   75× 75×   75×           77× 77× 77× 77× 77× 77×         77× 77× 77× 77× 77× 77× 77×   77× 77× 77× 77× 77× 77× 77× 77× 77× 77× 77×                             77×   77×     77× 77×       77× 77× 77× 77×   77× 77× 25×   52×       69× 69× 69× 69× 69× 69× 69× 69× 69× 69× 62×   69× 69× 69×           69×   64× 64× 64×     64× 64× 64× 64×           64×       64× 64× 64× 64× 64× 25×   64×   64× 64×   64×     64×                                                       69×   810× 810× 810× 810×                                                                                                                                     101× 101× 101× 101×   75× 75× 39× 39× 39×       39× 39× 39× 39×   39× 39×         103× 103× 103×           103× 103× 103×               103×   69× 69× 69× 69× 69× 69×       69×     69× 69×       69× 69× 66× 66× 66×       69×     69× 68×   69×           75× 75×   220× 220×             220× 156× 156× 156× 156×       220× 186× 122×   186× 67×   186× 186× 64× 25×   64× 64×     34× 26×   220×                 75× 75× 75× 75× 39×   75× 75× 75× 75× 75× 75×             75× 75× 75× 75×                                                                                                                                                                                                                                               1773×                                             1773×          
define(["require", "exports", "@syncfusion/ej2-base", "../../workbook/common/address", "../common/event", "../common/index", "../../workbook/common/event", "../../workbook/base/index", "../../workbook/index", "../common/index", "../../workbook/index", "../common/event", "../common/event"], function (require, exports, ej2_base_1, address_1, event_1, index_1, event_2, index_2, index_3, index_4, index_5, event_3, event_4) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Edit = (function () {
        function Edit(parent) {
            this.editorElem = null;
            this.editCellData = {};
            this.isEdit = false;
            this.isCellEdit = true;
            this.isNewValueEdit = true;
            this.isAltEnter = false;
            this.validCharacters = ['+', '-', '*', '/', ',', '(', '=', '&'];
            this.formulaBarCurStartPos = null;
            this.curEndPos = null;
            this.curStartPos = null;
            this.selectionStart = null;
            this.selectionEnd = null;
            this.uniqueColl = '';
            this.uniqueActCell = '';
            this.isSpill = false;
            this.keyCodes = {
                BACKSPACE: 8,
                SPACE: 32,
                TAB: 9,
                DELETE: 46,
                ESC: 27,
                ENTER: 13,
                FIRSTALPHABET: 65,
                LASTALPHABET: 90,
                FIRSTNUMBER: 48,
                LASTNUMBER: 59,
                FIRSTNUMPAD: 96,
                LASTNUMPAD: 111,
                SYMBOLSETONESTART: 186,
                SYMBOLSETONEEND: 192,
                SYMBOLSETTWOSTART: 219,
                SYMBOLSETTWOEND: 222,
                FIREFOXEQUALPLUS: 61,
                FIREFOXMINUS: 173,
                F2: 113
            };
            this.parent = parent;
            this.addEventListener();
        }
        Edit.prototype.destroy = function () {
            if (this.isEdit) {
                this.cancelEdit(true, false);
            }
            this.removeEventListener();
            this.parent = null;
            this.editorElem = null;
        };
        Edit.prototype.addEventListener = function () {
            ej2_base_1.EventHandler.add(this.parent.element, 'dblclick', this.dblClickHandler, this);
            this.parent.on(event_1.mouseDown, this.mouseDownHandler, this);
            this.parent.on(index_1.keyUp, this.keyUpHandler, this);
            this.parent.on(event_1.keyDown, this.keyDownHandler, this);
            this.parent.on(event_1.editOperation, this.performEditOperation, this);
            this.parent.on(event_3.initiateCur, this.initiateCurPosition, this);
            this.parent.on(event_4.editValue, this.updateFormulaBarValue, this);
            this.parent.on(event_3.addressHandle, this.addressHandler, this);
            this.parent.on(event_4.initiateEdit, this.initiateRefSelection, this);
            this.parent.on(event_4.forRefSelRender, this.refSelectionRender, this);
            this.parent.on(event_2.checkUniqueRange, this.checkUniqueRange, this);
            this.parent.on(event_2.reApplyFormula, this.reApplyFormula, this);
            this.parent.on(event_4.activeSheetChanged, this.sheetChangeHandler, this);
        };
        Edit.prototype.removeEventListener = function () {
            ej2_base_1.EventHandler.remove(this.parent.element, 'dblclick', this.dblClickHandler);
            if (!this.parent.isDestroyed) {
                this.parent.off(event_1.mouseDown, this.mouseDownHandler);
                this.parent.off(index_1.keyUp, this.keyUpHandler);
                this.parent.off(event_1.keyDown, this.keyDownHandler);
                this.parent.off(event_1.editOperation, this.performEditOperation);
                this.parent.off(event_3.initiateCur, this.initiateCurPosition);
                this.parent.off(event_4.editValue, this.updateFormulaBarValue);
                this.parent.off(event_3.addressHandle, this.addressHandler);
                this.parent.off(event_4.initiateEdit, this.initiateRefSelection);
                this.parent.off(event_4.forRefSelRender, this.refSelectionRender);
                this.parent.off(event_2.checkUniqueRange, this.checkUniqueRange);
                this.parent.off(event_2.reApplyFormula, this.reApplyFormula);
                this.parent.off(event_4.activeSheetChanged, this.sheetChangeHandler);
            }
        };
        Edit.prototype.getModuleName = function () {
            return 'edit';
        };
        Edit.prototype.performEditOperation = function (args) {
            var action = args.action;
            switch (action) {
                case 'renderEditor':
                    this.renderEditor();
                    break;
                case 'refreshEditor':
                    this.refreshEditor(args.value, args.refreshFormulaBar, args.refreshEditorElem, args.isAppend, args.trigEvent);
                    Iif (args.refreshCurPos) {
                        this.setCursorPosition();
                    }
                    break;
                case 'startEdit':
                    Eif (!this.isEdit) {
                        this.isNewValueEdit = args.isNewValueEdit;
                        this.startEdit(args.address, args.value, args.refreshCurPos);
                    }
                    else {
                        var isEdit = false;
                        var arg = { isEdit: isEdit };
                        this.parent.notify(event_4.isFormulaBarEdit, arg);
                        if (arg.isEdit) {
                            this.isNewValueEdit = args.isNewValueEdit;
                            this.startEdit(args.address, args.value, args.refreshCurPos);
                        }
                    }
                    break;
                case 'endEdit':
                    if (this.isEdit) {
                        this.endEdit(args.refreshFormulaBar);
                    }
                    break;
                case 'cancelEdit':
                    Eif (this.isEdit) {
                        this.cancelEdit(args.refreshFormulaBar);
                    }
                    break;
                case 'getCurrentEditValue':
                    args.editedValue = this.editCellData.value;
                    if (args.endFormulaRef !== undefined) {
                        args.endFormulaRef = this.endFormulaRef;
                    }
                    break;
                case 'refreshDependentCellValue':
                    this.refreshDependentCellValue(args.rowIdx, args.colIdx, args.sheetIdx);
                    break;
                case 'getElement':
                    args.element = this.getEditElement(this.parent.getActiveSheet());
                    break;
                case 'focusEditorElem':
                    this.editorElem.focus();
                    break;
                case 'getCurrentEditSheetIdx':
                    args.sheetIndex = this.editCellData.sheetIndex;
                    break;
            }
        };
        Edit.prototype.keyUpHandler = function (e) {
            if (this.isEdit) {
                var editElement = this.getEditElement(this.parent.getActiveSheet());
                if (e.altKey && e.keyCode === 13) {
                    editElement.focus();
                    this.altEnter();
                    this.isAltEnter = true;
                }
                else if (this.isCellEdit && this.editCellData.value !== editElement.textContent && e.keyCode !== 16) {
                    this.refreshEditor(editElement.textContent, this.isCellEdit);
                }
                var isFormulaEdit = index_5.checkIsFormula(this.editCellData.value, true);
                if (isFormulaEdit && (!e || e.keyCode !== 16)) {
                    this.updateFormulaReference(editElement);
                    Iif (this.endFormulaRef) {
                        var curOffset = this.getCurPosition();
                        if (curOffset.end && this.validCharacters.indexOf(this.editCellData.value[curOffset.end - 1]) > -1) {
                            this.endFormulaRef = false;
                        }
                    }
                }
            }
        };
        Edit.prototype.updateFormulaReference = function (editElement) {
            var formulaRefIndicator = this.parent.element.querySelector('.e-formularef-indicator');
            if (formulaRefIndicator) {
                formulaRefIndicator.parentElement.removeChild(formulaRefIndicator);
            }
            Iif (this.editCellData.value !== editElement.textContent) {
                this.refreshEditor(editElement.textContent, true);
            }
            var sheetIdx = this.editCellData.sheetIndex;
            var editValue = this.editCellData.value;
            this.parent.notify(event_3.initiateFormulaReference, { range: editValue, formulaSheetIdx: sheetIdx });
        };
        Edit.prototype.keyDownHandler = function (e) {
            var trgtElem = e.target;
            var keyCode = e.keyCode;
            var sheet = this.parent.getActiveSheet();
            var actCell = index_5.getCellIndexes(sheet.activeCell);
            var cell = index_2.getCell(actCell[0], actCell[1], sheet) || {};
            if (!ej2_base_1.closest(e.target, '.e-findtool-dlg') && !ej2_base_1.closest(e.target, '.e-validationerror-dlg')
                && !ej2_base_1.closest(e.target, '.e-hyperlink-dlg')) {
                if (!sheet.isProtected || ej2_base_1.closest(e.target, '.e-sheet-rename') || !index_5.isLocked(cell, index_2.getColumn(sheet, actCell[1]))) {
                    if (this.isEdit) {
                        var editorElem = this.getEditElement(sheet);
                        var isFormulaEdit = index_5.checkIsFormula(this.editCellData.value, true);
                        Eif (this.isCellEdit || (isFormulaEdit && this.editCellData.value !== editorElem.textContent && e.keyCode !== 16)) {
                            Iif (actCell[1] < this.parent.frozenColCount(sheet) && (!sheet.frozenRows || actCell[0] >=
                                this.parent.frozenRowCount(sheet)) && editorElem && editorElem.style.height !== 'auto') {
                                if (index_4.getTextWidth(editorElem.textContent, cell.style, this.parent.cellStyle) > parseInt(editorElem.style.maxWidth, 10)) {
                                    editorElem.style.height = 'auto';
                                }
                            }
                            if (index_4.getTextWidth(editorElem.textContent, cell.style, this.parent.cellStyle) > parseInt(editorElem.style.maxWidth, 10) - 5) {
                                editorElem.style.height = 'auto';
                            }
                            Iif (actCell[0] < this.parent.frozenRowCount(sheet) && editorElem && !editorElem.style.overflow && index_4.getTextWidth(editorElem.textContent, cell.style, this.parent.cellStyle) > parseInt(editorElem.style.maxWidth, 10)) {
                                editorElem.style.overflow = 'auto';
                            }
                            this.refreshEditor(editorElem.textContent, this.isCellEdit, false, false, false);
                        }
                        Eif (!e.altKey) {
                            switch (keyCode) {
                                case this.keyCodes.ENTER:
                                    Iif (ej2_base_1.Browser.isWindows) {
                                        e.preventDefault();
                                    }
                                    if (this.isAltEnter) {
                                        var text = editorElem.textContent;
                                        Eif (text && text.indexOf('\n') > -1) {
                                            index_5.wrap(this.parent.getActiveSheet().selectedRange, true, this.parent);
                                            this.refreshEditor(editorElem.textContent, this.isCellEdit, false, false, false);
                                            this.isAltEnter = false;
                                        }
                                    }
                                    if (!isFormulaEdit) {
                                        this.endEdit(false, e);
                                    }
                                    else {
                                        var formulaRefIndicator = this.parent.element.querySelector('.e-formularef-indicator');
                                        Eif (formulaRefIndicator) {
                                            formulaRefIndicator.parentElement.removeChild(formulaRefIndicator);
                                        }
                                        Eif (this.editCellData.sheetIndex === sheet.id - 1) {
                                            this.endEdit(false, e);
                                        }
                                        else {
                                            this.parent.goTo(this.editCellData.fullAddr);
                                            this.endEdit(false, e);
                                        }
                                    }
                                    break;
                                case this.keyCodes.TAB:
                                    Eif (!this.hasFormulaSuggSelected()) {
                                        this.endEdit(false, e);
                                    }
                                    break;
                                case this.keyCodes.ESC:
                                    this.cancelEdit(true, true, e);
                                    break;
                            }
                        }
                    }
                    else {
                        if (!this.isEdit && (trgtElem.classList.contains('e-spreadsheet') || ej2_base_1.closest(trgtElem, '.e-sheet-panel'))) {
                            var isAlphabet = (keyCode >= this.keyCodes.FIRSTALPHABET && keyCode <= this.keyCodes.LASTALPHABET);
                            var isNumeric = (keyCode >= this.keyCodes.FIRSTNUMBER && keyCode <= this.keyCodes.LASTNUMBER);
                            var isNumpadKeys = (keyCode >= this.keyCodes.FIRSTNUMPAD && keyCode <= this.keyCodes.LASTNUMPAD);
                            var isSymbolkeys = (keyCode >= this.keyCodes.SYMBOLSETONESTART &&
                                keyCode <= this.keyCodes.SYMBOLSETONEEND);
                            Eif (!isSymbolkeys) {
                                isSymbolkeys = (keyCode >= this.keyCodes.SYMBOLSETTWOSTART && keyCode <= this.keyCodes.SYMBOLSETTWOEND);
                            }
                            var isFirefoxExceptionkeys = (keyCode === this.keyCodes.FIREFOXEQUALPLUS) ||
                                (keyCode === this.keyCodes.FIREFOXMINUS);
                            var isF2Edit = (!e.shiftKey && !e.ctrlKey && !e.metaKey && keyCode === this.keyCodes.F2);
                            var isBackSpace = keyCode === this.keyCodes.BACKSPACE;
                            if ((!e.ctrlKey && !e.metaKey && !e.altKey && ((!e.shiftKey && keyCode === this.keyCodes.SPACE) || isAlphabet || isNumeric ||
                                isNumpadKeys || isSymbolkeys || (ej2_base_1.Browser.info.name === 'mozilla' && isFirefoxExceptionkeys))) || isF2Edit || isBackSpace) {
                                Eif (isF2Edit) {
                                    this.isNewValueEdit = false;
                                }
                                var pictureElements = document.getElementsByClassName('e-ss-overlay-active');
                                var pictureLen = pictureElements.length;
                                Iif (pictureLen > 0) {
                                    if (keyCode === this.keyCodes.DELETE) {
                                        this.parent.notify(index_1.deleteImage, {
                                            id: pictureElements[0].id, sheetIdx: this.parent.activeSheetIndex + 1
                                        });
                                    }
                                }
                                else {
                                    this.startEdit(null, null, true, true);
                                }
                            }
                            if (keyCode === this.keyCodes.DELETE) {
                                var islockcell = sheet.isProtected && index_1.isLockedCells(this.parent);
                                if (!islockcell) {
                                    this.editingHandler('delete');
                                    this.parent.notify(event_2.activeCellChanged, null);
                                }
                                else {
                                    this.parent.notify(index_4.editAlert, null);
                                }
                            }
                        }
                    }
                }
                else {
                    Eif (((keyCode >= this.keyCodes.FIRSTALPHABET && keyCode <= this.keyCodes.LASTALPHABET) ||
                        (keyCode >= this.keyCodes.FIRSTNUMBER && keyCode <= this.keyCodes.LASTNUMBER)
                        || (keyCode === this.keyCodes.DELETE) || (keyCode === this.keyCodes.BACKSPACE) || (keyCode === this.keyCodes.SPACE)
                        || (keyCode >= this.keyCodes.FIRSTNUMPAD && keyCode <= this.keyCodes.LASTNUMPAD) ||
                        (keyCode >= this.keyCodes.SYMBOLSETONESTART && keyCode <= this.keyCodes.SYMBOLSETONEEND)
                        || (keyCode >= 219 && keyCode <= 222) || (!e.shiftKey && !e.ctrlKey && !e.metaKey && keyCode === this.keyCodes.F2))
                        && (keyCode !== 67) && (keyCode !== 89) && (keyCode !== 90)) {
                        Iif (sheet.protectSettings.insertLink && keyCode === 75) {
                            return;
                        }
                        Eif (!this.parent.element.querySelector('.e-editAlert-dlg') && !e.ctrlKey && e.keyCode !== 70 &&
                            !trgtElem.parentElement.classList.contains('e-unprotectpwd-content') &&
                            !trgtElem.parentElement.classList.contains('e-password-content') &&
                            !trgtElem.parentElement.classList.contains('e-sheet-password-content') &&
                            !trgtElem.parentElement.classList.contains('e-unprotectsheetpwd-content') &&
                            !trgtElem.parentElement.classList.contains('e-reenterpwd-content')) {
                            this.parent.notify(index_4.editAlert, null);
                        }
                    }
                }
            }
        };
        Edit.prototype.renderEditor = function () {
            Eif (!this.editorElem || !ej2_base_1.select('#' + this.parent.element.id + '_edit', this.parent.element)) {
                var editor = this.parent.createElement('div', { id: this.parent.element.id + '_edit', className: 'e-spreadsheet-edit' });
                editor.contentEditable = 'true';
                editor.spellcheck = false;
                if (this.parent.element.getElementsByClassName('e-spreadsheet-edit')[0]) {
                    this.parent.element.getElementsByClassName('e-spreadsheet-edit')[0].remove();
                }
                var sheetContentElem = this.parent.element.querySelector('.e-sheet-content');
                Iif (!sheetContentElem) {
                    return;
                }
                sheetContentElem.appendChild(editor);
                this.editorElem = editor;
            }
            this.parent.notify(index_1.formulaOperation, { action: 'renderAutoComplete' });
        };
        Edit.prototype.refreshEditor = function (value, refreshFormulaBar, refreshEditorElem, isAppend, trigEvent) {
            if (trigEvent === void 0) { trigEvent = true; }
            Iif (isAppend) {
                value = this.editCellData.value = this.editCellData.value + value;
            }
            else {
                this.editCellData.value = value;
            }
            var editorElem = this.getEditElement(this.parent.getActiveSheet());
            if (refreshEditorElem && editorElem) {
                editorElem.textContent = value;
            }
            if (refreshFormulaBar) {
                this.parent.notify(index_1.formulaBarOperation, { action: 'refreshFormulabar', value: value });
            }
            if (this.parent.isEdit && editorElem && trigEvent && this.editCellData.value === editorElem.textContent) {
                Iif (this.triggerEvent('cellEditing').cancel) {
                    this.cancelEdit();
                }
            }
        };
        Edit.prototype.startEdit = function (address, value, refreshCurPos, preventFormulaReference) {
            if (refreshCurPos === void 0) { refreshCurPos = true; }
            if (this.parent.showSheetTabs) {
                this.parent.element.querySelector('.e-add-sheet-tab').setAttribute('disabled', 'true');
            }
            var sheet = this.parent.getActiveSheet();
            var range = index_5.getCellIndexes(sheet.activeCell);
            var cell = index_2.getCell(range[0], range[1], sheet, false, true);
            if (index_4.hasTemplate(this.parent, range[0], range[1], this.parent.activeSheetIndex)) {
                var cellEle = this.parent.getCell(range[0], range[1]);
                var isDelTemplate = false;
                var value_1 = cellEle.innerHTML;
                Eif (cellEle) {
                    Iif (value_1.indexOf('<') > -1 && value_1.indexOf('>') > -1 && value_1.indexOf('input') > -1) {
                        isDelTemplate = true;
                    }
                }
                Iif (isDelTemplate) {
                    return;
                }
            }
            this.updateEditCellDetail(address, value);
            this.initiateEditor(refreshCurPos);
            this.positionEditor();
            this.parent.isEdit = this.isEdit = true;
            this.parent.notify(event_1.clearCopy, null);
            this.parent.notify(event_1.enableToolbarItems, [{ enable: false }]);
            if (cell.formula && !preventFormulaReference) {
                this.parent.notify(event_3.initiateFormulaReference, { range: cell.formula, formulaSheetIdx: this.editCellData.sheetIndex });
            }
        };
        Edit.prototype.setCursorPosition = function () {
            var elem = this.getEditElement(this.parent.getActiveSheet());
            var textLen = elem.textContent.length;
            if (textLen) {
                var selection = document.getSelection();
                var range = document.createRange();
                range.setStart(elem.firstChild, textLen);
                range.collapse(true);
                selection.removeAllRanges();
                selection.addRange(range);
            }
            elem.focus();
        };
        Edit.prototype.hasFormulaSuggSelected = function () {
            var suggDdlElem = document.getElementById(this.parent.element.id + '_ac_popup');
            return suggDdlElem && suggDdlElem.style.visibility === 'visible' &&
                suggDdlElem.querySelectorAll('.e-item-focus').length > 0;
        };
        Edit.prototype.editingHandler = function (action) {
            var pictureElements = document.getElementsByClassName('e-ss-overlay-active');
            var pictureLen = pictureElements.length;
            var isSpill;
            switch (action) {
                case 'delete':
                    Iif (pictureLen > 0) {
                        if (pictureElements[0].classList.contains('e-datavisualization-chart')) {
                            this.parent.notify(event_4.deleteChart, {
                                id: pictureElements[0].id, sheetIdx: this.parent.activeSheetIndex + 1
                            });
                        }
                        else {
                            this.parent.notify(index_1.deleteImage, {
                                id: pictureElements[0].id, sheetIdx: this.parent.activeSheetIndex + 1
                            });
                        }
                    }
                    else {
                        var sheet = this.parent.getActiveSheet();
                        var address = sheet.selectedRange;
                        var range = address_1.getIndexesFromAddress(address);
                        range = range[0] > range[2] ? index_5.getSwapRange(range) : range;
                        address = address_1.getRangeAddress(range);
                        var cellDeleteArgs = { address: sheet.name + '!' + address };
                        this.parent.notify(event_4.beginAction, { action: 'cellDelete', eventArgs: cellDeleteArgs });
                        address = address_1.getRangeFromAddress(cellDeleteArgs.address);
                        range = address_1.getRangeIndexes(address);
                        index_3.clearRange(this.parent, range, this.parent.activeSheetIndex, true);
                        this.parent.serviceLocator.getService('cell').refreshRange(range);
                        this.parent.notify(index_3.selectionComplete, {});
                        var args = { cellIdx: range, isUnique: false };
                        this.checkUniqueRange(args);
                        Iif (args.isUnique) {
                            var indexes = address_1.getRangeIndexes(this.uniqueColl);
                            var cell = index_2.getCell(indexes[0], indexes[1], this.parent.getActiveSheet());
                            if (cell) {
                                isSpill = cell.value.indexOf('#SPILL!') > -1;
                            }
                        }
                        Iif (args.isUnique && this.uniqueColl.split(':')[0] === address.split(':')[0]) {
                            var index = address_1.getRangeIndexes(this.uniqueColl);
                            for (var i = index[0]; i <= index[2]; i++) {
                                for (var j = index[1]; j <= index[3]; j++) {
                                    this.parent.updateCell({ value: '', formula: '' }, address_1.getRangeAddress([i, j]));
                                }
                            }
                            this.parent.notify(event_2.removeUniquecol, null);
                            this.uniqueColl = '';
                        }
                        else Iif (args.isUnique) {
                            var uniqueRange = address_1.getRangeIndexes(this.uniqueColl);
                            if (index_2.getCell(uniqueRange[0], uniqueRange[1], sheet).value === '#SPILL!') {
                                var skip = false;
                                for (var j = uniqueRange[0]; j <= uniqueRange[2]; j++) {
                                    for (var k = uniqueRange[1]; k <= uniqueRange[3]; k++) {
                                        var cell = index_2.getCell(j, k, sheet);
                                        if (j === uniqueRange[0] && k === uniqueRange[1]) {
                                            skip = false;
                                        }
                                        else if (!ej2_base_1.isNullOrUndefined(cell.value) && cell.value !== '') {
                                            skip = true;
                                        }
                                    }
                                }
                                if (!skip) {
                                    this.reApplyFormula();
                                }
                            }
                        }
                        Iif (args.isUnique) {
                            this.parent.notify(event_1.completeAction, { action: 'cellDelete',
                                eventArgs: { address: sheet.name + '!' + address, isSpill: isSpill } });
                        }
                        else {
                            this.parent.notify(event_1.completeAction, { action: 'cellDelete', eventArgs: { address: sheet.name + '!' + address } });
                        }
                    }
                    break;
            }
        };
        Edit.prototype.getCurPosition = function () {
            var cursorOffset = {};
            var selection = window.getSelection();
            if (this.editorElem.textContent === this.editCellData.value) {
                cursorOffset.start = selection.anchorOffset;
                cursorOffset.end = selection.focusOffset;
                Iif (cursorOffset.start > cursorOffset.end) {
                    var x = cursorOffset.start;
                    cursorOffset.start = cursorOffset.end;
                    cursorOffset.end = x;
                }
            }
            Iif (selection && selection.focusNode && selection.focusNode.classList &&
                selection.focusNode.classList.contains('e-formula-bar-panel') &&
                this.editorElem.textContent === this.editCellData.value) {
                var formulaBar = selection.focusNode.getElementsByClassName('e-formula-bar e-css')[0];
                cursorOffset.start = formulaBar.selectionStart;
                cursorOffset.end = formulaBar.selectionEnd;
            }
            return cursorOffset;
        };
        Edit.prototype.mouseDownHandler = function (e) {
            Eif (!ej2_base_1.closest(e.target, '.e-findtool-dlg')) {
                if (this.isEdit) {
                    var curOffset = this.getCurPosition();
                    Iif (curOffset.start) {
                        this.curStartPos = this.selectionStart = curOffset.start;
                    }
                    Iif (curOffset.end) {
                        this.curEndPos = this.selectionEnd = curOffset.end;
                    }
                    var trgtElem = e.target;
                    var sheet = this.parent.getActiveSheet();
                    var formulaRefIndicator = this.parent.element.querySelector('.e-formularef-indicator');
                    this.isCellEdit = trgtElem.classList.contains('e-spreadsheet-edit');
                    var isFormula = index_5.checkIsFormula(this.editCellData.value, true);
                    var editorElem = this.getEditElement(sheet);
                    if (trgtElem.classList.contains('e-cell') || trgtElem.classList.contains('e-header-cell') ||
                        trgtElem.classList.contains('e-selectall') || ej2_base_1.closest(trgtElem, '.e-toolbar-item.e-active') || ej2_base_1.closest(trgtElem, '.e-table')) {
                        if (this.isAltEnter) {
                            var editText = editorElem.textContent;
                            Eif (editText && editText.indexOf('\n') > -1) {
                                this.isAltEnter = false;
                                index_5.wrap(this.parent.getActiveSheet().selectedRange, true, this.parent);
                                this.refreshEditor(editorElem.textContent, this.isCellEdit);
                            }
                        }
                        if (!isFormula || this.endFormulaRef) {
                            this.endFormulaRef = false;
                            this.endEdit(false, e);
                        }
                        else {
                            var curPos = this.selectionEnd;
                            var actCellIdx = index_5.getCellIndexes(sheet.activeCell);
                            var cell = index_2.getCell(actCellIdx[0], actCellIdx[1], sheet);
                            Iif (this.selectionStart !== this.selectionEnd && this.editCellData.value === editorElem.textContent &&
                                this.validCharacters.indexOf(editorElem.textContent.substring((this.selectionStart - 1), this.selectionStart)) !== -1) {
                                if (index_5.isCellReference(editorElem.textContent.substring(this.selectionStart, this.selectionEnd)) &&
                                    editorElem.textContent.indexOf(':') !== this.selectionEnd) {
                                    this.editCellData.value = editorElem.textContent.substring(0, this.selectionStart) +
                                        editorElem.textContent.substring(this.selectionEnd, editorElem.textContent.length);
                                }
                            }
                            Iif (this.editCellData.value === editorElem.textContent && (editorElem.textContent.indexOf('(') !==
                                editorElem.textContent.length - 1 && editorElem.textContent.indexOf('(') !== -1) &&
                                this.selectionStart === this.selectionEnd) {
                                if (this.editCellData.sheetIndex !== sheet.id - 1) {
                                    var elem = this.parent.element.querySelector('.e-formula-bar');
                                    if (editorElem.textContent.substring(elem.selectionEnd - 1, elem.selectionEnd) !== ',' &&
                                        !e.shiftKey) {
                                        if (formulaRefIndicator) {
                                            formulaRefIndicator.parentElement.removeChild(formulaRefIndicator);
                                        }
                                        this.parent.goTo(this.editCellData.fullAddr);
                                        this.endEdit(false, e);
                                        return;
                                    }
                                }
                                else {
                                    if (this.validCharacters.indexOf(editorElem.textContent.substring(curPos - 1, curPos)) === -1) {
                                        if (formulaRefIndicator) {
                                            formulaRefIndicator.parentElement.removeChild(formulaRefIndicator);
                                        }
                                        this.endEdit(false, e);
                                        return;
                                    }
                                }
                            }
                            if (!cell) {
                                return;
                            }
                            isFormula = cell.formula ?
                                index_5.checkIsFormula(index_2.getCell(actCellIdx[0], actCellIdx[1], sheet).formula) ||
                                    (this.editCellData.value && this.editCellData.value.toString().indexOf('=') === 0) : false;
                            Iif (isFormula && this.parent.isEdit) {
                                var curPos_1 = this.selectionEnd;
                                if (this.editCellData.value.length === curPos_1) {
                                    if (this.editCellData.value.substring(this.editCellData.value.length - 1) === ')' ||
                                        index_5.isNumber(this.editCellData.value.substring(this.editCellData.value.length - 1))) {
                                        if (formulaRefIndicator) {
                                            formulaRefIndicator.parentElement.removeChild(formulaRefIndicator);
                                        }
                                        this.endEdit(false, e);
                                    }
                                }
                                else if (this.editCellData.value === editorElem.textContent) {
                                    if (this.validCharacters.indexOf((this.editCellData.value +
                                        sheet.selectedRange).substring(curPos_1 - 1, curPos_1)) === -1) {
                                        if (formulaRefIndicator) {
                                            formulaRefIndicator.parentElement.removeChild(formulaRefIndicator);
                                        }
                                        this.endEdit(false, e);
                                    }
                                    else if (this.validCharacters.indexOf(editorElem.textContent.substring(curPos_1 - 1, curPos_1)) === -1 ||
                                        (editorElem.textContent.substring(curPos_1, curPos_1 + 1) !== ')' &&
                                            this.validCharacters.indexOf(editorElem.textContent.substring(curPos_1, curPos_1 + 1)) === -1)) {
                                        if (formulaRefIndicator) {
                                            formulaRefIndicator.parentElement.removeChild(formulaRefIndicator);
                                        }
                                        this.endEdit(false, e);
                                    }
                                }
                            }
                        }
                    }
                    else {
                        Iif (isFormula && this.editCellData.value === editorElem.textContent && editorElem.textContent.indexOf('(') !==
                            editorElem.textContent.length - 1 && !this.isCellEdit &&
                            this.validCharacters.indexOf(this.editCellData.value.substring(this.selectionStart - 1, this.selectionStart)) === -1) {
                            if (this.editCellData.sheetIndex === sheet.id - 1) {
                                var curPos = window.getSelection().focusOffset;
                                if (this.validCharacters.indexOf(editorElem.textContent.substring(curPos - 1, curPos)) === -1) {
                                    if (formulaRefIndicator) {
                                        formulaRefIndicator.parentElement.removeChild(formulaRefIndicator);
                                    }
                                    this.parent.goTo(this.editCellData.fullAddr);
                                    this.endEdit(false, e);
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        };
        Edit.prototype.dblClickHandler = function (e) {
            var trgtElem = e.target;
            var sheet = this.parent.getActiveSheet();
            var actCell = index_5.getCellIndexes(sheet.activeCell);
            var cell = index_2.getCell(actCell[0], actCell[1], sheet) || {};
            Iif (ej2_base_1.closest(trgtElem, '.e-datavisualization-chart')) {
                return;
            }
            if (!sheet.isProtected || !index_5.isLocked(cell, index_2.getColumn(sheet, actCell[1]))) {
                Eif ((trgtElem.className.indexOf('e-ss-overlay') < 0) &&
                    (trgtElem.classList.contains('e-active-cell') || trgtElem.classList.contains('e-cell')
                        || ej2_base_1.closest(trgtElem, '.e-sheet-content') || trgtElem.classList.contains('e-table'))) {
                    if (this.isEdit) {
                        Iif (index_5.checkIsFormula(this.editCellData.value)) {
                            var sheetName = this.editCellData.fullAddr.substring(0, this.editCellData.fullAddr.indexOf('!'));
                            if (this.parent.getActiveSheet().name === sheetName) {
                                this.endEdit();
                            }
                        }
                        else {
                            Iif (trgtElem.className.indexOf('e-spreadsheet-edit') < 0) {
                                this.endEdit();
                            }
                        }
                    }
                    else {
                        this.isNewValueEdit = false;
                        this.startEdit();
                    }
                }
            }
            else {
                Eif (trgtElem.classList.contains('e-active-cell') || trgtElem.classList.contains('e-cell')) {
                    this.parent.notify(index_4.editAlert, null);
                }
            }
        };
        Edit.prototype.updateEditCellDetail = function (addr, value) {
            var sheetIdx;
            var sheet;
            Eif (ej2_base_1.isNullOrUndefined(this.editCellData.sheetIndex)) {
                Iif (addr && addr.split('!').length > 1) {
                    sheetIdx = index_2.getSheetIndex(this.parent, index_3.getSheetNameFromAddress(addr));
                }
                else {
                    sheetIdx = this.parent.activeSheetIndex;
                }
            }
            else {
                sheetIdx = this.editCellData.sheetIndex;
            }
            Eif (!this.editCellData.addr) {
                sheet = index_3.getSheet(this.parent, sheetIdx);
                Iif (addr) {
                    addr = address_1.getRangeFromAddress(addr);
                }
                else {
                    addr = sheet.activeCell;
                }
            }
            else if (index_5.checkIsFormula(this.editCellData.value, true)) {
                sheet = index_3.getSheet(this.parent, sheetIdx);
                this.isNewValueEdit = false;
            }
            Eif (addr) {
                var range = address_1.getRangeIndexes(addr);
                var rowIdx = range[0];
                var colIdx = range[1];
                var cellElem = this.parent.getCell(rowIdx, colIdx);
                var cellPosition = index_1.getCellPosition(sheet, range, this.parent.frozenRowCount(sheet), this.parent.frozenColCount(sheet), this.parent.viewport.beforeFreezeHeight, this.parent.viewport.beforeFreezeWidth, this.parent.sheetModule.colGroupWidth);
                this.editCellData = {
                    addr: addr,
                    fullAddr: index_2.getSheetName(this.parent, sheetIdx) + '!' + addr,
                    rowIndex: rowIdx,
                    colIndex: colIdx,
                    sheetIndex: sheetIdx,
                    element: cellElem,
                    value: value || '',
                    position: cellPosition
                };
            }
        };
        Edit.prototype.initiateEditor = function (refreshCurPos) {
            var _this = this;
            var data = this.parent.getData(this.editCellData.fullAddr);
            data.then(function (values) {
                values.forEach(function (cell) {
                    var args = { cell: cell, value: cell ? cell.value : '' };
                    _this.parent.notify(event_2.getFormattedBarText, args);
                    var value = cell ? args.value : '';
                    if (cell && cell.formula) {
                        value = cell.formula;
                    }
                    _this.editCellData.oldValue = value;
                    if (_this.editCellData.value) {
                        value = _this.editCellData.value;
                    }
                    else {
                        _this.editCellData.value = value;
                    }
                    if (_this.isNewValueEdit) {
                        value = '';
                    }
                    else {
                        _this.isNewValueEdit = true;
                    }
                    if (!ej2_base_1.isUndefined(value)) {
                        _this.refreshEditor(value, false, true, false, false);
                    }
                    Eif (refreshCurPos) {
                        _this.setCursorPosition();
                    }
                    Iif (_this.triggerEvent('cellEdit').cancel) {
                        _this.cancelEdit(true, false);
                    }
                });
            });
        };
        Edit.prototype.positionEditor = function (isWrap) {
            var tdElem = this.editCellData.element;
            var isEdit = false;
            var cellEle;
            var arg = { isEdit: isEdit };
            this.parent.notify(event_4.isFormulaBarEdit, arg);
            Iif (arg.isEdit && ej2_base_1.isNullOrUndefined(tdElem)) {
                cellEle = this.parent.getCell(this.editCellData.rowIndex, this.editCellData.colIndex);
                tdElem = cellEle;
                this.editCellData.element = cellEle;
            }
            Eif (tdElem) {
                tdElem.classList.add('e-ss-edited');
                var sheet = this.parent.getActiveSheet();
                var cell = index_2.getCell(this.editCellData.rowIndex, this.editCellData.colIndex, sheet, false, true);
                var left = this.editCellData.position.left + 1;
                var top_1 = this.editCellData.position.top + 1;
                var args = { range: [this.editCellData.rowIndex, this.editCellData.colIndex, this.editCellData.rowIndex,
                        this.editCellData.colIndex] };
                this.parent.notify(event_2.activeCellMergedRange, args);
                var minHeight = index_2.getRowsHeight(sheet, args.range[0], args.range[2]) - 3;
                var minWidth = index_2.getColumnsWidth(sheet, args.range[1], args.range[3]) - 3;
                var mainContElement = this.parent.element.getElementsByClassName('e-main-panel')[0];
                var editWidth = void 0;
                var frozenCol = this.parent.frozenColCount(sheet);
                var zIndex = void 0;
                var preventWrap = void 0;
                var frozenRow = this.parent.frozenRowCount(sheet);
                var addWrap = void 0;
                Iif (this.editCellData.colIndex < frozenCol) {
                    editWidth = Math.abs(this.parent.getRowHeaderContent().getBoundingClientRect()[this.parent.enableRtl ? 'left' : 'right'] -
                        tdElem.getBoundingClientRect()[this.parent.enableRtl ? 'right' : 'left']) - 1;
                    if (this.editCellData.rowIndex < frozenRow) {
                        if (this.parent.getRowHeaderContent().style.zIndex === '2') {
                            zIndex = '3';
                        }
                    }
                    else {
                        if (index_4.getTextWidth(cell.value, cell.style, this.parent.cellStyle) > editWidth) {
                            addWrap = true;
                        }
                    }
                }
                else {
                    editWidth = (mainContElement.offsetWidth - left - 28) - this.parent.sheetModule.getRowHeaderWidth(sheet);
                }
                Iif (this.editCellData.rowIndex < frozenRow) {
                    preventWrap = true;
                }
                var height = !preventWrap && ((cell && cell.wrap) || (tdElem && isWrap) || addWrap) ? 'auto;' : minHeight + 'px;';
                var inlineStyles = 'display:block;top:' + top_1 + 'px;' + (this.parent.enableRtl ? 'right:' : 'left:') + left + 'px;' +
                    'min-width:' + minWidth + 'px;max-width:' + (cell && cell.wrap ? minWidth : editWidth) + 'px;' +
                    'height:' + height + (cell && cell.wrap ? ('width:' + minWidth + 'px;') : '') + 'min-height:' + minHeight + 'px;' +
                    (zIndex ? 'z-index: ' + zIndex + ';' : '') + (preventWrap && ((cell && !cell.wrap) || (tdElem && isWrap)) && (index_4.getTextWidth(cell.value, cell.style, this.parent.cellStyle) > editWidth || (tdElem && isWrap)) ? 'overflow: auto;' : '');
                inlineStyles += tdElem.style.cssText;
                var editorElem = this.getEditElement(sheet, true);
                editorElem.setAttribute('style', inlineStyles);
                if (index_4.getTextWidth(editorElem.textContent, cell.style, this.parent.cellStyle) > editWidth) {
                    editorElem.style.height = 'auto';
                }
                this.parent.element.querySelector('.e-active-cell').style.height = (minHeight + 4) + 'px';
                if (tdElem.classList.contains('e-right-align')) {
                    editorElem.classList.add('e-right-align');
                }
                else if (tdElem.classList.contains('e-center-align')) {
                    editorElem.classList.add('e-center-align');
                }
            }
        };
        Edit.prototype.updateEditedValue = function (tdRefresh, value) {
            Iif (tdRefresh === void 0) { tdRefresh = true; }
            var oldCellValue = this.editCellData.oldValue;
            var oldValue = oldCellValue ? oldCellValue.toString().toUpperCase() : '';
            var isValidate = true;
            var address = this.editCellData.addr;
            var cellIndex = address_1.getRangeIndexes(this.parent.getActiveSheet().activeCell);
            var sheet = this.parent.getActiveSheet();
            var cell = index_2.getCell(cellIndex[0], cellIndex[1], sheet);
            var column = index_2.getColumn(sheet, cellIndex[1]);
            if (value) {
                this.editCellData.value = value;
            }
            var newVal = this.editCellData.value;
            this.parent.notify(index_1.setActionData, { args: { action: 'beforeCellSave', eventArgs: { address: this.editCellData.addr } } });
            if (this.parent.allowDataValidation && ((cell && cell.validation) || (column && column.validation))) {
                var value_2 = newVal ? newVal : this.getEditElement(sheet).innerText;
                var isCell = true;
                var sheetIdx = this.parent.activeSheetIndex;
                var range = void 0;
                Eif (typeof address === 'string') {
                    range = address_1.getRangeIndexes(address);
                }
                else {
                    range = address;
                }
                this.parent.notify(event_2.isValidation, { value: value_2, range: range, sheetIdx: sheetIdx, isCell: isCell });
                isValidate = this.parent.allowDataValidation;
                this.editCellData.value = isValidate ? value_2 : this.editCellData.value;
                this.parent.allowDataValidation = true;
            }
            if ((oldCellValue !== this.editCellData.value || oldValue.indexOf('=RAND()') > -1 || oldValue.indexOf('RAND()') > -1 ||
                oldValue.indexOf('=RANDBETWEEN(') > -1 || oldValue.indexOf('RANDBETWEEN(') > -1) && isValidate) {
                var sheet_1 = this.parent.getActiveSheet();
                var cellIndex_1 = address_1.getRangeIndexes(sheet_1.activeCell);
                Iif (oldCellValue && oldCellValue.toString().indexOf('=UNIQUE(') > -1 && this.editCellData.value === '') {
                    this.parent.notify(event_2.removeUniquecol, null);
                }
                var args = { cellIdx: cellIndex_1, isUnique: false };
                this.checkUniqueRange(args);
                var isUniqueRange = args.isUnique;
                Iif (isUniqueRange && oldCellValue !== '' && this.editCellData.value === '') {
                    var rangeIdx = address_1.getRangeIndexes(this.uniqueColl);
                    if (index_2.getCell(rangeIdx[0], rangeIdx[1], sheet_1).value.indexOf('#SPILL!') === -1) {
                        return isValidate;
                    }
                }
                Iif (oldCellValue && oldCellValue.toString().indexOf('UNIQUE') > -1 &&
                    this.editCellData.value && this.editCellData.value.toString().indexOf('UNIQUE') > -1 && isUniqueRange) {
                    this.updateUniqueRange('');
                }
                this.parent.notify(event_2.workbookEditOperation, { action: 'updateCellValue', address: this.editCellData.addr, value: this.editCellData.value });
                var cell_1 = index_2.getCell(cellIndex_1[0], cellIndex_1[1], sheet_1, true);
                var eventArgs = this.getRefreshNodeArgs(cell_1);
                this.editCellData.value = eventArgs.value;
                if (cell_1 && cell_1.formula) {
                    this.editCellData.formula = cell_1.formula;
                }
                if (cell_1 && cell_1.wrap) {
                    this.parent.notify(event_2.wrapEvent, { range: cellIndex_1, wrap: true, sheet: sheet_1 });
                }
                Eif (tdRefresh) {
                    this.parent.refreshNode(this.editCellData.element, eventArgs);
                }
                Iif (cell_1 && cell_1.hyperlink) {
                    this.parent.serviceLocator.getService('cell').refreshRange(cellIndex_1);
                }
                Iif (isUniqueRange) {
                    var rangeIdx = address_1.getRangeIndexes(this.uniqueColl);
                    if (index_2.getCell(rangeIdx[0], rangeIdx[1], sheet_1).value.indexOf('#SPILL!') > -1) {
                        this.isSpill = true;
                    }
                    if ((oldCellValue !== '' && this.editCellData.value === '') ||
                        (this.editCellData.formula && this.editCellData.formula.length > 1 && oldCellValue !== this.editCellData.formula)) {
                        var skip = false;
                        for (var j = rangeIdx[0]; j <= rangeIdx[2]; j++) {
                            for (var k = rangeIdx[1]; k <= rangeIdx[3]; k++) {
                                var cell_2 = index_2.getCell(j, k, sheet_1);
                                if (j === rangeIdx[0] && k === rangeIdx[1]) {
                                    skip = false;
                                }
                                else if (cell_2 && !ej2_base_1.isNullOrUndefined(cell_2.value) && cell_2.value !== '') {
                                    skip = true;
                                }
                            }
                        }
                        if (!skip) {
                            this.reApplyFormula();
                        }
                    }
                    else {
                        this.updateUniqueRange(newVal);
                    }
                }
            }
            return isValidate;
        };
        Edit.prototype.checkUniqueRange = function (uniquArgs) {
            var args = { range: [] };
            this.parent.notify(event_2.getUniqueRange, args);
            var collection = args.range;
            for (var i = 0; i < collection.length; i++) {
                if (collection[i].split('!')[0] === this.parent.getActiveSheet().name) {
                    var rangeIdx = address_1.getRangeIndexes(collection[i]);
                    for (var j = rangeIdx[0]; j <= rangeIdx[2]; j++) {
                        for (var k = rangeIdx[1]; k <= rangeIdx[3]; k++) {
                            if (uniquArgs.cellIdx[0] === j && uniquArgs.cellIdx[1] === k) {
                                uniquArgs.isUnique = true;
                                this.uniqueCell = true;
                                var uniqueIndex = this.uniqueColl !== '' ? address_1.getRangeIndexes(this.uniqueColl) : [0, 0, 0, 0];
                                var collectionIndex = address_1.getRangeIndexes(collection[i]);
                                if (uniqueIndex[0] === collectionIndex[0] && uniqueIndex[1] === collectionIndex[1]) {
                                    var index = [uniqueIndex[0], collectionIndex[1], uniqueIndex[0], collectionIndex[1]];
                                    index[2] = uniqueIndex[2] > collectionIndex[2] ? uniqueIndex[2] : collectionIndex[2];
                                    index[3] = uniqueIndex[3] > collectionIndex[3] ? uniqueIndex[3] : collectionIndex[3];
                                    this.uniqueColl = address_1.getRangeAddress(index);
                                    uniquArgs.uniqueRange = address_1.getRangeAddress(index);
                                }
                                else {
                                    this.uniqueColl = collection[i];
                                    uniquArgs.uniqueRange = collection[i];
                                }
                            }
                        }
                    }
                }
            }
        };
        Edit.prototype.updateUniqueRange = function (value) {
            var rangeIdx = address_1.getRangeIndexes(this.uniqueColl);
            var skip = false;
            if (index_2.getCell(rangeIdx[0], rangeIdx[1], this.parent.getActiveSheet()).value !== '#SPILL!') {
                skip = true;
            }
            for (var j = rangeIdx[0]; j <= rangeIdx[2]; j++) {
                for (var k = rangeIdx[1]; k <= rangeIdx[3]; k++) {
                    if (skip) {
                        if (j === rangeIdx[0] && k === rangeIdx[1]) {
                            this.parent.updateCell({ value: '#SPILL!' }, address_1.getRangeAddress([j, k]));
                        }
                        else {
                            if (address_1.getRangeAddress([j, k]).split(':')[0] === this.editCellData.addr) {
                                this.parent.updateCell({ value: value }, address_1.getRangeAddress([j, k]));
                            }
                            else {
                                this.parent.updateCell({ value: '' }, address_1.getRangeAddress([j, k]));
                            }
                        }
                    }
                }
            }
        };
        Edit.prototype.reApplyFormula = function () {
            var cellIdx = address_1.getRangeIndexes(this.uniqueColl);
            var cell = index_2.getCell(cellIdx[0], cellIdx[1], this.parent.getActiveSheet());
            this.parent.updateCell({ value: '' }, address_1.getRangeAddress([cellIdx[0], cellIdx[1]]));
            var sheets = this.parent.sheets;
            var formula = cell.formula;
            for (var i = 0; i < sheets.length; i++) {
                if (formula.indexOf(sheets[i].name) > -1) {
                    formula = formula.replace(sheets[i].name, '!' + i);
                }
            }
            this.parent.computeExpression(formula);
            this.uniqueCell = false;
            if (this.uniqueActCell !== '') {
                this.editCellData.value = this.uniqueActCell;
                this.uniqueActCell = '';
            }
        };
        Edit.prototype.refreshDependentCellValue = function (rowIdx, colIdx, sheetIdx) {
            Eif (rowIdx && colIdx) {
                rowIdx--;
                colIdx--;
                if (((this.editCellData.rowIndex !== rowIdx || this.editCellData.colIndex !== colIdx)
                    && this.parent.activeSheetIndex === sheetIdx) || (this.uniqueCell && this.parent.activeSheetIndex === sheetIdx)) {
                    var td = this.parent.getCell(rowIdx, colIdx);
                    if (td) {
                        Eif (td.parentElement) {
                            var curRowIdx = td.parentElement.getAttribute('aria-rowindex');
                            Iif (curRowIdx && Number(curRowIdx) - 1 !== rowIdx) {
                                return;
                            }
                        }
                        var sheet = index_3.getSheet(this.parent, sheetIdx);
                        var cell = index_2.getCell(rowIdx, colIdx, sheet);
                        var actCell = address_1.getRangeIndexes(sheet.activeCell);
                        if (actCell[0] === rowIdx && actCell[1] === colIdx) {
                            this.uniqueActCell = cell.value;
                        }
                        var eventArgs = this.getRefreshNodeArgs(cell, rowIdx, colIdx);
                        this.parent.refreshNode(td, eventArgs);
                    }
                }
            }
        };
        Edit.prototype.getRefreshNodeArgs = function (cell, rowIdx, colIdx) {
            cell = cell ? cell : {};
            var fCode = (cell && cell.format) ? cell.format : '';
            var eventArgs = {
                value: cell.value, format: fCode, onLoad: true,
                formattedText: '', isRightAlign: false, type: 'General', cell: cell,
                rowIndex: rowIdx === undefined ? this.editCellData.rowIndex : rowIdx,
                colIndex: colIdx === undefined ? this.editCellData.colIndex : colIdx, isRowFill: false
            };
            this.parent.notify(event_2.getFormattedCellObject, eventArgs);
            eventArgs.formattedText = this.parent.allowNumberFormatting ? eventArgs.formattedText : eventArgs.value;
            var args = {
                isRightAlign: eventArgs.isRightAlign,
                result: eventArgs.formattedText,
                type: eventArgs.type,
                value: eventArgs.value,
                curSymbol: eventArgs.curSymbol,
                isRowFill: eventArgs.isRowFill
            };
            return args;
        };
        Edit.prototype.endEdit = function (refreshFormulaBar, event) {
            if (refreshFormulaBar === void 0) { refreshFormulaBar = false; }
            var sheet = this.parent.getActiveSheet();
            var actCell = index_5.getCellIndexes(sheet.activeCell);
            var cell = this.parent.getCell(actCell[0], actCell[1]);
            var fSize = '';
            Iif (this.editCellData.element && this.editCellData.element.children[0] &&
                this.editCellData.element.children[0].className === 'e-cf-databar') {
                fSize = cell.children[0].querySelector('.e-databar-value').style.fontSize;
            }
            Iif (refreshFormulaBar) {
                this.refreshEditor(this.editCellData.oldValue, false, true, false, false);
            }
            var triggerEventArgs = this.triggerEvent('beforeCellSave');
            Iif (triggerEventArgs.cancel) {
                event.preventDefault();
                return;
            }
            var isValidate = this.updateEditedValue(true, triggerEventArgs.value);
            if (isValidate) {
                this.triggerEvent('cellSave', event, triggerEventArgs.value);
                this.resetEditState();
                this.focusElement();
            }
            else Iif (event) {
                event.preventDefault();
            }
            Iif (fSize !== '') {
                cell.children[0].querySelector('.e-databar-value').style.fontSize = fSize;
            }
            if (this.parent.showSheetTabs && !this.parent.isProtected) {
                this.parent.element.querySelector('.e-add-sheet-tab').removeAttribute('disabled');
            }
            Iif (this.parent.isValidationHighlighted && index_2.getCell(actCell[0], actCell[1], sheet).validation) {
                this.parent.addInvalidHighlight();
            }
        };
        Edit.prototype.cancelEdit = function (refreshFormulaBar, trigEvent, event) {
            if (refreshFormulaBar === void 0) { refreshFormulaBar = true; }
            if (trigEvent === void 0) { trigEvent = true; }
            this.refreshEditor(this.editCellData.oldValue, refreshFormulaBar, false, false, false);
            if (trigEvent) {
                this.triggerEvent('cellSave', event);
            }
            this.resetEditState();
            this.focusElement();
        };
        Edit.prototype.focusElement = function () {
            index_1.focus(this.parent.element);
            this.parent.notify(event_1.enableToolbarItems, [{ enable: true }]);
        };
        Edit.prototype.triggerEvent = function (eventName, event, value) {
            var cell = index_2.getCell(this.editCellData.rowIndex, this.editCellData.colIndex, this.parent.getActiveSheet());
            var eventArgs = {
                element: this.editCellData.element,
                value: value ? value : this.editCellData.value,
                oldValue: this.editCellData.oldValue,
                address: this.editCellData.fullAddr,
                displayText: this.parent.getDisplayText(cell)
            };
            if (eventArgs.address) {
                var indexes = address_1.getRangeIndexes(eventArgs.address);
                var args = { cellIdx: indexes, isUnique: false };
                this.checkUniqueRange(args);
                Iif (args.isUnique) {
                    eventArgs.isSpill = this.isSpill;
                }
            }
            if (eventArgs.value !== eventArgs.oldValue) {
                if (eventName !== 'cellSave') {
                    eventArgs.cancel = false;
                }
                if (eventName === 'beforeCellSave') {
                    this.parent.notify(event_4.beginAction, { eventArgs: eventArgs, action: 'cellSave', preventAction: true });
                }
                this.parent.trigger(eventName, eventArgs);
                if (eventName === 'cellSave') {
                    if (this.editCellData.formula) {
                        eventArgs.formula = this.editCellData.formula;
                    }
                    eventArgs.originalEvent = event;
                    this.parent.notify(event_1.completeAction, { eventArgs: eventArgs, action: 'cellSave' });
                }
            }
            else if (eventName !== 'cellSave' && eventName !== 'beforeCellSave') {
                this.parent.trigger(eventName, eventArgs);
            }
            return { value: eventArgs.value, oldValue: null, element: null, address: null, cancel: eventArgs.cancel };
        };
        Edit.prototype.altEnter = function () {
            this.positionEditor(true);
            var selection = window.getSelection();
            var node = selection.anchorNode;
            var offset;
            var range = document.createRange();
            offset = (node.nodeType === 3) ? selection.anchorOffset : node.textContent.length;
            Iif (offset === 0 && node.textContent.length > 0) {
                offset = node.textContent.length;
            }
            var text = node.textContent;
            var textBefore = text.slice(0, offset);
            var textAfter = text.slice(offset) || ' ';
            node.textContent = textBefore + '\n' + textAfter;
            range = document.createRange();
            Iif (node.nodeType === 3) {
                range.setStart(node, offset + 1);
                range.setEnd(node, offset + 1);
            }
            else Eif (node.nodeType === 1) {
                range.setStart(node.firstChild, offset + 1);
                range.setEnd(node.firstChild, offset + 1);
            }
            selection.removeAllRanges();
            selection.addRange(range);
        };
        Edit.prototype.resetEditState = function (elemRefresh) {
            Eif (elemRefresh === void 0) { elemRefresh = true; }
            Eif (elemRefresh) {
                var editorElem = this.getEditElement(this.parent.getActiveSheet());
                if (index_5.checkIsFormula(editorElem.textContent) || editorElem.textContent === '') {
                    this.parent.notify(event_3.clearCellRef, null);
                }
                Eif (this.editCellData.element) {
                    this.editCellData.element.classList.remove('e-ss-edited');
                    this.editorElem.textContent = '';
                    Eif (editorElem === this.editorElem) {
                        this.editorElem.removeAttribute('style');
                        this.editorElem.classList.remove('e-right-align');
                    }
                    else {
                        ej2_base_1.detach(editorElem);
                    }
                }
            }
            this.editCellData = {};
            this.parent.isEdit = this.isEdit = false;
            this.isCellEdit = true;
            this.parent.notify(index_1.formulaOperation, { action: 'endEdit' });
        };
        Edit.prototype.refSelectionRender = function () {
            var editorElem = this.getEditElement(this.parent.getActiveSheet());
            if (editorElem) {
                if (index_5.checkIsFormula(editorElem.textContent)) {
                    this.parent.notify(event_3.initiateFormulaReference, {
                        range: editorElem.textContent, formulaSheetIdx: this.editCellData.sheetIndex
                    });
                }
            }
        };
        Edit.prototype.initiateRefSelection = function () {
            var sheetName = this.editCellData.fullAddr.substring(0, this.editCellData.fullAddr.indexOf('!'));
            var value = this.parent.element.querySelector('.e-formula-bar').value;
            if (this.parent.getActiveSheet().name === sheetName && index_5.checkIsFormula(this.editCellData.value, true)) {
                this.startEdit(this.editCellData.addr, value, false);
                this.parent.notify(event_3.initiateFormulaReference, {
                    range: this.editCellData.value, formulaSheetIdx: this.editCellData.sheetIndex
                });
                this.getEditElement(this.parent.getActiveSheet()).innerHTML = value;
                this.initiateCurPosition();
            }
            else {
                this.initiateCurPosition();
            }
        };
        Edit.prototype.addressHandler = function (args) {
            var selection = window.getSelection();
            this.selectionStart = selection.anchorOffset;
            this.selectionEnd = selection.focusOffset;
            Iif (this.selectionStart > this.selectionEnd) {
                var x = this.selectionStart;
                this.selectionStart = this.selectionEnd;
                this.selectionEnd = x;
            }
            Iif ((selection && selection.focusNode && selection.focusNode.classList &&
                selection.focusNode.classList.contains('e-formula-bar-panel'))) {
                var formulaBar = selection.focusNode.getElementsByClassName('e-formula-bar e-css')[0];
                this.selectionStart = formulaBar.selectionStart;
                this.selectionEnd = formulaBar.selectionEnd;
            }
            var eventArgs = { action: 'getCurrentEditValue', editedValue: '' };
            this.parent.notify(event_1.editOperation, eventArgs);
            var address = args.range;
            var sheetName = this.editCellData.fullAddr.substring(0, this.editCellData.fullAddr.indexOf('!'));
            var sheetIdx = this.editCellData.sheetIndex;
            var editorEle = this.getEditElement(this.parent.getActiveSheet());
            Iif (this.parent.getActiveSheet().name !== sheetName) {
                address = '\'' + this.parent.getActiveSheet().name + '\'' + '!' + address;
            }
            if (args.isSelect) {
                this.parent.notify(event_3.initiateFormulaReference, { range: eventArgs.editedValue + address, formulaSheetIdx: sheetIdx });
            }
            else {
                var sheetName_1 = this.editCellData.fullAddr.substring(0, this.editCellData.fullAddr.indexOf('!'));
                Eif (this.parent.getActiveSheet().name === sheetName_1) {
                    var editedValue = eventArgs.editedValue;
                    Iif (this.selectionStart !== this.selectionEnd) {
                        this.formulaBarCurStartPos = this.selectionStart;
                        this.curStartPos = this.selectionStart;
                        this.curEndPos = this.selectionStart + address.length;
                        editorEle.textContent = editedValue.substring(0, this.selectionStart)
                            + address + editedValue.substring(this.selectionStart);
                    }
                    else Iif (editedValue.indexOf(')') === editedValue.length - 1 && this.selectionEnd === editedValue.length) {
                        editorEle.textContent = editedValue.substring(0, editedValue.length - 1)
                            + address + editedValue.substring(editedValue.length - 1);
                        this.curEndPos = editorEle.textContent.length - 1;
                    }
                    else Eif (editedValue.indexOf(')') !== editedValue.length - 1) {
                        editorEle.textContent = editedValue + address;
                        this.curEndPos = editorEle.textContent.length;
                    }
                    else if (editorEle.textContent !== editedValue) {
                        editorEle.textContent = editedValue.substring(0, this.curStartPos)
                            + address + editedValue.substring(this.curStartPos);
                        this.curEndPos = this.curStartPos + address.length;
                    }
                    else if (this.selectionStart === this.selectionEnd &&
                        this.validCharacters.indexOf(editedValue.substring(this.selectionStart - 1, this.selectionEnd)) !== -1 &&
                        (this.validCharacters.indexOf(editedValue.substring(this.selectionStart, this.selectionEnd + 1)) !== -1 ||
                            editedValue.substring(this.selectionStart, this.selectionEnd + 1) === ')')) {
                        editorEle.textContent = editedValue.substring(0, this.selectionStart)
                            + address + editedValue.substring(this.selectionEnd);
                        this.curStartPos = this.selectionStart;
                        this.curEndPos = this.selectionStart + address.length;
                        this.formulaBarCurStartPos = this.curStartPos;
                    }
                }
            }
        };
        Edit.prototype.updateFormulaBarValue = function () {
            var selection = window.getSelection();
            var value = this.editCellData.value;
            var address = this.parent.getActiveSheet().selectedRange;
            address = address_1.isSingleCell(address_1.getIndexesFromAddress(address)) ? address.split(':')[0] : address;
            var formulaBar = this.parent.element.querySelector('.e-formula-bar');
            Eif (value && index_5.checkIsFormula(value, true)) {
                var sheetName = this.editCellData.fullAddr.substring(0, this.editCellData.fullAddr.indexOf('!'));
                Iif (this.parent.getActiveSheet().name !== sheetName) {
                    address = '\'' + this.parent.getActiveSheet().name + '\'' + '!' + address;
                }
                Iif (!ej2_base_1.isNullOrUndefined(this.formulaBarCurStartPos)) {
                    formulaBar.value = value.substring(0, this.formulaBarCurStartPos)
                        + address + value.substring(this.formulaBarCurStartPos);
                }
                else Iif (value.indexOf(')') === value.length - 1 && selection.focusOffset === value.length) {
                    formulaBar.value = value.substring(0, value.length - 1) + address + value.substring(value.length - 1);
                }
                else Eif (value.indexOf(')') !== value.length - 1) {
                    formulaBar.value = value + address;
                }
                else if (formulaBar.value !== value) {
                    formulaBar.value = value.substring(0, this.curStartPos)
                        + address + value.substring(this.curStartPos);
                }
                this.curEndPos = this.curStartPos + address.length;
            }
        };
        Edit.prototype.setFormulaBarCurPosition = function (input, selectionStart, selectionEnd) {
            if (input.setSelectionRange) {
                input.focus();
                input.selectionStart = selectionStart;
                input.selectionEnd = selectionStart;
                input.setSelectionRange(selectionStart, selectionEnd);
            }
        };
        Edit.prototype.initiateCurPosition = function (args) {
            Iif (args === void 0) { args = { isCellEdit: false }; }
            var el = this.getEditElement(this.parent.getActiveSheet(), true);
            Iif (args.isCellEdit) {
                var curOffset = this.getCurPosition();
                if (!this.endFormulaRef && curOffset.start === curOffset.end) {
                    this.updateFormulaReference(el);
                    if (curOffset.end && this.validCharacters.indexOf(this.editCellData.value[curOffset.end - 1]) === -1) {
                        this.endFormulaRef = true;
                    }
                }
                return;
            }
            var value = el.innerText;
            var selection = window.getSelection();
            Iif ((selection && selection.focusNode && selection.focusNode.classList &&
                selection.focusNode.classList.contains('e-formula-bar-panel'))) {
                var formulaBar = this.parent.element.querySelector('.e-formula-bar');
                this.setFormulaBarCurPosition(formulaBar, this.curEndPos, this.curEndPos);
                return;
            }
            Eif (value) {
                var range = document.createRange();
                Iif (value.indexOf(')') === value.length - 1) {
                    range.setStart(el.childNodes[0], this.curEndPos);
                    range.setEnd(el.childNodes[0], this.curEndPos);
                }
                else {
                    range.setStart(el.childNodes[0], this.curEndPos);
                    range.setEnd(el.childNodes[0], this.curEndPos);
                }
                selection.removeAllRanges();
                selection.addRange(range);
            }
            var sheetIdx = this.editCellData.sheetIndex;
            Iif (sheetIdx !== this.parent.getActiveSheet().id - 1) {
                var elem = this.parent.element.querySelector('.e-formula-bar');
                if (elem.value) {
                    var valueLength = elem.value.length;
                    if (elem.value.indexOf(')') === valueLength - 1) {
                        this.setFormulaBarCurPosition(elem, valueLength - 1, valueLength - 1);
                    }
                    else {
                        this.setFormulaBarCurPosition(elem, valueLength, valueLength);
                    }
                }
            }
        };
        Edit.prototype.getEditElement = function (sheet, isEdit) {
            Iif ((this.isEdit || isEdit) && (sheet.frozenRows || sheet.frozenColumns)) {
                var frozenRow = this.parent.frozenRowCount(sheet);
                var frozenCol = this.parent.frozenColCount(sheet);
                var range = index_5.getCellIndexes(sheet.activeCell);
                var content = void 0;
                if (range[0] < frozenRow && range[1] < frozenCol) {
                    content = this.parent.getSelectAllContent();
                }
                else if (range[0] < frozenRow) {
                    content = this.parent.getColumnHeaderContent();
                }
                else if (range[1] < frozenCol) {
                    content = this.parent.getRowHeaderContent();
                }
                else {
                    return this.editorElem;
                }
                var editEle = content.getElementsByClassName('e-spreadsheet-edit')[0];
                if (!editEle && isEdit) {
                    editEle = content.appendChild(this.editorElem.cloneNode());
                }
                return editEle;
            }
            return this.editorElem;
        };
        Edit.prototype.sheetChangeHandler = function () {
            this.editCellData && (this.editCellData.value = null);
        };
        return Edit;
    }());
    exports.Edit = Edit;
});