| 13535 | } |
| 13536 | |
| 13537 | function buildKeyMap(completion, handle) { |
| 13538 | var baseMap = { |
| 13539 | Up: function () { |
| 13540 | handle.moveFocus(-1) |
| 13541 | }, |
| 13542 | Down: function () { |
| 13543 | handle.moveFocus(1) |
| 13544 | }, |
| 13545 | PageUp: function () { |
| 13546 | handle.moveFocus(-handle.menuSize() + 1, true) |
| 13547 | }, |
| 13548 | PageDown: function () { |
| 13549 | handle.moveFocus(handle.menuSize() - 1, true) |
| 13550 | }, |
| 13551 | Home: function () { |
| 13552 | handle.setFocus(0) |
| 13553 | }, |
| 13554 | End: function () { |
| 13555 | handle.setFocus(handle.length - 1) |
| 13556 | }, |
| 13557 | Enter: handle.pick, |
| 13558 | Tab: handle.pick, |
| 13559 | Esc: handle.close |
| 13560 | } |
| 13561 | |
| 13562 | var mac = /Mac/.test(navigator.platform) |
| 13563 | |
| 13564 | if (mac) { |
| 13565 | baseMap["Ctrl-P"] = function () { |
| 13566 | handle.moveFocus(-1) |
| 13567 | } |
| 13568 | baseMap["Ctrl-N"] = function () { |
| 13569 | handle.moveFocus(1) |
| 13570 | } |
| 13571 | } |
| 13572 | |
| 13573 | var custom = completion.options.customKeys |
| 13574 | var ourMap = custom ? {} : baseMap |
| 13575 | function addBinding(key, val) { |
| 13576 | var bound |
| 13577 | if (typeof val != "string") |
| 13578 | bound = function (cm) { |
| 13579 | return val(cm, handle) |
| 13580 | } |
| 13581 | // This mechanism is deprecated |
| 13582 | else if (baseMap.hasOwnProperty(val)) bound = baseMap[val] |
| 13583 | else bound = val |
| 13584 | ourMap[key] = bound |
| 13585 | } |
| 13586 | if (custom) for (var key in custom) if (custom.hasOwnProperty(key)) addBinding(key, custom[key]) |
| 13587 | var extra = completion.options.extraKeys |
| 13588 | if (extra) for (var key in extra) if (extra.hasOwnProperty(key)) addBinding(key, extra[key]) |
| 13589 | return ourMap |
| 13590 | } |
| 13591 | |
| 13592 | function getHintElement(hintsElement, el) { |
| 13593 | while (el && el != hintsElement) { |