| 19 | })(function(CodeMirror) { |
| 20 | "use strict"; |
| 21 | function searchOverlay(query, caseInsensitive) { |
| 22 | if (typeof query == "string") |
| 23 | query = new RegExp(query.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"), caseInsensitive ? "gi" : "g"); |
| 24 | else if (!query.global) |
| 25 | query = new RegExp(query.source, query.ignoreCase ? "gi" : "g"); |
| 26 | |
| 27 | return {token: function(stream) { |
| 28 | query.lastIndex = stream.pos; |
| 29 | var match = query.exec(stream.string); |
| 30 | if (match && match.index == stream.pos) { |
| 31 | stream.pos += match[0].length; |
| 32 | return "searching"; |
| 33 | } else if (match) { |
| 34 | stream.pos = match.index; |
| 35 | } else { |
| 36 | stream.skipToEnd(); |
| 37 | } |
| 38 | }}; |
| 39 | } |
| 40 | |
| 41 | function SearchState() { |
| 42 | this.posFrom = this.posTo = this.query = null; |