GHC 2017-01-09

1 comment.

, https://git.io/vM8Qh in ccampbell/mousetrap
Bug: a keybinding could be unavailable if another partially overlapping and shorter one is registered before it
===============================================================================================================

I found a kind of weird bug in 1.6.0 (reproducible on master), where a keybinding could be unavailable if another partially overlapping and shorter one is registered before it.

Repro: Compare [test-good.html](https://rawgit.com/zmwangx/9cc60e0e09919da526a955e72eb76355/raw/4878a3797caa789c70875eac4ae8adc9650bc514/test-good.html):

```html
<!DOCTYPE html>
<html>
<head>
  <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
  <script src="https://rawgit.com/ccampbell/mousetrap/35c73fddf78380f69e21493674754a2663a36ea9/mousetrap.js"></script>
  <script>
    Mousetrap.bind('a b enter', function () {
      $('#alert').text('a b enter pressed')
    })
    Mousetrap.bind('a enter', function () {
      $('#alert').text('a enter pressed')
    })
  </script>
</head>
<body>
  <div id="alert">press "a b enter" or "a enter"</div>
</body>
</html>
```

where we register `a b enter` **before** `a enter`, resulting in both keybindings working; and [test-bad.html](https://rawgit.com/zmwangx/9cc60e0e09919da526a955e72eb76355/raw/4878a3797caa789c70875eac4ae8adc9650bc514/test-bad.html):

```html
<!DOCTYPE html>
<html>
<head>
  <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
  <script src="https://rawgit.com/ccampbell/mousetrap/35c73fddf78380f69e21493674754a2663a36ea9/mousetrap.js"></script>
  <script>
    Mousetrap.bind('a enter', function () {
      $('#alert').text('a enter pressed')
    })
    Mousetrap.bind('a b enter', function () {
      $('#alert').text('a b enter pressed')
    })
  </script>
</head>
<body>
  <div id="alert">press "a b enter" or "a enter"</div>
</body>
</html>
```

where we register `a b enter` **after** `a enter`, resulting in `a enter` working but `a b enter` not.