From ca45ade4c5294f130eb6cccb9919247339b2260a Mon Sep 17 00:00:00 2001 From: gorhill Date: Thu, 22 Jun 2017 14:34:18 -0400 Subject: [PATCH] fix #2723 --- platform/firefox/vapi-background.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index 5e43d7b49..70896f27a 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -3399,9 +3399,9 @@ vAPI.contextMenu = (function() { vAPI.commands = (function() { var commands = [ - { id: 'launch-element-zapper', shortcut: 'alt-z' }, - { id: 'launch-element-picker', shortcut: 'alt-x' }, - { id: 'launch-logger', shortcut: 'alt-l' } + { id: 'launch-element-zapper' }, + { id: 'launch-element-picker' }, + { id: 'launch-logger' } ]; var clientListener; @@ -3431,19 +3431,25 @@ vAPI.commands = (function() { myKeyset = doc.createElement('keyset'); myKeyset.setAttribute('id', 'uBlock0Keyset'); - var myKey, shortcut, parts, modifier, key; + var myKey, shortcut, parts, modifiers, key; for ( var command of commands ) { shortcut = vAPI.localStorage.getItem('shortcuts.' + command.id); - if ( shortcut === null ) { shortcut = command.shortcut; } - parts = /(([a-z]+)-)?(\w)/.exec(shortcut); + if ( shortcut === null ) { + vAPI.localStorage.setItem('shortcuts.' + command.id, ''); + } + if ( typeof shortcut !== 'string' ) { continue; } + parts = /^((?:[a-z]+-){1,})?(\w)$/.exec(shortcut); if ( parts === null ) { continue; } - modifier = parts[2] || ''; - key = parts[3] || ''; - if ( key === '' ) { continue; } + modifiers = parts[1]; + if ( typeof modifiers === 'string' ) { + modifiers = parts[1].slice(0, -1).split('-').join(' '); + } + key = parts[2]; + if ( typeof key !== 'string' ) { continue; } myKey = doc.createElement('key'); myKey.setAttribute('id', 'uBlock0Key-' + command.id); - if ( modifier !== '' ) { - myKey.setAttribute('modifiers', parts[2]); + if ( modifiers !== '' ) { + myKey.setAttribute('modifiers', modifiers); } myKey.setAttribute('key', key); // https://stackoverflow.com/a/16786770