diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2020-03-24 12:15:51 -0400 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2020-03-26 17:57:57 +0100 |
commit | 1204099c6ed37de7cfe44dbc73cd372bc2b14c8f (patch) | |
tree | 4b68e41bd18ac966aa4c5867e0b93b161e9b3e3e | |
parent | 38b97e1791eb472cd320e3b2f1560a87c43c9e0f (diff) |
leaflet: don't allow focus stealing
This improves typing in the formula-bar.
Change-Id: I14359b5b4e842b68b1807d286e1831b3805bb4ea
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/91019
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/91131
Tested-by: Andras Timar <andras.timar@collabora.com>
-rw-r--r-- | cypress_test/integration_tests/common/helper.js | 6 | ||||
-rw-r--r-- | cypress_test/integration_tests/mobile/calc/focus_spec.js | 31 | ||||
-rw-r--r-- | loleaflet/src/layer/tile/TileLayer.js | 20 | ||||
-rw-r--r-- | loleaflet/src/map/Map.js | 10 |
4 files changed, 51 insertions, 16 deletions
diff --git a/cypress_test/integration_tests/common/helper.js b/cypress_test/integration_tests/common/helper.js index 5f9eabdac..1b3f4ca9f 100644 --- a/cypress_test/integration_tests/common/helper.js +++ b/cypress_test/integration_tests/common/helper.js @@ -80,6 +80,10 @@ function assertHaveKeyboardInput() { function assertCursorAndFocus() { cy.log('Verifying Cursor and Focus.'); + // Active element must be the textarea named clipboard. + cy.document().its('activeElement.className') + .should('be.eq', 'clipboard'); + // In edit mode, we should have the blinking cursor. cy.get('.leaflet-cursor.blinking-cursor') .should('exist'); @@ -121,7 +125,7 @@ function clearAllText() { // clipboard (which Cypress doesn't support). // Takes a closure f that takes the text // string as argument. Use as follows: -// helper.getTextForClipboard((htmlText, plainText) => { +// helper.getTextForClipboard((plainText) => { // expect(plainText, 'Selection Text').to.equal(testText); // }); function getTextForClipboard(f) { diff --git a/cypress_test/integration_tests/mobile/calc/focus_spec.js b/cypress_test/integration_tests/mobile/calc/focus_spec.js index 0ea2b3b77..aae23ac19 100644 --- a/cypress_test/integration_tests/mobile/calc/focus_spec.js +++ b/cypress_test/integration_tests/mobile/calc/focus_spec.js @@ -72,4 +72,35 @@ describe('Calc focus tests', function() { calcHelper.assertInTextEditMode(); }); + + it('Formula-bar focus', function() { + // Click on edit button + helper.enableEditingMobile(); + + // Body has the focus -> can't type in the document + cy.document().its('activeElement.tagName') + .should('be.eq', 'BODY'); + + helper.assertNoKeyboardInput(); + + // One tap on a cell -> no document focus + calcHelper.clickOnFirstCell(); + + cy.get('.leaflet-marker-icon') + .should('be.visible'); + + // No focus + cy.document().its('activeElement.tagName') + .should('be.eq', 'BODY'); + + // Click in the formula-bar. + cy.get('.inputbar_container') + .click(); + + helper.assertCursorAndFocus(); + + // Type some text. + cy.get('textarea.clipboard') + .type('blah'); + }); }); diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js index 61a5b688b..4c35db6e4 100644 --- a/loleaflet/src/layer/tile/TileLayer.js +++ b/loleaflet/src/layer/tile/TileLayer.js @@ -1171,7 +1171,7 @@ L.TileLayer = L.GridLayer.extend({ this._showURLPopUp(cursorPos, obj.hyperlink.link); } - if (!this._map.editorHasFocus() && (modifierViewId === this._viewId) && (this._map._permission === 'edit')) { + if (!this._map.editorHasFocus() && this._map._isCursorVisible && (modifierViewId === this._viewId) && (this._map._permission === 'edit')) { // Regain cursor if we had been out of focus and now have input. // (only if it is our own cursor and the input is actually not // going into a dialog) @@ -2188,20 +2188,18 @@ L.TileLayer = L.GridLayer.extend({ this._updateCursorPos(); - // Update the cursor/keyboard only when the document has focus. - if (this._map.editorHasFocus()) { - this._map._textInput.showCursor(); + this._map._textInput.showCursor(); - // Don't show the keyboard when the Wizard is visible. - if (!window.mobileWizard) { - // If the user is editing, show the keyboard, but don't change - // anything if nothing is changed. - this._map.focus(true); - } + // Don't show the keyboard when the Wizard is visible. + if (!window.mobileWizard) { + // If the user is editing, show the keyboard, but don't change + // anything if nothing is changed. + this._map.focus(true); } } else { this._map._textInput.hideCursor(); - this._map.focus(false); + if (this._map.editorHasFocus()) // Allow input if a dialog has the focus. + this._map.focus(false); } }, diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js index 024192295..38f0803dc 100644 --- a/loleaflet/src/map/Map.js +++ b/loleaflet/src/map/Map.js @@ -1408,12 +1408,14 @@ L.Map = L.Evented.extend({ this._activeDialog = dialog; this._isSearching = false; - var doclayer = this._docLayer; - if (doclayer) + if (this.editorHasFocus()) { + // The document has the focus. + var doclayer = this._docLayer; doclayer._updateCursorAndOverlay(); - - if (acceptInput !== undefined) + } else if (acceptInput !== undefined) { + // A dialog has the focus. this.focus(acceptInput); + } }, // Our browser tab lost focus. |