diff --git a/cell/apiDefines.js b/cell/apiDefines.js index 28c00a5e65..91a7b74db0 100644 --- a/cell/apiDefines.js +++ b/cell/apiDefines.js @@ -1020,6 +1020,23 @@ var c_oAscPopUpSelectorType = { window['Asc']['c_oAscSpreadsheetShortcutType'] = window['Asc'].c_oAscSpreadsheetShortcutType = c_oAscSpreadsheetShortcutType; prot = c_oAscSpreadsheetShortcutType; + prot["RefreshAllPivots"] = prot.RefreshAllPivots; + prot["RefreshSelectedPivots"] = prot.RefreshSelectedPivots; + prot["EditSelectAll"] = prot.EditSelectAll; + prot["RecalculateAll"] = prot.RecalculateAll; + prot["RecalculateActiveSheet"] = prot.RecalculateActiveSheet; + prot["CellInsertDate"] = prot.CellInsertDate; + prot["CellInsertTime"] = prot.CellInsertTime; + prot["CellInsertSumFunction"] = prot.CellInsertSumFunction; + prot["NextWorksheet"] = prot.NextWorksheet; + prot["PreviousWorksheet"] = prot.PreviousWorksheet; + prot["Strikeout"] = prot.Strikeout; + prot["Italic"] = prot.Italic; + prot["Bold"] = prot.Bold; + prot["Underline"] = prot.Underline; + prot["EditUndo"] = prot.EditUndo; + prot["EditRedo"] = prot.EditRedo; + prot["SpeechWorker"] = prot.SpeechWorker; diff --git a/cell/view/CellEditorView.js b/cell/view/CellEditorView.js index 7cdaca19b2..e2a068b4ef 100644 --- a/cell/view/CellEditorView.js +++ b/cell/view/CellEditorView.js @@ -2416,17 +2416,15 @@ * * @param event {KeyboardEvent} * @param isInput {boolean} - * @returns {boolean} + * @returns {number} */ CellEditor.prototype._onWindowKeyDown = function (event, isInput) { - var t = this, kind = undefined, hieroglyph = false; - var ctrlKey = !AscCommon.getAltGr(event) && (event.metaKey || event.ctrlKey); - const bIsMacOs = AscCommon.AscBrowser.isMacOs; - const bIsWordRemove = bIsMacOs ? event.altKey : ctrlKey; - let nRetValue = keydownresult_PreventKeyPress; + let t = this, kind = undefined, hieroglyph = false; + let nRetValue = keydownresult_PreventNothing; + let api = window["Asc"]["editor"]; if (this.handlers.trigger('getWizard') || !t.isOpened || (!isInput && !t.enableKeyEvents && event.emulated !== true)) { - return true; + return nRetValue; } // для исправления Bug 15902 - Alt забирает фокус из приложения @@ -2434,56 +2432,74 @@ t.lastKeyCode = event.which; } - t._setSkipKeyPress(true); - t.skipTLUpdate = false; + t._setSkipKeyPress(false); + t.skipTLUpdate = true; // определение ввода иероглифов if (t.isTopLineActive && AscCommonExcel.getFragmentsLength(t.options.fragments) !== t.input.value.length) { hieroglyph = true; } + nRetValue = keydownresult_PreventKeyPress; AscCommon.check_KeyboardEvent(event); const oEvent = AscCommon.global_keyboardEvent; const nShortcutAction = t.view.Api.getShortcut(oEvent); + switch (nShortcutAction) { case Asc.c_oAscSpreadsheetShortcutType.Strikeout: - if (hieroglyph) { - t._syncEditors(); - } - t.setTextStyle("s", null); + { + if (hieroglyph) + { + t._syncEditors(); + } + t.setTextStyle("s", null); nRetValue = keydownresult_PreventAll; break; + } case Asc.c_oAscSpreadsheetShortcutType.Bold: - if (hieroglyph) { - t._syncEditors(); - } - t.setTextStyle("b", null); + { + if (hieroglyph) + { + t._syncEditors(); + } + t.setTextStyle("b", null); nRetValue = keydownresult_PreventAll; break; + } case Asc.c_oAscSpreadsheetShortcutType.Italic: - if (hieroglyph) { + { + if (hieroglyph) + { t._syncEditors(); } t.setTextStyle("i", null); nRetValue = keydownresult_PreventAll; break; + } case Asc.c_oAscSpreadsheetShortcutType.Underline: - if (hieroglyph) { + { + if (hieroglyph) + { t._syncEditors(); } t.setTextStyle("u", null); nRetValue = keydownresult_PreventAll; break; + } case Asc.c_oAscSpreadsheetShortcutType.EditSelectAll: - if (!t.hasFocus) { - t.setFocus(true); - } - if (!t.isTopLineActive) { - nRetValue = keydownresult_PreventAll; - } - t._moveCursor(kBeginOfText); - t._selectChars(kEndOfText); + { + if (!t.hasFocus) + { + t.setFocus(true); + } + if (!t.isTopLineActive) + { + nRetValue = keydownresult_PreventAll; + } + t._moveCursor(kBeginOfText); + t._selectChars(kEndOfText); break; + } case Asc.c_oAscSpreadsheetShortcutType.EditUndo: { t.undo(); @@ -2491,268 +2507,277 @@ break; } case Asc.c_oAscSpreadsheetShortcutType.EditRedo: + { t.redo(); nRetValue = keydownresult_PreventAll; break; + } case Asc.c_oAscSpreadsheetShortcutType.CellInsertTime: - var oDate = new Asc.cDate(); + { + const oDate = new Asc.cDate(); t._addChars(oDate.getTimeString(api)); nRetValue = keydownresult_PreventAll; break; + } case Asc.c_oAscSpreadsheetShortcutType.CellInsertDate: - var oDate = new Asc.cDate(); + { + const oDate = new Asc.cDate(); t._addChars(oDate.getDateString(api)); nRetValue = keydownresult_PreventAll; break; - default: + } + default: { + const oCustom = t.view.Api.getCustomShortcutAction(nShortcutAction); + if (oCustom) { + if (AscCommon.c_oAscCustomShortcutType.Symbol === oCustom.Type) { + api["asc_insertSymbol"](oCustom.Font, oCustom.CharCode); + } + } break; + } } - let api = window["Asc"]["editor"]; - switch (event.which) { - - case 27: // "esc" - if (t.handlers.trigger("isGlobalLockEditCell") || this.getMenuEditorMode()) { - return false; + if (!nShortcutAction) + { + const bIsMacOs = AscCommon.AscBrowser.isMacOs; + const bIsWordRemove = bIsMacOs ? oEvent.IsAlt() : oEvent.CtrlKey; + switch (oEvent.GetKeyCode()) { + case 27: // "esc" + { + if (t.handlers.trigger("isGlobalLockEditCell") || this.getMenuEditorMode()) { + break; + } + t.close(); + nRetValue = keydownresult_PreventAll; + break; } - t.close(); - event.stopPropagation(); - event.preventDefault(); - return false; - case 13: // "enter" - if (window['IS_NATIVE_EDITOR']) { - t._addNewLine(); - } else { - if (!(event.altKey && event.shiftKey)) { - if (event.altKey) { - t._addNewLine(); - } else if(this.getMenuEditorMode()) { - t._addNewLine(); - } else { - if (false === t.handlers.trigger("isGlobalLockEditCell")) { - if (t.textFlags) { - t.textFlags.ctrlKey = event.ctrlKey; - t.textFlags.shiftKey = event.shiftKey; + case 13: { // "enter" + if (window['IS_NATIVE_EDITOR']) { + t._addNewLine(); + } + else { + if (!(oEvent.IsAlt() && oEvent.IsShift())) { + if (oEvent.IsAlt()) { + t._addNewLine(); + } + else if (this.getMenuEditorMode()) { + t._addNewLine(); + } + else { + if (false === t.handlers.trigger("isGlobalLockEditCell")) { + if (t.textFlags) { + t.textFlags.ctrlKey = event.ctrlKey; + t.textFlags.shiftKey = oEvent.IsShift(); + } + t._tryCloseEditor(event); } - t._tryCloseEditor(event); } } } - } - event.stopPropagation(); - event.preventDefault(); - return false; - - case 9: // tab - if (hieroglyph) { - t._syncEditors(); - } - - if (false === t.handlers.trigger("isGlobalLockEditCell")) { - t._tryCloseEditor(event); - } - return false; - - case 8: // "backspace" - if (!this.enableKeyEvents) { + nRetValue = keydownresult_PreventAll; break; } - - if (!window['IS_NATIVE_EDITOR']) { - // Отключим стандартную обработку браузера нажатия backspace - event.stopPropagation(); - event.preventDefault(); + case 9: { // tab if (hieroglyph) { t._syncEditors(); } - } - t._removeChars(bIsWordRemove ? kPrevWord : kPrevChar); - return false; - case 35: // "end" - if (!this.enableKeyEvents) { + if (false === t.handlers.trigger("isGlobalLockEditCell")) { + t._tryCloseEditor(event); + } break; } + case 8: { // "backspace" + if (!this.enableKeyEvents) { + break; + } - // Отключим стандартную обработку браузера нажатия end - event.stopPropagation(); - event.preventDefault(); - if (!t.hasFocus) { + if (!window['IS_NATIVE_EDITOR']) { + // Отключим стандартную обработку браузера нажатия backspace + nRetValue = keydownresult_PreventAll; + if (hieroglyph) { + t._syncEditors(); + } + } + t._removeChars(bIsWordRemove ? kPrevWord : kPrevChar); break; } - if (hieroglyph) { - t._syncEditors(); - } - kind = ctrlKey ? kEndOfText : kEndOfLine; - event.shiftKey ? t._selectChars(kind) : t._moveCursor(kind); - return false; + case 35: { // "end" + if (!this.enableKeyEvents) { + break; + } - case 36: // "home" - if (!this.enableKeyEvents) { + // Отключим стандартную обработку браузера нажатия end + nRetValue = keydownresult_PreventAll; + if (!t.hasFocus) { + break; + } + if (hieroglyph) { + t._syncEditors(); + } + kind = oEvent.CtrlKey ? kEndOfText : kEndOfLine; + oEvent.IsShift() ? t._selectChars(kind) : t._moveCursor(kind); break; } + case 36: { // "home" + if (!this.enableKeyEvents) { + break; + } - // Отключим стандартную обработку браузера нажатия home - event.stopPropagation(); - event.preventDefault(); - if (!t.hasFocus) { + // Отключим стандартную обработку браузера нажатия home + nRetValue = keydownresult_PreventAll; + if (!t.hasFocus) { + break; + } + if (hieroglyph) { + t._syncEditors(); + } + kind = oEvent.CtrlKey ? kBeginOfText : kBeginOfLine; + oEvent.IsShift() ? t._selectChars(kind) : t._moveCursor(kind); break; } - if (hieroglyph) { - t._syncEditors(); - } - kind = ctrlKey ? kBeginOfText : kBeginOfLine; - event.shiftKey ? t._selectChars(kind) : t._moveCursor(kind); - return false; + case 37: { // "left" + if (!this.enableKeyEvents) { + this._delayedUpdateCursorByTopLine(); + break; + } + + nRetValue = keydownresult_PreventAll; + if (!t.hasFocus) { + break; + } + if (hieroglyph) { + t._syncEditors(); + } + if (bIsMacOs && oEvent.CtrlKey) { + oEvent.IsShift() ? t._selectChars(kBeginOfLine) : t._moveCursor(kBeginOfLine); + } + else { + const bWord = bIsMacOs ? oEvent.IsAlt() : oEvent.CtrlKey; + kind = bWord ? kPrevWord : kPrevChar; + oEvent.IsShift() ? t._selectChars(kind) : t._moveCursor(kind); + } - case 37: // "left" - if (!this.enableKeyEvents) { - this._delayedUpdateCursorByTopLine(); break; } + case 38: {// "up" + if (!this.enableKeyEvents) { + this._delayedUpdateCursorByTopLine(); + break; + } - event.stopPropagation(); - event.preventDefault(); - if (!t.hasFocus) { + nRetValue = keydownresult_PreventAll; + if (!t.hasFocus) { + break; + } + if (hieroglyph) { + t._syncEditors(); + } + oEvent.IsShift() ? t._selectChars(kPrevLine) : t._moveCursor(kPrevLine); break; } - if (hieroglyph) { - t._syncEditors(); - } - if (bIsMacOs && ctrlKey) - { - event.shiftKey ? t._selectChars(kBeginOfLine) : t._moveCursor(kBeginOfLine); - } - else - { - const bWord = bIsMacOs ? event.altKey : ctrlKey; - kind = bWord ? kPrevWord : kPrevChar; - event.shiftKey ? t._selectChars(kind) : t._moveCursor(kind); - } - return false; + case 39: {// "right" + if (!this.enableKeyEvents) { + this._delayedUpdateCursorByTopLine(); + break; + } - case 38: // "up" - if (!this.enableKeyEvents) { - this._delayedUpdateCursorByTopLine(); + nRetValue = keydownresult_PreventAll; + if (!t.hasFocus) { + break; + } + if (hieroglyph) { + t._syncEditors(); + } + if (bIsMacOs && oEvent.CtrlKey) { + oEvent.IsShift() ? t._selectChars(kEndOfLine) : t._moveCursor(kEndOfLine); + } + else { + const bWord = bIsMacOs ? oEvent.IsAlt() : oEvent.CtrlKey; + kind = bWord ? kNextWord : kNextChar; + oEvent.IsShift() ? t._selectChars(kind) : t._moveCursor(kind); + } break; } + case 40: { // "down" + if (!this.enableKeyEvents) { + this._delayedUpdateCursorByTopLine(); + break; + } - event.stopPropagation(); - event.preventDefault(); - if (!t.hasFocus) { + nRetValue = keydownresult_PreventAll; + if (!t.hasFocus) { + break; + } + if (hieroglyph) { + t._syncEditors(); + } + oEvent.IsShift() ? t._selectChars(kNextLine) : t._moveCursor(kNextLine); break; } - if (hieroglyph) { - t._syncEditors(); - } - event.shiftKey ? t._selectChars(kPrevLine) : t._moveCursor(kPrevLine); - return false; + case 46: {// "del" + if (!this.enableKeyEvents || oEvent.IsShift()) { + break; + } - case 39: // "right" - if (!this.enableKeyEvents) { - this._delayedUpdateCursorByTopLine(); + if (hieroglyph) { + t._syncEditors(); + } + nRetValue = keydownresult_PreventAll; + t._removeChars(bIsWordRemove ? kNextWord : kNextChar); break; } - - event.stopPropagation(); - event.preventDefault(); - if (!t.hasFocus) { + case 144://Num Lock + case 145: {//Scroll Lock + if (AscBrowser.isOpera) { + nRetValue = keydownresult_PreventAll; + } break; } - if (hieroglyph) { - t._syncEditors(); - } - if (bIsMacOs && ctrlKey) - { - event.shiftKey ? t._selectChars(kEndOfLine) : t._moveCursor(kEndOfLine); - } - else - { - const bWord = bIsMacOs ? event.altKey : ctrlKey; - kind = bWord ? kNextWord : kNextChar; - event.shiftKey ? t._selectChars(kind) : t._moveCursor(kind); - } - return false; - - case 40: // "down" - if (!this.enableKeyEvents) { - this._delayedUpdateCursorByTopLine(); + case 80: {// print Ctrl + p + if (oEvent.CtrlKey) { + nRetValue = keydownresult_PreventAll; + break; + } break; } - - event.stopPropagation(); - event.preventDefault(); - if (!t.hasFocus) { + case 110: {//NumpadDecimal + t._addChars(api.asc_getDecimalSeparator()); + nRetValue = keydownresult_PreventAll; break; } - if (hieroglyph) { - t._syncEditors(); - } - event.shiftKey ? t._selectChars(kNextLine) : t._moveCursor(kNextLine); - return false; - - case 46: // "del" - if (!this.enableKeyEvents || event.shiftKey) { + case 113: {// F2 + if (AscBrowser.isOpera) { + nRetValue = keydownresult_PreventAll; + } break; } + case 115: {// F4 + const res = this._findRangeUnderCursor(); + if (res.range) { + res.range.switchReference(); + // ToDo add change ref to other sheet + this.changeCellRange(res.range); + } - if (hieroglyph) { - t._syncEditors(); - } - event.stopPropagation(); - event.preventDefault(); - t._removeChars(bIsWordRemove ? kNextWord : kNextChar); - return true; - - case 144://Num Lock - case 145://Scroll Lock - if (AscBrowser.isOpera) { - event.stopPropagation(); - event.preventDefault(); - } - return false; - - case 80: // print Ctrl + p - if (ctrlKey) { - event.stopPropagation(); - event.preventDefault(); - return false; - } - break; - - case 110: //NumpadDecimal - t._addChars(api.asc_getDecimalSeparator()); - event.stopPropagation(); - event.preventDefault(); - return false; - - case 113: // F2 - if (AscBrowser.isOpera) { - event.stopPropagation(); - event.preventDefault(); + nRetValue = keydownresult_PreventAll; + break; } - return false; - - case 115: // F4 - var res = this._findRangeUnderCursor(); - if (res.range) { - res.range.switchReference(); - // ToDo add change ref to other sheet - this.changeCellRange(res.range); + default: { + nRetValue = keydownresult_PreventNothing; + break; } - - event.stopPropagation(); - event.preventDefault(); - return false; - default: - t._setSkipKeyPress(false); - break; + } } - t.skipTLUpdate = true; - return true; + if (nRetValue & keydownresult_PreventKeyPress) + { + t._setSkipKeyPress(true); + t.skipTLUpdate = false; + } + return nRetValue; }; /** @param event {KeyboardEvent} */ diff --git a/cell/view/EventsController.js b/cell/view/EventsController.js index eaeb31acf5..a26186ad63 100644 --- a/cell/view/EventsController.js +++ b/cell/view/EventsController.js @@ -775,7 +775,6 @@ /** @param event {KeyboardEvent} */ asc_CEventsController.prototype._onWindowKeyDown = function (event) { let t = this; - var result = true; // для исправления Bug 15902 - Alt забирает фокус из приложения // этот код должен выполняться самым первым if (event.keyCode === 18) { @@ -799,7 +798,7 @@ const isFormulaEditMode = this.getFormulaEditMode(); // Двигаемся ли мы в выделенной области - var selectionActivePointChanged = false; + let selectionActivePointChanged = false; // Для таких браузеров, которые не присылают отжатие левой кнопки мыши для двойного клика, при выходе из // окна редактора и отпускания кнопки, будем отрабатывать выход из окна (только Chrome присылает эвент MouseUp даже при выходе из браузера) @@ -815,17 +814,19 @@ } - var isNeedCheckActiveCellChanged = null; - var _activeCell; + let isNeedCheckActiveCellChanged = null; + let _activeCell; const nShortcutAction = t.view.Api.getShortcut(oEvent); switch (nShortcutAction) { - case Asc.c_oAscSpreadsheetShortcutType.RecalculateAll: + case Asc.c_oAscSpreadsheetShortcutType.RecalculateAll: { t.handlers.trigger("calculate", Asc.c_oAscCalculateType.All); break; - case Asc.c_oAscSpreadsheetShortcutType.RecalculateActiveSheet: + } + case Asc.c_oAscSpreadsheetShortcutType.RecalculateActiveSheet: { t.handlers.trigger("calculate", Asc.c_oAscCalculateType.ActiveSheet); break; + } case Asc.c_oAscSpreadsheetShortcutType.RefreshAllPivots: case Asc.c_oAscSpreadsheetShortcutType.RefreshSelectedPivots: { if (!(canEdit && !t.getCellEditMode() && !selectionDialogMode)) { @@ -934,7 +935,7 @@ { break; } - var oCustom = t.view.Api.getCustomShortcutAction(nShortcutAction); + const oCustom = t.view.Api.getCustomShortcutAction(nShortcutAction); if (oCustom) { if (AscCommon.c_oAscCustomShortcutType.Symbol === oCustom.Type) { t.view.Api["asc_insertSymbol"](oCustom.Font, oCustom.CharCode); @@ -1056,8 +1057,8 @@ if (t.getCellEditMode()) { break; } - var isSelectColumns = ctrlKey; - var isSelectAllMacOs = isSelectColumns && shiftKey && macOs; + const isSelectColumns = ctrlKey; + const isSelectAllMacOs = isSelectColumns && shiftKey && macOs; // Обработать как обычный текст if ((!isSelectColumns && !shiftKey) || isSelectAllMacOs) { //теперь пробел обрабатывается на WindowKeyDown @@ -1260,13 +1261,13 @@ } } - var activeCellBefore; + let activeCellBefore; if (isNeedCheckActiveCellChanged) { activeCellBefore = t.handlers.trigger("getActiveCell"); } - var _checkLastTab = function () { + const _checkLastTab = function () { if (isNeedCheckActiveCellChanged) { - var activeCellAfter = t.handlers.trigger("getActiveCell"); + const activeCellAfter = t.handlers.trigger("getActiveCell"); if (!activeCellBefore || !activeCellAfter || !activeCellAfter.isEqual(activeCellBefore)) { t.lastTab = null; } @@ -1294,7 +1295,7 @@ } else { t.handlers.trigger("changeSelection", /*isStartPoint*/!shiftKey, dc, dr, /*isCoord*/false, false, function (d) { - var wb = window["Asc"]["editor"].wb; + const wb = window["Asc"]["editor"].wb; if (t.targetInfo) { wb._onUpdateWorksheet(t.targetInfo.coordX, t.targetInfo.coordY, false); } diff --git a/cell/view/WorkbookView.js b/cell/view/WorkbookView.js index e758c2d2ab..737c5ecc19 100644 --- a/cell/view/WorkbookView.js +++ b/cell/view/WorkbookView.js @@ -1129,11 +1129,11 @@ if (nRetValue & keydownresult_PreventPropagation) { - event.preventDefault(); + event.stopPropagation(); } if (nRetValue & keydownresult_PreventDefault) { - event.stopPropagation(); + event.preventDefault(); } this.Api.sendEvent("asc_onKeyDown", event); }