diff options
| -rw-r--r-- | background_page.html | 35 | ||||
| -rw-r--r-- | vimiumFrontend.js | 19 |
2 files changed, 35 insertions, 19 deletions
diff --git a/background_page.html b/background_page.html index ada3e0f0..520ae49c 100644 --- a/background_page.html +++ b/background_page.html @@ -11,6 +11,8 @@ var validFirstKeys = {}; var singleKeyCommands = []; + var specialKeyStrokeRegex = /^<(a|m|c)-.>/; + var defaultSettings = { scrollStepSize: 60, defaultZoomLevel: 100, @@ -275,9 +277,16 @@ } // End action functions + function splitKeyIntoFirstAndSecond(key) { + if (key.search(specialKeyStrokeRegex) == 0) + return { first: key.slice(0, 5), second: key.slice(5) }; + else + return { first: key[0], second: key.slice(1) }; + } + function getActualKeyStrokeLength(key) { - if (key.slice(0, 3) == "<c-" && key[key.length - 1] == ">") - return 1; + if (key.search(specialKeyStrokeRegex) == 0) + return 1 + getActualKeyStrokeLength(key.slice(5)); else return key.length; } @@ -285,8 +294,10 @@ function populateValidFirstKeys() { for (var key in keyToCommandRegistry) { - if (key.length == 2) - validFirstKeys[key[0]] = true; + if (getActualKeyStrokeLength(key) == 2) + { + validFirstKeys[splitKeyIntoFirstAndSecond(key).first] = true; + } } } @@ -313,9 +324,9 @@ { for (var key in keyToCommandRegistry) { - // NOTE(ilya): This won't work if we allow keys like <c-x><c-y>. - if (key[0] == command) - completionKeys.push(key.substring(1)); + var splitKey = splitKeyIntoFirstAndSecond(key); + if (splitKey.first == command) + completionKeys.push(splitKey.second); } } @@ -366,12 +377,14 @@ } newKeyQueue = ""; - } else if (command.length > 1) { + } else if (getActualKeyStrokeLength(command) > 1) { + var splitKey = splitKeyIntoFirstAndSecond(command); + // The second key might be a valid command by its self. - if (keyToCommandRegistry[command[1]]) - newKeyQueue = checkKeyQueue(command[1]); + if (keyToCommandRegistry[splitKey.second]) + newKeyQueue = checkKeyQueue(splitKey.second); else - newKeyQueue = (validFirstKeys[command[1]] ? command[1] : ""); + newKeyQueue = (validFirstKeys[splitKey.second] ? splitKey.second : ""); } else { newKeyQueue = (validFirstKeys[command] ? count.toString() + command : ""); } diff --git a/vimiumFrontend.js b/vimiumFrontend.js index bac5d8ae..f67768f7 100644 --- a/vimiumFrontend.js +++ b/vimiumFrontend.js @@ -287,14 +287,17 @@ function onKeydown(event) { return; } - if (event.shiftKey) - keyChar = keyChar.toUpperCase(); - if (event.ctrlKey) - keyChar = "<c-" + keyChar + ">"; - if (event.metaKey) - keyChar = "<m-" + keyChar + ">"; - if (event.altKey) - keyChar = "<a-" + keyChar + ">"; + if (keyChar != "") // Again, ignore just modifiers. Maybe this should replace the keyCode > 31 condition. + { + if (event.shiftKey) + keyChar = keyChar.toUpperCase(); + else if (event.ctrlKey) + keyChar = "<c-" + keyChar + ">"; + else if (event.metaKey) + keyChar = "<m-" + keyChar + ">"; + else if (event.altKey) + keyChar = "<a-" + keyChar + ">"; + } } if (insertMode && isEscape(event)) |
