all files / spreadsheet/actions/ keyboard-shortcut.js

67.96% Statements 70/103
60.22% Branches 56/93
100% Functions 9/9
67.96% Lines 70/103
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   121× 121×   121×   121×     12× 12×       52× 12× 12×     12×       12×     12×         12×   11×                                     11×           11×           11×       12× 12× 12× 12× 12× 12× 12×   12×   12× 11×       11×       11×   10×           11×                   52×     18525×   121× 121×        
define(["require", "exports", "../common/index", "../common/index", "../../workbook/common/index", "../../workbook/index", "../../workbook/base/cell", "@syncfusion/ej2-base"], function (require, exports, index_1, index_2, index_3, index_4, cell_1, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var KeyboardShortcut = (function () {
        function KeyboardShortcut(parent) {
            this.parent = parent;
            this.addEventListener();
        }
        KeyboardShortcut.prototype.addEventListener = function () {
            this.parent.on(index_1.keyDown, this.keyDownHandler, this);
        };
        KeyboardShortcut.prototype.removeEventListener = function () {
            if (!this.parent.isDestroyed) {
                this.parent.off(index_1.keyDown, this.keyDownHandler);
            }
        };
        KeyboardShortcut.prototype.isTrgtNotInput = function (e) {
            var trgt = e.target;
            return (!ej2_base_1.closest(trgt, '.e-filter-popup')
                && !ej2_base_1.closest(trgt, '.e-find-dlg') && !ej2_base_1.closest(trgt, '.e-hyperlink-dlg') &&
                !ej2_base_1.closest(trgt, '.e-sheet-tab') && !ej2_base_1.closest(trgt, '.e-name-box') && !ej2_base_1.closest(trgt, '.e-link-dialog'));
        };
        KeyboardShortcut.prototype.keyDownHandler = function (e) {
            if ((e.ctrlKey || e.metaKey) && this.isTrgtNotInput(e)) {
                Eif (!ej2_base_1.closest(e.target, '.e-find-dlg')) {
                    Iif ([79, 83].indexOf(e.keyCode) > -1) {
                        e.preventDefault();
                    }
                    else Iif (e.keyCode === 65 && !this.parent.isEdit) {
                        e.preventDefault();
                    }
                }
                Iif (e.keyCode === 79) {
                    ej2_base_1.select('#' + this.parent.element.id + '_fileUpload', this.parent.element).click();
                }
                else Iif (e.keyCode === 83) {
                    if (this.parent.saveUrl && this.parent.allowSave) {
                        this.parent.notify(index_4.exportDialog, null);
                    }
                }
                else if (e.keyCode === 67) {
                    this.parent.notify(index_1.copy, { promise: Promise });
                }
                else Iif (e.keyCode === 75) {
                    var sheet = this.parent.getActiveSheet();
                    var indexes = index_3.getCellIndexes(sheet.activeCell);
                    var row = this.parent.sheets[this.parent.getActiveSheet().id - 1].rows[indexes[0]];
                    var cell = void 0;
                    e.preventDefault();
                    if (!ej2_base_1.isNullOrUndefined(row)) {
                        cell = row.cells[indexes[1]];
                    }
                    if (ej2_base_1.isNullOrUndefined(cell)) {
                        cell_1.setCell(indexes[0], indexes[1], this.parent.getActiveSheet(), cell, false);
                    }
                    if (cell && cell.hyperlink) {
                        this.parent.notify(index_1.editHyperlink, null);
                    }
                    else {
                        this.parent.notify(index_1.initiateHyperlink, null);
                    }
                }
                else Iif (e.keyCode === 90) {
                    if (!this.parent.isEdit) {
                        e.preventDefault();
                        this.parent.notify(index_1.performUndoRedo, { isUndo: true });
                    }
                }
                else Iif (e.keyCode === 89) {
                    if (!this.parent.isEdit) {
                        e.preventDefault();
                        this.parent.notify(index_1.performUndoRedo, { isUndo: false });
                    }
                }
                else Iif (e.keyCode === 82 || e.keyCode === 68) {
                    e.preventDefault();
                    this.parent.notify(index_1.fillRange, { verticalFill: e.keyCode === 68 });
                }
                var actSheet = this.parent.sheets[this.parent.getActiveSheet().id - 1];
                var isLocked = void 0;
                Eif (actSheet) {
                    var actCell = actSheet.activeCell;
                    var actCellIndex = index_3.getCellIndexes(actCell);
                    var cellObj = cell_1.getCell(actCellIndex[0], actCellIndex[1], actSheet);
                    isLocked = actSheet.isProtected && index_4.isLocked(cellObj, index_4.getColumn(actSheet, actCellIndex[1]));
                }
                if (e.keyCode === 70) {
                    e.preventDefault();
                    this.parent.notify(index_3.ribbonFind, null);
                }
                if ((!isLocked || !actSheet.isProtected || e.keyCode === 86) && e.keyCode !== 70) {
                    Iif (e.keyCode === 71) {
                        e.preventDefault();
                        this.parent.notify(index_2.gotoDlg, null);
                    }
                    else Iif (e.keyCode === 72) {
                        e.preventDefault();
                        this.parent.notify(index_2.findDlg, null);
                    }
                    else if (e.keyCode === 88) {
                        this.parent.notify(index_1.cut, { promise: Promise });
                    }
                    else if (e.keyCode === 86) {
                        this.parent.notify(index_1.paste, { isAction: true });
                    }
                    else if (e.keyCode === 66) {
                        e.preventDefault();
                        var value = this.parent.getCellStyleValue(['fontWeight'], index_3.getCellIndexes(this.parent.getActiveSheet().activeCell)).fontWeight;
                        value = value === 'bold' ? 'normal' : 'bold';
                        this.parent.notify(index_3.setCellFormat, { style: { fontWeight: value }, onActionUpdate: true, refreshRibbon: true });
                    }
                    else if (e.keyCode === 73) {
                        e.preventDefault();
                        var value = this.parent.getCellStyleValue(['fontStyle'], index_3.getCellIndexes(this.parent.getActiveSheet().activeCell)).fontStyle;
                        value = value === 'italic' ? 'normal' : 'italic';
                        this.parent.notify(index_3.setCellFormat, { style: { fontStyle: value }, onActionUpdate: true, refreshRibbon: true });
                    }
                    else if (e.keyCode === 85) {
                        e.preventDefault();
                        this.parent.notify(index_3.textDecorationUpdate, { style: { textDecoration: 'underline' }, refreshRibbon: true });
                    }
                    else if (e.keyCode === 53) {
                        e.preventDefault();
                        this.parent.notify(index_3.textDecorationUpdate, { style: { textDecoration: 'line-through' }, refreshRibbon: true });
                    }
                    Iif (e.shiftKey) {
                        if (e.keyCode === 76) {
                            if (!this.parent.isEdit) {
                                e.preventDefault();
                                this.parent.notify(index_2.initiateFilterUI, {});
                            }
                        }
                    }
                }
            }
            if (e.keyCode === 27) {
                this.parent.notify(index_1.clearCopy, null);
            }
        };
        KeyboardShortcut.prototype.getModuleName = function () {
            return 'keyboardShortcut';
        };
        KeyboardShortcut.prototype.destroy = function () {
            this.removeEventListener();
            this.parent = null;
        };
        return KeyboardShortcut;
    }());
    exports.KeyboardShortcut = KeyboardShortcut;
});