| 162 | } |
| 163 | |
| 164 | function buildKeyMap(completion, handle) { |
| 165 | var baseMap = { |
| 166 | Up: function() {handle.moveFocus(-1);}, |
| 167 | Down: function() {handle.moveFocus(1);}, |
| 168 | PageUp: function() {handle.moveFocus(-handle.menuSize() + 1, true);}, |
| 169 | PageDown: function() {handle.moveFocus(handle.menuSize() - 1, true);}, |
| 170 | Home: function() {handle.setFocus(0);}, |
| 171 | End: function() {handle.setFocus(handle.length - 1);}, |
| 172 | Enter: handle.pick, |
| 173 | Tab: handle.pick, |
| 174 | Esc: handle.close |
| 175 | }; |
| 176 | var custom = completion.options.customKeys; |
| 177 | var ourMap = custom ? {} : baseMap; |
| 178 | function addBinding(key, val) { |
| 179 | var bound; |
| 180 | if (typeof val != "string") |
| 181 | bound = function(cm) { return val(cm, handle); }; |
| 182 | // This mechanism is deprecated |
| 183 | else if (baseMap.hasOwnProperty(val)) |
| 184 | bound = baseMap[val]; |
| 185 | else |
| 186 | bound = val; |
| 187 | ourMap[key] = bound; |
| 188 | } |
| 189 | if (custom) |
| 190 | for (var key in custom) if (custom.hasOwnProperty(key)) |
| 191 | addBinding(key, custom[key]); |
| 192 | var extra = completion.options.extraKeys; |
| 193 | if (extra) |
| 194 | for (var key in extra) if (extra.hasOwnProperty(key)) |
| 195 | addBinding(key, extra[key]); |
| 196 | return ourMap; |
| 197 | } |
| 198 | |
| 199 | function getHintElement(hintsElement, el) { |
| 200 | while (el && el != hintsElement) { |