Bartosz Dziewoński has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/377351 )
Change subject: SelectWidget: Ignore keypresses with modifiers in type-to-search ...................................................................... SelectWidget: Ignore keypresses with modifiers in type-to-search This is more complicated than it sounds because we still want to allow the user to type 'A' (Shift+A) or 'ą' (AltGr+A on Polish keyboard). Introduce a helper function to check for these. Bug: T174133 Change-Id: If314d088b3ec9e07086207b67aaeaf541b1223f0 --- M src/core.js M src/widgets/SelectWidget.js M tests/core.test.js 3 files changed, 49 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/oojs/ui refs/changes/51/377351/1 diff --git a/src/core.js b/src/core.js index 1073da9..5f16d59 100644 --- a/src/core.js +++ b/src/core.js @@ -190,6 +190,22 @@ }; /** + * Check whether a jQuery event represents a plain key press, without modifiers commonly used for + * keyboard shortcuts, like Ctrl or Command. + * + * Note that modifiers required to input text are allowed, including Shift and Alt+Ctrl (AltGr). + * + * For example, this function will return true for 'A', 'Shift+A' or 'Alt+Ctrl+A' ('AltGr+A'), + * but false for 'Alt+A', 'Ctrl+A' or 'Command+A'. + * + * @param {jQuery.Event} e The jQuery event object + * @return {boolean} Whether it was a plain key press + */ +OO.ui.isPlainKeyPress = function ( e ) { + return !e.metaKey && ( ( !e.altKey && !e.ctrlKey ) || ( e.altKey && e.ctrlKey ) ); +}; + +/** * Check if a node is contained within another node * * Similar to jQuery#contains except a list of containers can be supplied diff --git a/src/widgets/SelectWidget.js b/src/widgets/SelectWidget.js index fc5040a..814258c 100644 --- a/src/widgets/SelectWidget.js +++ b/src/widgets/SelectWidget.js @@ -390,6 +390,9 @@ OO.ui.SelectWidget.prototype.onKeyPress = function ( e ) { var c, filter, item; + if ( !OO.ui.isPlainKeyPress( e ) ) { + return; + } if ( !e.charCode ) { if ( e.keyCode === OO.ui.Keys.BACKSPACE && this.keyPressBuffer !== '' ) { this.keyPressBuffer = this.keyPressBuffer.substr( 0, this.keyPressBuffer.length - 1 ); diff --git a/tests/core.test.js b/tests/core.test.js index a758e65..cc7bbc0 100644 --- a/tests/core.test.js +++ b/tests/core.test.js @@ -1,5 +1,35 @@ QUnit.module( 'core' ); +QUnit.test( 'isPlainKeyPress', function ( assert ) { + var cases, i, event, expected, result; + // Every possible combination of Alt, Ctrl, Shift, Command + cases = [ + [ { altKey: 0, ctrlKey: 0, shiftKey: 0, metaKey: 0 }, true ], + [ { altKey: 0, ctrlKey: 0, shiftKey: 0, metaKey: 1 }, false ], + [ { altKey: 0, ctrlKey: 0, shiftKey: 1, metaKey: 0 }, true ], + [ { altKey: 0, ctrlKey: 0, shiftKey: 1, metaKey: 1 }, false ], + [ { altKey: 0, ctrlKey: 1, shiftKey: 0, metaKey: 0 }, false ], + [ { altKey: 0, ctrlKey: 1, shiftKey: 0, metaKey: 1 }, false ], + [ { altKey: 0, ctrlKey: 1, shiftKey: 1, metaKey: 0 }, false ], + [ { altKey: 0, ctrlKey: 1, shiftKey: 1, metaKey: 1 }, false ], + [ { altKey: 1, ctrlKey: 0, shiftKey: 0, metaKey: 0 }, false ], + [ { altKey: 1, ctrlKey: 0, shiftKey: 0, metaKey: 1 }, false ], + [ { altKey: 1, ctrlKey: 0, shiftKey: 1, metaKey: 0 }, false ], + [ { altKey: 1, ctrlKey: 0, shiftKey: 1, metaKey: 1 }, false ], + [ { altKey: 1, ctrlKey: 1, shiftKey: 0, metaKey: 0 }, true ], + [ { altKey: 1, ctrlKey: 1, shiftKey: 0, metaKey: 1 }, false ], + [ { altKey: 1, ctrlKey: 1, shiftKey: 1, metaKey: 0 }, true ], + [ { altKey: 1, ctrlKey: 1, shiftKey: 1, metaKey: 1 }, false ] + ]; + + for ( i = 0; i < cases.length; i++ ) { + event = cases[ i ][ 0 ]; + expected = cases[ i ][ 1 ]; + result = OO.ui.isPlainKeyPress( event ); + assert.strictEqual( result, expected ); + } +} ); + /** * @note: Keep tests in sync with phpunit/TagTest.php */ -- To view, visit https://gerrit.wikimedia.org/r/377351 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If314d088b3ec9e07086207b67aaeaf541b1223f0 Gerrit-PatchSet: 1 Gerrit-Project: oojs/ui Gerrit-Branch: master Gerrit-Owner: Bartosz Dziewoński <matma....@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits