codemirror-rails 3.18 → 3.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/lib/codemirror/rails/version.rb +2 -2
  3. data/vendor/assets/javascripts/codemirror.js +42 -19
  4. data/vendor/assets/javascripts/codemirror/addons/edit/closetag.js +1 -1
  5. data/vendor/assets/javascripts/codemirror/addons/edit/continuelist.js +1 -1
  6. data/vendor/assets/javascripts/codemirror/addons/fold/foldcode.js +6 -4
  7. data/vendor/assets/javascripts/codemirror/addons/fold/foldgutter.js +2 -0
  8. data/vendor/assets/javascripts/codemirror/addons/fold/indent-fold.js +21 -7
  9. data/vendor/assets/javascripts/codemirror/addons/hint/javascript-hint.js +3 -19
  10. data/vendor/assets/javascripts/codemirror/addons/hint/sql-hint.js +105 -0
  11. data/vendor/assets/javascripts/codemirror/addons/hint/xml-hint.js +1 -0
  12. data/vendor/assets/javascripts/codemirror/addons/search/search.js +2 -0
  13. data/vendor/assets/javascripts/codemirror/addons/tern/tern.js +1 -1
  14. data/vendor/assets/javascripts/codemirror/addons/wrap/hardwrap.js +99 -0
  15. data/vendor/assets/javascripts/codemirror/keymaps/vim.js +55 -17
  16. data/vendor/assets/javascripts/codemirror/modes/coffeescript.js +314 -313
  17. data/vendor/assets/javascripts/codemirror/modes/css.js +19 -7
  18. data/vendor/assets/javascripts/codemirror/modes/eiffel.js +147 -0
  19. data/vendor/assets/javascripts/codemirror/modes/gfm.js +2 -1
  20. data/vendor/assets/javascripts/codemirror/modes/gherkin.js +168 -0
  21. data/vendor/assets/javascripts/codemirror/modes/less.js +110 -22
  22. data/vendor/assets/javascripts/codemirror/modes/php.js +4 -4
  23. data/vendor/assets/javascripts/codemirror/modes/smartymixed.js +6 -1
  24. data/vendor/assets/javascripts/codemirror/modes/sql.js +15 -2
  25. data/vendor/assets/javascripts/codemirror/modes/xml.js +7 -3
  26. data/vendor/assets/stylesheets/codemirror.css +1 -1
  27. data/vendor/assets/stylesheets/codemirror/addons/fold/foldgutter.css +21 -0
  28. data/vendor/assets/stylesheets/codemirror/addons/lint/lint.css +1 -0
  29. data/vendor/assets/stylesheets/codemirror/themes/3024-day.css +1 -1
  30. data/vendor/assets/stylesheets/codemirror/themes/3024-night.css +1 -1
  31. data/vendor/assets/stylesheets/codemirror/themes/ambiance.css +1 -1
  32. data/vendor/assets/stylesheets/codemirror/themes/base16-dark.css +1 -1
  33. data/vendor/assets/stylesheets/codemirror/themes/base16-light.css +1 -1
  34. data/vendor/assets/stylesheets/codemirror/themes/blackboard.css +1 -1
  35. data/vendor/assets/stylesheets/codemirror/themes/cobalt.css +1 -1
  36. data/vendor/assets/stylesheets/codemirror/themes/eclipse.css +1 -1
  37. data/vendor/assets/stylesheets/codemirror/themes/elegant.css +1 -1
  38. data/vendor/assets/stylesheets/codemirror/themes/erlang-dark.css +1 -1
  39. data/vendor/assets/stylesheets/codemirror/themes/lesser-dark.css +1 -1
  40. data/vendor/assets/stylesheets/codemirror/themes/mbo.css +35 -0
  41. data/vendor/assets/stylesheets/codemirror/themes/midnight.css +1 -1
  42. data/vendor/assets/stylesheets/codemirror/themes/monokai.css +1 -1
  43. data/vendor/assets/stylesheets/codemirror/themes/night.css +1 -1
  44. data/vendor/assets/stylesheets/codemirror/themes/paraiso-dark.css +1 -1
  45. data/vendor/assets/stylesheets/codemirror/themes/paraiso-light.css +1 -1
  46. data/vendor/assets/stylesheets/codemirror/themes/rubyblue.css +1 -1
  47. data/vendor/assets/stylesheets/codemirror/themes/solarized.css +7 -7
  48. data/vendor/assets/stylesheets/codemirror/themes/the-matrix.css +1 -1
  49. data/vendor/assets/stylesheets/codemirror/themes/tomorrow-night-eighties.css +1 -1
  50. data/vendor/assets/stylesheets/codemirror/themes/twilight.css +1 -1
  51. data/vendor/assets/stylesheets/codemirror/themes/vibrant-ink.css +1 -1
  52. data/vendor/assets/stylesheets/codemirror/themes/xq-dark.css +1 -1
  53. data/vendor/assets/stylesheets/codemirror/themes/xq-light.css +1 -1
  54. metadata +7 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cfb792b0da3816a44ec84933d0e66151ac99385d
4
- data.tar.gz: 8caa95433b98eb880163d9526e1d164323723c27
3
+ metadata.gz: 9386202ed77c77960e25b33dfc99951976f4fae4
4
+ data.tar.gz: b0e5fb1cb06211914a2fcd09e97d2fd05c419cc2
5
5
  SHA512:
6
- metadata.gz: 870029fa185381657331c3e262fd0e106f75675c039caf72be59ee00788aca72fcc2cd7e79ab961b1850cf504f6cc24e1cc9c0d2cb017e7139c9c1dba6658a87
7
- data.tar.gz: d460615e4a5a40e3a7ef4505bc4a5a398ac1a00b217c5cb5271b9b1efa0cd1774a9623b52d5158063b0e2fe165be60615262d1fc886a3224c4ed55f7622fe3e9
6
+ metadata.gz: b5f1e8a81e9800c2cc7718b3f2dd3ea07fa13a7ca9db1c35719569da67fc32d1cb2e3dccce1c206250b24b421b5600505724ac236bd423c54b70b8de58ab6537
7
+ data.tar.gz: 414b29b5373f82921da9abe9f169d9de4728031c6193a60638bff52b751b90f283aa8149da0d8992b97ec4fb1e2dbffb8e0601b545f7dc748350a1b27d9cad69
@@ -1,6 +1,6 @@
1
1
  module Codemirror
2
2
  module Rails
3
- VERSION = '3.18'
4
- CODEMIRROR_VERSION = '3.18'
3
+ VERSION = '3.19'
4
+ CODEMIRROR_VERSION = '3.19'
5
5
  end
6
6
  end
@@ -353,8 +353,10 @@ window.CodeMirror = (function() {
353
353
  d.gutterFiller.style.width = d.gutters.offsetWidth + "px";
354
354
  } else d.gutterFiller.style.display = "";
355
355
 
356
- if (mac_geLion && scrollbarWidth(d.measure) === 0)
356
+ if (mac_geLion && scrollbarWidth(d.measure) === 0) {
357
357
  d.scrollbarV.style.minWidth = d.scrollbarH.style.minHeight = mac_geMountainLion ? "18px" : "12px";
358
+ d.scrollbarV.style.pointerEvents = d.scrollbarH.style.pointerEvents = "none";
359
+ }
358
360
  }
359
361
 
360
362
  function visibleLines(display, doc, viewPort) {
@@ -935,8 +937,9 @@ window.CodeMirror = (function() {
935
937
  // smallest indentation, which tends to need the least context to
936
938
  // parse correctly.
937
939
  function findStartLine(cm, n, precise) {
938
- var minindent, minline, doc = cm.doc, maxScan = cm.doc.mode.innerMode ? 1000 : 100;
939
- for (var search = n, lim = n - maxScan; search > lim; --search) {
940
+ var minindent, minline, doc = cm.doc;
941
+ var lim = precise ? -1 : n - (cm.doc.mode.innerMode ? 1000 : 100);
942
+ for (var search = n; search > lim; --search) {
940
943
  if (search <= doc.first) return doc.first;
941
944
  var line = getLine(doc, search - 1);
942
945
  if (line.stateAfter && (!precise || search <= doc.frontier)) return search;
@@ -961,6 +964,7 @@ window.CodeMirror = (function() {
961
964
  line.stateAfter = save ? copyState(doc.mode, state) : null;
962
965
  ++pos;
963
966
  });
967
+ if (precise) doc.frontier = pos;
964
968
  return state;
965
969
  }
966
970
 
@@ -1383,7 +1387,8 @@ window.CodeMirror = (function() {
1383
1387
  display.scroller.scrollLeft = display.scrollbarH.scrollLeft = doc.scrollLeft = newScrollPos.scrollLeft;
1384
1388
  alignHorizontally(cm);
1385
1389
  if (op.scrollToPos)
1386
- scrollPosIntoView(cm, clipPos(cm.doc, op.scrollToPos), op.scrollToPosMargin);
1390
+ scrollPosIntoView(cm, clipPos(cm.doc, op.scrollToPos.from),
1391
+ clipPos(cm.doc, op.scrollToPos.to), op.scrollToPos.margin);
1387
1392
  } else if (newScrollPos) {
1388
1393
  scrollCursorIntoView(cm);
1389
1394
  }
@@ -2179,7 +2184,11 @@ window.CodeMirror = (function() {
2179
2184
 
2180
2185
  var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop;
2181
2186
  if (!pos || opera) return; // Opera is difficult.
2182
- if (posEq(sel.from, sel.to) || posLess(pos, sel.from) || !posLess(pos, sel.to))
2187
+
2188
+ // Reset the current text selection only if the click is done outside of the selection
2189
+ // and 'resetSelectionOnContextMenu' option is true.
2190
+ var reset = cm.options.resetSelectionOnContextMenu;
2191
+ if (reset && (posEq(sel.from, sel.to) || posLess(pos, sel.from) || !posLess(pos, sel.to)))
2183
2192
  operation(cm, setSelection)(cm.doc, pos, pos);
2184
2193
 
2185
2194
  var oldCSS = display.input.style.cssText;
@@ -2630,7 +2639,7 @@ window.CodeMirror = (function() {
2630
2639
  // SCROLLING
2631
2640
 
2632
2641
  function scrollCursorIntoView(cm) {
2633
- var coords = scrollPosIntoView(cm, cm.doc.sel.head, cm.options.cursorScrollMargin);
2642
+ var coords = scrollPosIntoView(cm, cm.doc.sel.head, null, cm.options.cursorScrollMargin);
2634
2643
  if (!cm.state.focused) return;
2635
2644
  var display = cm.display, box = getRect(display.sizer), doScroll = null;
2636
2645
  if (coords.top + box.top < 0) doScroll = true;
@@ -2647,11 +2656,15 @@ window.CodeMirror = (function() {
2647
2656
  }
2648
2657
  }
2649
2658
 
2650
- function scrollPosIntoView(cm, pos, margin) {
2659
+ function scrollPosIntoView(cm, pos, end, margin) {
2651
2660
  if (margin == null) margin = 0;
2652
2661
  for (;;) {
2653
2662
  var changed = false, coords = cursorCoords(cm, pos);
2654
- var scrollPos = calculateScrollPos(cm, coords.left, coords.top - margin, coords.left, coords.bottom + margin);
2663
+ var endCoords = !end || end == pos ? coords : cursorCoords(cm, end);
2664
+ var scrollPos = calculateScrollPos(cm, Math.min(coords.left, endCoords.left),
2665
+ Math.min(coords.top, endCoords.top) - margin,
2666
+ Math.max(coords.left, endCoords.left),
2667
+ Math.max(coords.bottom, endCoords.bottom) + margin);
2655
2668
  var startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft;
2656
2669
  if (scrollPos.scrollTop != null) {
2657
2670
  setScrollTop(cm, scrollPos.scrollTop);
@@ -3169,17 +3182,23 @@ window.CodeMirror = (function() {
3169
3182
  clientHeight: scroller.clientHeight - co, clientWidth: scroller.clientWidth - co};
3170
3183
  },
3171
3184
 
3172
- scrollIntoView: operation(null, function(pos, margin) {
3173
- if (typeof pos == "number") pos = Pos(pos, 0);
3185
+ scrollIntoView: operation(null, function(range, margin) {
3186
+ if (range == null) range = {from: this.doc.sel.head, to: null};
3187
+ else if (typeof range == "number") range = {from: Pos(range, 0), to: null};
3188
+ else if (range.from == null) range = {from: range, to: null};
3189
+ if (!range.to) range.to = range.from;
3174
3190
  if (!margin) margin = 0;
3175
- var coords = pos;
3176
3191
 
3177
- if (!pos || pos.line != null) {
3178
- this.curOp.scrollToPos = pos ? clipPos(this.doc, pos) : this.doc.sel.head;
3179
- this.curOp.scrollToPosMargin = margin;
3180
- coords = cursorCoords(this, this.curOp.scrollToPos);
3192
+ var coords = range;
3193
+ if (range.from.line != null) {
3194
+ this.curOp.scrollToPos = {from: range.from, to: range.to, margin: margin};
3195
+ coords = {from: cursorCoords(this, range.from),
3196
+ to: cursorCoords(this, range.to)};
3181
3197
  }
3182
- var sPos = calculateScrollPos(this, coords.left, coords.top - margin, coords.right, coords.bottom + margin);
3198
+ var sPos = calculateScrollPos(this, Math.min(coords.from.left, coords.to.left),
3199
+ Math.min(coords.from.top, coords.to.top) - margin,
3200
+ Math.max(coords.from.right, coords.to.right),
3201
+ Math.max(coords.from.bottom, coords.to.bottom) + margin);
3183
3202
  updateScrollPos(this, sPos.scrollLeft, sPos.scrollTop);
3184
3203
  }),
3185
3204
 
@@ -3211,6 +3230,7 @@ window.CodeMirror = (function() {
3211
3230
  clearCaches(this);
3212
3231
  resetInput(this, true);
3213
3232
  updateScrollPos(this, doc.scrollLeft, doc.scrollTop);
3233
+ signalLater(this, "swapDoc", this, old);
3214
3234
  return old;
3215
3235
  }),
3216
3236
 
@@ -3285,6 +3305,8 @@ window.CodeMirror = (function() {
3285
3305
  option("lineNumberFormatter", function(integer) {return integer;}, guttersChanged, true);
3286
3306
  option("showCursorWhenSelecting", false, updateSelection, true);
3287
3307
 
3308
+ option("resetSelectionOnContextMenu", true);
3309
+
3288
3310
  option("readOnly", false, function(cm, val) {
3289
3311
  if (val == "nocursor") {onBlur(cm); cm.display.input.blur();}
3290
3312
  else if (!val) resetInput(cm, true);
@@ -3521,7 +3543,8 @@ window.CodeMirror = (function() {
3521
3543
  keyMap.basic = {
3522
3544
  "Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown",
3523
3545
  "End": "goLineEnd", "Home": "goLineStartSmart", "PageUp": "goPageUp", "PageDown": "goPageDown",
3524
- "Delete": "delCharAfter", "Backspace": "delCharBefore", "Tab": "defaultTab", "Shift-Tab": "indentAuto",
3546
+ "Delete": "delCharAfter", "Backspace": "delCharBefore", "Shift-Backspace": "delCharBefore",
3547
+ "Tab": "defaultTab", "Shift-Tab": "indentAuto",
3525
3548
  "Enter": "newlineAndIndent", "Insert": "toggleOverwrite"
3526
3549
  };
3527
3550
  // Note that the save and find-related commands aren't defined by
@@ -4461,7 +4484,7 @@ window.CodeMirror = (function() {
4461
4484
  return out;
4462
4485
  }
4463
4486
  return function(builder, text, style, startStyle, endStyle, title) {
4464
- return inner(builder, text.replace(/ {3,}/, split), style, startStyle, endStyle, title);
4487
+ return inner(builder, text.replace(/ {3,}/g, split), style, startStyle, endStyle, title);
4465
4488
  };
4466
4489
  }
4467
4490
 
@@ -5879,7 +5902,7 @@ window.CodeMirror = (function() {
5879
5902
 
5880
5903
  // THE END
5881
5904
 
5882
- CodeMirror.version = "3.18.0";
5905
+ CodeMirror.version = "3.19.0";
5883
5906
 
5884
5907
  return CodeMirror;
5885
5908
  })();
@@ -72,7 +72,7 @@
72
72
  function autoCloseSlash(cm) {
73
73
  var pos = cm.getCursor(), tok = cm.getTokenAt(pos);
74
74
  var inner = CodeMirror.innerMode(cm.getMode(), tok.state), state = inner.state;
75
- if (tok.string.charAt(0) != "<" || inner.mode.name != "xml") return CodeMirror.Pass;
75
+ if (tok.string.charAt(0) != "<" || tok.start != pos.ch - 1 || inner.mode.name != "xml") return CodeMirror.Pass;
76
76
 
77
77
  var tagName = state.context && state.context.tagName;
78
78
  if (tagName) cm.replaceSelection("/" + tagName + ">", "end");
@@ -6,7 +6,7 @@
6
6
 
7
7
  CodeMirror.commands.newlineAndIndentContinueMarkdownList = function(cm) {
8
8
  var pos = cm.getCursor(),
9
- inList = cm.getStateAfter(pos.line).list,
9
+ inList = cm.getStateAfter(pos.line).list !== false,
10
10
  match;
11
11
 
12
12
  if (!inList || !(match = cm.getLine(pos.line).match(listRE))) {
@@ -1,7 +1,7 @@
1
1
  (function() {
2
2
  "use strict";
3
3
 
4
- function doFold(cm, pos, options) {
4
+ function doFold(cm, pos, options, force) {
5
5
  var finder = options && (options.call ? options : options.rangeFinder);
6
6
  if (!finder) finder = cm.getHelper(pos, "fold");
7
7
  if (!finder) return;
@@ -13,7 +13,7 @@
13
13
  if (!range || range.to.line - range.from.line < minSize) return null;
14
14
  var marks = cm.findMarksAt(range.from);
15
15
  for (var i = 0; i < marks.length; ++i) {
16
- if (marks[i].__isFold) {
16
+ if (marks[i].__isFold && force !== "fold") {
17
17
  if (!allowFolded) return null;
18
18
  range.cleared = true;
19
19
  marks[i].clear();
@@ -27,7 +27,7 @@
27
27
  pos = CodeMirror.Pos(pos.line - 1, 0);
28
28
  range = getRange(false);
29
29
  }
30
- if (!range || range.cleared) return;
30
+ if (!range || range.cleared || force === "unfold") return;
31
31
 
32
32
  var myWidget = makeWidget(options);
33
33
  CodeMirror.on(myWidget, "mousedown", function() { myRange.clear(); });
@@ -59,7 +59,9 @@
59
59
  };
60
60
 
61
61
  // New-style interface
62
- CodeMirror.defineExtension("foldCode", function(pos, options) { doFold(this, pos, options); });
62
+ CodeMirror.defineExtension("foldCode", function(pos, options, force) {
63
+ doFold(this, pos, options, force);
64
+ });
63
65
 
64
66
  CodeMirror.registerHelper("fold", "combine", function() {
65
67
  var funcs = Array.prototype.slice.call(arguments, 0);
@@ -10,6 +10,7 @@
10
10
  cm.off("viewportChange", onViewportChange);
11
11
  cm.off("fold", onFold);
12
12
  cm.off("unfold", onFold);
13
+ cm.off("swapDoc", updateInViewport);
13
14
  }
14
15
  if (val) {
15
16
  cm.state.foldGutter = new State(parseOptions(val));
@@ -19,6 +20,7 @@
19
20
  cm.on("viewportChange", onViewportChange);
20
21
  cm.on("fold", onFold);
21
22
  cm.on("unfold", onFold);
23
+ cm.on("swapDoc", updateInViewport);
22
24
  }
23
25
  });
24
26
 
@@ -1,12 +1,26 @@
1
1
  CodeMirror.registerHelper("fold", "indent", function(cm, start) {
2
- var tabSize = cm.getOption("tabSize"), firstLine = cm.getLine(start.line);
3
- var myIndent = CodeMirror.countColumn(firstLine, null, tabSize);
4
- for (var i = start.line + 1, end = cm.lineCount(); i < end; ++i) {
5
- var curLine = cm.getLine(i);
6
- if (CodeMirror.countColumn(curLine, null, tabSize) < myIndent &&
7
- CodeMirror.countColumn(cm.getLine(i-1), null, tabSize) > myIndent)
2
+ var lastLine = cm.lastLine(),
3
+ tabSize = cm.getOption("tabSize"),
4
+ firstLine = cm.getLine(start.line),
5
+ myIndent = CodeMirror.countColumn(firstLine, null, tabSize);
6
+
7
+ function foldEnded(curColumn, prevColumn) {
8
+ return curColumn < myIndent ||
9
+ (curColumn == myIndent && prevColumn >= myIndent) ||
10
+ (curColumn > myIndent && i == lastLine);
11
+ }
12
+
13
+ for (var i = start.line + 1; i <= lastLine; i++) {
14
+ var curColumn = CodeMirror.countColumn(cm.getLine(i), null, tabSize);
15
+ var prevColumn = CodeMirror.countColumn(cm.getLine(i-1), null, tabSize);
16
+
17
+ if (foldEnded(curColumn, prevColumn)) {
18
+ var lastFoldLineNumber = curColumn > myIndent && i == lastLine ? i : i-1;
19
+ var lastFoldLine = cm.getLine(lastFoldLineNumber);
8
20
  return {from: CodeMirror.Pos(start.line, firstLine.length),
9
- to: CodeMirror.Pos(i, curLine.length)};
21
+ to: CodeMirror.Pos(lastFoldLineNumber, lastFoldLine.length)};
22
+ }
10
23
  }
11
24
  });
25
+
12
26
  CodeMirror.indentRangeFinder = CodeMirror.fold.indent; // deprecated
@@ -33,21 +33,6 @@
33
33
  tprop = getToken(editor, Pos(cur.line, tprop.start));
34
34
  if (tprop.string != ".") return;
35
35
  tprop = getToken(editor, Pos(cur.line, tprop.start));
36
- if (tprop.string == ')') {
37
- var level = 1;
38
- do {
39
- tprop = getToken(editor, Pos(cur.line, tprop.start));
40
- switch (tprop.string) {
41
- case ')': level++; break;
42
- case '(': level--; break;
43
- default: break;
44
- }
45
- } while (level > 0);
46
- tprop = getToken(editor, Pos(cur.line, tprop.start));
47
- if (tprop.type.indexOf("variable") === 0)
48
- tprop.type = "function";
49
- else return; // no clue
50
- }
51
36
  if (!context) var context = [];
52
37
  context.push(tprop);
53
38
  }
@@ -110,11 +95,11 @@
110
95
  for (var name in obj) maybeAdd(name);
111
96
  }
112
97
 
113
- if (context) {
98
+ if (context && context.length) {
114
99
  // If this is a property, see if it belongs to some object we can
115
100
  // find in the current environment.
116
101
  var obj = context.pop(), base;
117
- if (obj.type.indexOf("variable") === 0) {
102
+ if (obj.type && obj.type.indexOf("variable") === 0) {
118
103
  if (options && options.additionalContext)
119
104
  base = options.additionalContext[obj.string];
120
105
  base = base || window[obj.string];
@@ -132,8 +117,7 @@
132
117
  while (base != null && context.length)
133
118
  base = base[context.pop().string];
134
119
  if (base != null) gatherCompletions(base);
135
- }
136
- else {
120
+ } else {
137
121
  // If not, just look in the window object and any local scope
138
122
  // (reading into JS mode internals to get at the local and global variables)
139
123
  for (var v = token.state.localVars; v; v = v.next) maybeAdd(v.name);
@@ -0,0 +1,105 @@
1
+ (function () {
2
+ "use strict";
3
+
4
+ var tables;
5
+ var keywords;
6
+
7
+ function getKeywords(editor) {
8
+ var mode = editor.doc.modeOption;
9
+ if(mode === "sql") mode = "text/x-sql";
10
+ return CodeMirror.resolveMode(mode).keywords;
11
+ }
12
+
13
+ function match(string, word) {
14
+ var len = string.length;
15
+ var sub = word.substr(0, len);
16
+ return string.toUpperCase() === sub.toUpperCase();
17
+ }
18
+
19
+ function addMatches(result, search, wordlist, formatter) {
20
+ for(var word in wordlist) {
21
+ if(!wordlist.hasOwnProperty(word)) continue;
22
+ if(Array.isArray(wordlist)) {
23
+ word = wordlist[word];
24
+ }
25
+ if(match(search, word)) {
26
+ result.push(formatter(word));
27
+ }
28
+ }
29
+ }
30
+
31
+ function columnCompletion(result, editor) {
32
+ var cur = editor.getCursor();
33
+ var token = editor.getTokenAt(cur);
34
+ var string = token.string.substr(1);
35
+ var prevCur = CodeMirror.Pos(cur.line, token.start);
36
+ var table = editor.getTokenAt(prevCur).string;
37
+ var columns = tables[table];
38
+ if(!columns) {
39
+ table = findTableByAlias(table, editor);
40
+ }
41
+ columns = tables[table];
42
+ if(!columns) {
43
+ return;
44
+ }
45
+ addMatches(result, string, columns,
46
+ function(w) {return "." + w;});
47
+ }
48
+
49
+ function eachWord(line, f) {
50
+ var words = line.text.split(" ");
51
+ for(var i = 0; i < words.length; i++) {
52
+ f(words[i]);
53
+ }
54
+ }
55
+
56
+ // Tries to find possible table name from alias.
57
+ function findTableByAlias(alias, editor) {
58
+ var aliasUpperCase = alias.toUpperCase();
59
+ var previousWord = "";
60
+ var table = "";
61
+
62
+ editor.eachLine(function(line) {
63
+ eachWord(line, function(word) {
64
+ var wordUpperCase = word.toUpperCase();
65
+ if(wordUpperCase === aliasUpperCase) {
66
+ if(tables.hasOwnProperty(previousWord)) {
67
+ table = previousWord;
68
+ }
69
+ }
70
+ if(wordUpperCase !== "AS") {
71
+ previousWord = word;
72
+ }
73
+ });
74
+ });
75
+ return table;
76
+ }
77
+
78
+ function sqlHint(editor, options) {
79
+ tables = (options && options.tables) || {};
80
+ keywords = keywords || getKeywords(editor);
81
+ var cur = editor.getCursor();
82
+ var token = editor.getTokenAt(cur);
83
+
84
+ var result = [];
85
+
86
+ var search = token.string.trim();
87
+
88
+ addMatches(result, search, keywords,
89
+ function(w) {return w.toUpperCase();});
90
+
91
+ addMatches(result, search, tables,
92
+ function(w) {return w;});
93
+
94
+ if(search.lastIndexOf('.') === 0) {
95
+ columnCompletion(result, editor);
96
+ }
97
+
98
+ return {
99
+ list: result,
100
+ from: CodeMirror.Pos(cur.line, token.start),
101
+ to: CodeMirror.Pos(cur.line, token.end)
102
+ };
103
+ }
104
+ CodeMirror.registerHelper("hint", "sql", sqlHint);
105
+ })();
@@ -37,6 +37,7 @@
37
37
  Pos(cur.line, token.type == "string" ? token.start : token.end));
38
38
  var atName = before.match(/([^\s\u00a0=<>\"\']+)=$/), atValues;
39
39
  if (!atName || !attrs.hasOwnProperty(atName[1]) || !(atValues = attrs[atName[1]])) return;
40
+ if (typeof atValues == 'function') atValues = atValues.call(this, cm); // Functions can be used to supply values for autocomplete widget
40
41
  if (token.type == "string") {
41
42
  prefix = token.string;
42
43
  if (/['"]/.test(token.string.charAt(0))) {
@@ -70,6 +70,7 @@
70
70
  if (!cursor.find(rev)) return;
71
71
  }
72
72
  cm.setSelection(cursor.from(), cursor.to());
73
+ cm.scrollIntoView({from: cursor.from(), to: cursor.to()});
73
74
  state.posFrom = cursor.from(); state.posTo = cursor.to();
74
75
  });}
75
76
  function clearSearch(cm) {cm.operation(function() {
@@ -108,6 +109,7 @@
108
109
  (start && cursor.from().line == start.line && cursor.from().ch == start.ch)) return;
109
110
  }
110
111
  cm.setSelection(cursor.from(), cursor.to());
112
+ cm.scrollIntoView({from: cursor.from(), to: cursor.to()});
111
113
  confirmDialog(cm, doReplaceConfirm, "Replace?",
112
114
  [function() {doReplace(match);}, advance]);
113
115
  };