From 6232f19dccacb705770ceec34d13d609be11f152 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Fri, 22 Jul 2016 17:16:08 +0300 Subject: [PATCH] [SSE] Fixed bugs with focus and keydown events in function menu. --- apps/common/main/lib/component/Menu.js | 2 +- apps/common/main/lib/extend/Bootstrap.js | 2 +- .../main/app/controller/CellEditor.js | 25 ++++++++----------- .../main/app/controller/DocumentHolder.js | 3 ++- .../main/app/controller/Main.js | 6 +++-- 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/apps/common/main/lib/component/Menu.js b/apps/common/main/lib/component/Menu.js index 636785a7e9..e84794244a 100644 --- a/apps/common/main/lib/component/Menu.js +++ b/apps/common/main/lib/component/Menu.js @@ -441,7 +441,7 @@ define([ onAfterHideMenu: function(e) { this.trigger('hide:after', this, e); - Common.NotificationCenter.trigger('menu:hide'); + Common.NotificationCenter.trigger('menu:hide', this); }, onAfterKeydownMenu: function(e) { diff --git a/apps/common/main/lib/extend/Bootstrap.js b/apps/common/main/lib/extend/Bootstrap.js index 3e919d063d..4b61d204be 100755 --- a/apps/common/main/lib/extend/Bootstrap.js +++ b/apps/common/main/lib/extend/Bootstrap.js @@ -47,7 +47,7 @@ function onDropDownKeyDown(e) { $parent.trigger(beforeEvent); if ($parent.hasClass('no-stop-propagate')) { - if (arguments.length>1 && arguments[1] instanceof jQuery.Event) + if (arguments.length>1 && arguments[1] instanceof KeyboardEvent) e = arguments[1]; if ( /^(38|40|27|13|9)$/.test(e.keyCode) && !e.ctrlKey && !e.altKey) { patchDropDownKeyDownAdditional.call(this, e); diff --git a/apps/spreadsheeteditor/main/app/controller/CellEditor.js b/apps/spreadsheeteditor/main/app/controller/CellEditor.js index 8852b89504..40de0d73ca 100644 --- a/apps/spreadsheeteditor/main/app/controller/CellEditor.js +++ b/apps/spreadsheeteditor/main/app/controller/CellEditor.js @@ -81,6 +81,7 @@ define([ Common.NotificationCenter.on('api:disconnect', _.bind(this.onApiDisconnect, this)); Common.NotificationCenter.on('cells:range', _.bind(this.onCellsRange, this)); this.api.asc_registerCallback('asc_onLockDefNameManager', _.bind(this.onLockDefNameManager, this)); + this.api.asc_registerCallback('asc_onInputKeyDown', _.bind(this.onInputKeyDown, this)); return this; }, @@ -92,6 +93,15 @@ define([ this.editor.btnNamedRanges.setVisible(this.mode.isEdit && !this.mode.isEditDiagram && !this.mode.isEditMailMerge); }, + onInputKeyDown: function(e) { + if (Common.UI.Keys.UP === e.keyCode || Common.UI.Keys.DOWN === e.keyCode || + Common.UI.Keys.TAB === e.keyCode || Common.UI.Keys.RETURN === e.keyCode) { + var menu = $('#menu-formula-selection'); // for formula menu + if (menu.hasClass('open')) + menu.find('.dropdown-menu').trigger('keydown', e); + } + }, + onLaunch: function() { this.editor = this.createView('CellEditor',{ el: '#cell-editing-box' @@ -100,21 +110,6 @@ define([ this.bindViewEvents(this.editor, this.events); this.editor.$el.parent().find('.after').css({zIndex: '4'}); // for spreadsheets - bug 23127 - - var me = this; - $('#ce-cell-content').keydown(function (e) { - if (Common.UI.Keys.ESC === e.keyCode) { -// me.api.asc_enableKeyEvents(true); - } else if (Common.UI.Keys.UP === e.keyCode || Common.UI.Keys.DOWN === e.keyCode || - Common.UI.Keys.TAB === e.keyCode || Common.UI.Keys.RETURN === e.keyCode) { - var menu = $('#menu-formula-selection'); // for formula menu - if (menu.hasClass('open')) - menu.find('.dropdown-menu').trigger('keydown', e); -// if (Common.UI.Keys.RETURN === e.keyCode) -// me.api.asc_enableKeyEvents(true); - } - }); - this.editor.btnNamedRanges.menu.on('item:click', _.bind(this.onNamedRangesMenu, this)) .on('show:before', _.bind(this.onNameBeforeShow, this)); this.namedrange_locked = false; diff --git a/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js b/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js index 2dcf609907..cb8882d61e 100644 --- a/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js +++ b/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js @@ -1451,7 +1451,7 @@ define([ // Common.UI.Menu.prototype.onAfterKeydownMenu.call(menu, e); var li; - if (arguments.length>1 && arguments[1] instanceof jQuery.Event) // when typing in cell editor + if (arguments.length>1 && arguments[1] instanceof KeyboardEvent) // when typing in cell editor e = arguments[1]; if (menuContainer.hasClass('open')) { if (e.keyCode == Common.UI.Keys.TAB || e.keyCode == Common.UI.Keys.RETURN && !e.ctrlKey && !e.altKey) @@ -1505,6 +1505,7 @@ define([ } if (infocus) me.cellEditor.focus(); + menu.cmpEl.toggleClass('from-cell-edit', infocus); _.delay(function() { menu.cmpEl.find('li:first a').addClass('focus'); }, 10); diff --git a/apps/spreadsheeteditor/main/app/controller/Main.js b/apps/spreadsheeteditor/main/app/controller/Main.js index 136a511a0c..78145893ca 100644 --- a/apps/spreadsheeteditor/main/app/controller/Main.js +++ b/apps/spreadsheeteditor/main/app/controller/Main.js @@ -199,9 +199,11 @@ define([ }, 'menu:show': function(e){ }, - 'menu:hide': function(e){ - if (!me.isModalShowed) + 'menu:hide': function(menu){ + if (!me.isModalShowed && (!menu || !menu.cmpEl.hasClass('from-cell-edit'))) { + me.api.asc_InputClearKeyboardElement(); me.api.asc_enableKeyEvents(true); + } }, 'edit:complete': _.bind(this.onEditComplete, this), 'settings:unitschanged':_.bind(this.unitsChanged, this)