|
20 | 20 | }; |
21 | 21 | var Pos = CodeMirror.Pos; |
22 | 22 |
|
| 23 | + function isArray(val) { return Object.prototype.toString.call(val) == "[object Array]" } |
| 24 | + |
23 | 25 | function getKeywords(editor) { |
24 | 26 | var mode = editor.doc.modeOption; |
25 | 27 | if (mode === "sql") mode = "text/x-sql"; |
|
30 | 32 | return typeof item == "string" ? item : item.text; |
31 | 33 | } |
32 | 34 |
|
| 35 | + function wrapTable(name, value) { |
| 36 | + if (isArray(value)) value = {columns: value} |
| 37 | + if (!value.text) value.text = name |
| 38 | + return value |
| 39 | + } |
| 40 | + |
33 | 41 | function parseTables(input) { |
34 | 42 | var result = {} |
35 | | - if (Object.prototype.toString.call(input) == "[object Array]") { |
| 43 | + if (isArray(input)) { |
36 | 44 | for (var i = input.length - 1; i >= 0; i--) { |
37 | 45 | var item = input[i] |
38 | | - result[getText(item).toUpperCase()] = item |
| 46 | + result[getText(item).toUpperCase()] = wrapTable(getText(item), item) |
39 | 47 | } |
40 | 48 | } else if (input) { |
41 | 49 | for (var name in input) |
42 | | - result[name.toUpperCase()] = input[name] |
| 50 | + result[name.toUpperCase()] = wrapTable(name, input[name]) |
43 | 51 | } |
44 | 52 | return result |
45 | 53 | } |
|
62 | 70 | } |
63 | 71 |
|
64 | 72 | function addMatches(result, search, wordlist, formatter) { |
65 | | - for (var word in wordlist) { |
66 | | - if (!wordlist.hasOwnProperty(word)) continue; |
67 | | - if (wordlist.slice) word = wordlist[word]; |
68 | | - |
69 | | - if (match(search, word)) result.push(formatter(word)); |
| 73 | + if (isArray(wordlist)) { |
| 74 | + for (var i = 0; i < wordlist.length; i++) |
| 75 | + if (match(search, wordlist[i])) result.push(formatter(wordlist[i])) |
| 76 | + } else { |
| 77 | + for (var word in wordlist) if (wordlist.hasOwnProperty(word)) { |
| 78 | + var val = wordlist[word] |
| 79 | + if (!val || val === true) |
| 80 | + val = word |
| 81 | + else |
| 82 | + val = val.displayText ? {text: val.text, displayText: val.displayText} : val.text |
| 83 | + if (match(search, val)) result.push(formatter(val)) |
| 84 | + } |
70 | 85 | } |
71 | 86 | } |
72 | 87 |
|
|
0 commit comments