| 1 |
ace.define("ace/ext/searchbox-css",["require","exports","module"], function(require, exports, module){module.exports = "\n\n/* ------------------------------------------------------------------------------------------\n * Editor Search Form\n * --------------------------------------------------------------------------------------- */\n.ace_search {\n background-color: #ddd;\n color: #666;\n border: 1px solid #cbcbcb;\n border-top: 0 none;\n overflow: hidden;\n margin: 0;\n padding: 4px 6px 0 4px;\n position: absolute;\n top: 0;\n z-index: 99;\n white-space: normal;\n}\n.ace_search.left {\n border-left: 0 none;\n border-radius: 0px 0px 5px 0px;\n left: 0;\n}\n.ace_search.right {\n border-radius: 0px 0px 0px 5px;\n border-right: 0 none;\n right: 0;\n}\n\n.ace_search_form, .ace_replace_form {\n margin: 0 20px 4px 0;\n overflow: hidden;\n line-height: 1.9;\n}\n.ace_replace_form {\n margin-right: 0;\n}\n.ace_search_form.ace_nomatch {\n outline: 1px solid red;\n}\n\n.ace_search_field {\n border-radius: 3px 0 0 3px;\n background-color: white;\n color: black;\n border: 1px solid #cbcbcb;\n border-right: 0 none;\n outline: 0;\n padding: 0;\n font-size: inherit;\n margin: 0;\n line-height: inherit;\n padding: 0 6px;\n min-width: 17em;\n vertical-align: top;\n min-height: 1.8em;\n box-sizing: content-box;\n}\n.ace_searchbtn {\n border: 1px solid #cbcbcb;\n line-height: inherit;\n display: inline-block;\n padding: 0 6px;\n background: #fff;\n border-right: 0 none;\n border-left: 1px solid #dcdcdc;\n cursor: pointer;\n margin: 0;\n position: relative;\n color: #666;\n}\n.ace_searchbtn:last-child {\n border-radius: 0 3px 3px 0;\n border-right: 1px solid #cbcbcb;\n}\n.ace_searchbtn:disabled {\n background: none;\n cursor: default;\n}\n.ace_searchbtn:hover {\n background-color: #eef1f6;\n}\n.ace_searchbtn.prev, .ace_searchbtn.next {\n padding: 0px 0.7em\n}\n.ace_searchbtn.prev:after, .ace_searchbtn.next:after {\n content: \"\";\n border: solid 2px #888;\n width: 0.5em;\n height: 0.5em;\n border-width: 2px 0 0 2px;\n display:inline-block;\n transform: rotate(-45deg);\n}\n.ace_searchbtn.next:after {\n border-width: 0 2px 2px 0 ;\n}\n.ace_searchbtn_close {\n background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAcCAYAAABRVo5BAAAAZ0lEQVR42u2SUQrAMAhDvazn8OjZBilCkYVVxiis8H4CT0VrAJb4WHT3C5xU2a2IQZXJjiQIRMdkEoJ5Q2yMqpfDIo+XY4k6h+YXOyKqTIj5REaxloNAd0xiKmAtsTHqW8sR2W5f7gCu5nWFUpVjZwAAAABJRU5ErkJggg==) no-repeat 50% 0;\n border-radius: 50%;\n border: 0 none;\n color: #656565;\n cursor: pointer;\n font: 16px/16px Arial;\n padding: 0;\n height: 14px;\n width: 14px;\n top: 9px;\n right: 7px;\n position: absolute;\n}\n.ace_searchbtn_close:hover {\n background-color: #656565;\n background-position: 50% 100%;\n color: white;\n}\n\n.ace_button {\n margin-left: 2px;\n cursor: pointer;\n -webkit-user-select: none;\n -moz-user-select: none;\n -o-user-select: none;\n -ms-user-select: none;\n user-select: none;\n overflow: hidden;\n opacity: 0.7;\n border: 1px solid rgba(100,100,100,0.23);\n padding: 1px;\n box-sizing: border-box!important;\n color: black;\n}\n\n.ace_button:hover {\n background-color: #eee;\n opacity:1;\n}\n.ace_button:active {\n background-color: #ddd;\n}\n\n.ace_button.checked {\n border-color: #3399ff;\n opacity:1;\n}\n\n.ace_search_options{\n margin-bottom: 3px;\n text-align: right;\n -webkit-user-select: none;\n -moz-user-select: none;\n -o-user-select: none;\n -ms-user-select: none;\n user-select: none;\n clear: both;\n}\n\n.ace_search_counter {\n float: left;\n font-family: arial;\n padding: 0 8px;\n}"; |
| 2 |
|
| 3 |
}); |
| 4 |
|
| 5 |
ace.define("ace/ext/searchbox",["require","exports","module","ace/lib/dom","ace/lib/lang","ace/lib/event","ace/ext/searchbox-css","ace/keyboard/hash_handler","ace/lib/keys","ace/config"], function(require, exports, module){"use strict"; |
| 6 |
var dom = require("../lib/dom"); |
| 7 |
var lang = require("../lib/lang"); |
| 8 |
var event = require("../lib/event"); |
| 9 |
var searchboxCss = require("./searchbox-css"); |
| 10 |
var HashHandler = require("../keyboard/hash_handler").HashHandler; |
| 11 |
var keyUtil = require("../lib/keys"); |
| 12 |
var nls = require("../config").nls; |
| 13 |
var MAX_COUNT = 999; |
| 14 |
dom.importCssString(searchboxCss, "ace_searchbox", false); |
| 15 |
var SearchBox = (function () { |
| 16 |
function SearchBox(editor, range, showReplaceForm) { |
| 17 |
this.activeInput; |
| 18 |
var div = dom.createElement("div"); |
| 19 |
dom.buildDom(["div", { class: "ace_search right" }, |
| 20 |
["span", { action: "hide", class: "ace_searchbtn_close" }], |
| 21 |
["div", { class: "ace_search_form" }, |
| 22 |
["input", { class: "ace_search_field", placeholder: nls("Search for"), spellcheck: "false" }], |
| 23 |
["span", { action: "findPrev", class: "ace_searchbtn prev" }, "\u200b"], |
| 24 |
["span", { action: "findNext", class: "ace_searchbtn next" }, "\u200b"], |
| 25 |
["span", { action: "findAll", class: "ace_searchbtn", title: "Alt-Enter" }, nls("All")] |
| 26 |
], |
| 27 |
["div", { class: "ace_replace_form" }, |
| 28 |
["input", { class: "ace_search_field", placeholder: nls("Replace with"), spellcheck: "false" }], |
| 29 |
["span", { action: "replaceAndFindNext", class: "ace_searchbtn" }, nls("Replace")], |
| 30 |
["span", { action: "replaceAll", class: "ace_searchbtn" }, nls("All")] |
| 31 |
], |
| 32 |
["div", { class: "ace_search_options" }, |
| 33 |
["span", { action: "toggleReplace", class: "ace_button", title: nls("Toggle Replace mode"), |
| 34 |
style: "float:left;margin-top:-2px;padding:0 5px;" }, "+"], |
| 35 |
["span", { class: "ace_search_counter" }], |
| 36 |
["span", { action: "toggleRegexpMode", class: "ace_button", title: nls("RegExp Search") }, ".*"], |
| 37 |
["span", { action: "toggleCaseSensitive", class: "ace_button", title: nls("CaseSensitive Search") }, "Aa"], |
| 38 |
["span", { action: "toggleWholeWords", class: "ace_button", title: nls("Whole Word Search") }, "\\b"], |
| 39 |
["span", { action: "searchInSelection", class: "ace_button", title: nls("Search In Selection") }, "S"] |
| 40 |
] |
| 41 |
], div); |
| 42 |
this.element = div.firstChild; |
| 43 |
this.setSession = this.setSession.bind(this); |
| 44 |
this.$init(); |
| 45 |
this.setEditor(editor); |
| 46 |
dom.importCssString(searchboxCss, "ace_searchbox", editor.container); |
| 47 |
} |
| 48 |
SearchBox.prototype.setEditor = function (editor) { |
| 49 |
editor.searchBox = this; |
| 50 |
editor.renderer.scroller.appendChild(this.element); |
| 51 |
this.editor = editor; |
| 52 |
}; |
| 53 |
SearchBox.prototype.setSession = function (e) { |
| 54 |
this.searchRange = null; |
| 55 |
this.$syncOptions(true); |
| 56 |
}; |
| 57 |
SearchBox.prototype.$initElements = function (sb) { |
| 58 |
this.searchBox = sb.querySelector(".ace_search_form"); |
| 59 |
this.replaceBox = sb.querySelector(".ace_replace_form"); |
| 60 |
this.searchOption = sb.querySelector("[action=searchInSelection]"); |
| 61 |
this.replaceOption = sb.querySelector("[action=toggleReplace]"); |
| 62 |
this.regExpOption = sb.querySelector("[action=toggleRegexpMode]"); |
| 63 |
this.caseSensitiveOption = sb.querySelector("[action=toggleCaseSensitive]"); |
| 64 |
this.wholeWordOption = sb.querySelector("[action=toggleWholeWords]"); |
| 65 |
this.searchInput = this.searchBox.querySelector(".ace_search_field"); |
| 66 |
this.replaceInput = this.replaceBox.querySelector(".ace_search_field"); |
| 67 |
this.searchCounter = sb.querySelector(".ace_search_counter"); |
| 68 |
}; |
| 69 |
SearchBox.prototype.$init = function () { |
| 70 |
var sb = this.element; |
| 71 |
this.$initElements(sb); |
| 72 |
var _this = this; |
| 73 |
event.addListener(sb, "mousedown", function (e) { |
| 74 |
setTimeout(function () { |
| 75 |
_this.activeInput.focus(); |
| 76 |
}, 0); |
| 77 |
event.stopPropagation(e); |
| 78 |
}); |
| 79 |
event.addListener(sb, "click", function (e) { |
| 80 |
var t = e.target || e.srcElement; |
| 81 |
var action = t.getAttribute("action"); |
| 82 |
if (action && _this[action]) |
| 83 |
_this[action](); |
| 84 |
else if (_this.$searchBarKb.commands[action]) |
| 85 |
_this.$searchBarKb.commands[action].exec(_this); |
| 86 |
event.stopPropagation(e); |
| 87 |
}); |
| 88 |
event.addCommandKeyListener(sb, function (e, hashId, keyCode) { |
| 89 |
var keyString = keyUtil.keyCodeToString(keyCode); |
| 90 |
var command = _this.$searchBarKb.findKeyCommand(hashId, keyString); |
| 91 |
if (command && command.exec) { |
| 92 |
command.exec(_this); |
| 93 |
event.stopEvent(e); |
| 94 |
} |
| 95 |
}); |
| 96 |
this.$onChange = lang.delayedCall(function () { |
| 97 |
_this.find(false, false); |
| 98 |
}); |
| 99 |
event.addListener(this.searchInput, "input", function () { |
| 100 |
_this.$onChange.schedule(20); |
| 101 |
}); |
| 102 |
event.addListener(this.searchInput, "focus", function () { |
| 103 |
_this.activeInput = _this.searchInput; |
| 104 |
_this.searchInput.value && _this.highlight(); |
| 105 |
}); |
| 106 |
event.addListener(this.replaceInput, "focus", function () { |
| 107 |
_this.activeInput = _this.replaceInput; |
| 108 |
_this.searchInput.value && _this.highlight(); |
| 109 |
}); |
| 110 |
}; |
| 111 |
SearchBox.prototype.setSearchRange = function (range) { |
| 112 |
this.searchRange = range; |
| 113 |
if (range) { |
| 114 |
this.searchRangeMarker = this.editor.session.addMarker(range, "ace_active-line"); |
| 115 |
} |
| 116 |
else if (this.searchRangeMarker) { |
| 117 |
this.editor.session.removeMarker(this.searchRangeMarker); |
| 118 |
this.searchRangeMarker = null; |
| 119 |
} |
| 120 |
}; |
| 121 |
SearchBox.prototype.$syncOptions = function (preventScroll) { |
| 122 |
dom.setCssClass(this.replaceOption, "checked", this.searchRange); |
| 123 |
dom.setCssClass(this.searchOption, "checked", this.searchOption.checked); |
| 124 |
this.replaceOption.textContent = this.replaceOption.checked ? "-" : "+"; |
| 125 |
dom.setCssClass(this.regExpOption, "checked", this.regExpOption.checked); |
| 126 |
dom.setCssClass(this.wholeWordOption, "checked", this.wholeWordOption.checked); |
| 127 |
dom.setCssClass(this.caseSensitiveOption, "checked", this.caseSensitiveOption.checked); |
| 128 |
var readOnly = this.editor.getReadOnly(); |
| 129 |
this.replaceOption.style.display = readOnly ? "none" : ""; |
| 130 |
this.replaceBox.style.display = this.replaceOption.checked && !readOnly ? "" : "none"; |
| 131 |
this.find(false, false, preventScroll); |
| 132 |
}; |
| 133 |
SearchBox.prototype.highlight = function (re) { |
| 134 |
this.editor.session.highlight(re || this.editor.$search.$options.re); |
| 135 |
this.editor.renderer.updateBackMarkers(); |
| 136 |
}; |
| 137 |
SearchBox.prototype.find = function (skipCurrent, backwards, preventScroll) { |
| 138 |
var range = this.editor.find(this.searchInput.value, { |
| 139 |
skipCurrent: skipCurrent, |
| 140 |
backwards: backwards, |
| 141 |
wrap: true, |
| 142 |
regExp: this.regExpOption.checked, |
| 143 |
caseSensitive: this.caseSensitiveOption.checked, |
| 144 |
wholeWord: this.wholeWordOption.checked, |
| 145 |
preventScroll: preventScroll, |
| 146 |
range: this.searchRange |
| 147 |
}); |
| 148 |
var noMatch = !range && this.searchInput.value; |
| 149 |
dom.setCssClass(this.searchBox, "ace_nomatch", noMatch); |
| 150 |
this.editor._emit("findSearchBox", { match: !noMatch }); |
| 151 |
this.highlight(); |
| 152 |
this.updateCounter(); |
| 153 |
}; |
| 154 |
SearchBox.prototype.updateCounter = function () { |
| 155 |
var editor = this.editor; |
| 156 |
var regex = editor.$search.$options.re; |
| 157 |
var supportsUnicodeFlag = regex.unicode; |
| 158 |
var all = 0; |
| 159 |
var before = 0; |
| 160 |
if (regex) { |
| 161 |
var value = this.searchRange |
| 162 |
? editor.session.getTextRange(this.searchRange) |
| 163 |
: editor.getValue(); |
| 164 |
var offset = editor.session.doc.positionToIndex(editor.selection.anchor); |
| 165 |
if (this.searchRange) |
| 166 |
offset -= editor.session.doc.positionToIndex(this.searchRange.start); |
| 167 |
var last = regex.lastIndex = 0; |
| 168 |
var m; |
| 169 |
while ((m = regex.exec(value))) { |
| 170 |
all++; |
| 171 |
last = m.index; |
| 172 |
if (last <= offset) |
| 173 |
before++; |
| 174 |
if (all > MAX_COUNT) |
| 175 |
break; |
| 176 |
if (!m[0]) { |
| 177 |
regex.lastIndex = last += lang.skipEmptyMatch(value, last, supportsUnicodeFlag); |
| 178 |
if (last >= value.length) |
| 179 |
break; |
| 180 |
} |
| 181 |
} |
| 182 |
} |
| 183 |
this.searchCounter.textContent = nls("$0 of $1", [before, (all > MAX_COUNT ? MAX_COUNT + "+" : all)]); |
| 184 |
}; |
| 185 |
SearchBox.prototype.findNext = function () { |
| 186 |
this.find(true, false); |
| 187 |
}; |
| 188 |
SearchBox.prototype.findPrev = function () { |
| 189 |
this.find(true, true); |
| 190 |
}; |
| 191 |
SearchBox.prototype.findAll = function () { |
| 192 |
var range = this.editor.findAll(this.searchInput.value, { |
| 193 |
regExp: this.regExpOption.checked, |
| 194 |
caseSensitive: this.caseSensitiveOption.checked, |
| 195 |
wholeWord: this.wholeWordOption.checked |
| 196 |
}); |
| 197 |
var noMatch = !range && this.searchInput.value; |
| 198 |
dom.setCssClass(this.searchBox, "ace_nomatch", noMatch); |
| 199 |
this.editor._emit("findSearchBox", { match: !noMatch }); |
| 200 |
this.highlight(); |
| 201 |
this.hide(); |
| 202 |
}; |
| 203 |
SearchBox.prototype.replace = function () { |
| 204 |
if (!this.editor.getReadOnly()) |
| 205 |
this.editor.replace(this.replaceInput.value); |
| 206 |
}; |
| 207 |
SearchBox.prototype.replaceAndFindNext = function () { |
| 208 |
if (!this.editor.getReadOnly()) { |
| 209 |
this.editor.replace(this.replaceInput.value); |
| 210 |
this.findNext(); |
| 211 |
} |
| 212 |
}; |
| 213 |
SearchBox.prototype.replaceAll = function () { |
| 214 |
if (!this.editor.getReadOnly()) |
| 215 |
this.editor.replaceAll(this.replaceInput.value); |
| 216 |
}; |
| 217 |
SearchBox.prototype.hide = function () { |
| 218 |
this.active = false; |
| 219 |
this.setSearchRange(null); |
| 220 |
this.editor.off("changeSession", this.setSession); |
| 221 |
this.element.style.display = "none"; |
| 222 |
this.editor.keyBinding.removeKeyboardHandler(this.$closeSearchBarKb); |
| 223 |
this.editor.focus(); |
| 224 |
}; |
| 225 |
SearchBox.prototype.show = function (value, isReplace) { |
| 226 |
this.active = true; |
| 227 |
this.editor.on("changeSession", this.setSession); |
| 228 |
this.element.style.display = ""; |
| 229 |
this.replaceOption.checked = isReplace; |
| 230 |
if (value) |
| 231 |
this.searchInput.value = value; |
| 232 |
this.searchInput.focus(); |
| 233 |
this.searchInput.select(); |
| 234 |
this.editor.keyBinding.addKeyboardHandler(this.$closeSearchBarKb); |
| 235 |
this.$syncOptions(true); |
| 236 |
}; |
| 237 |
SearchBox.prototype.isFocused = function () { |
| 238 |
var el = document.activeElement; |
| 239 |
return el == this.searchInput || el == this.replaceInput; |
| 240 |
}; |
| 241 |
return SearchBox; |
| 242 |
}()); |
| 243 |
var $searchBarKb = new HashHandler(); |
| 244 |
$searchBarKb.bindKeys({ |
| 245 |
"Ctrl-f|Command-f": function (sb) { |
| 246 |
var isReplace = sb.isReplace = !sb.isReplace; |
| 247 |
sb.replaceBox.style.display = isReplace ? "" : "none"; |
| 248 |
sb.replaceOption.checked = false; |
| 249 |
sb.$syncOptions(); |
| 250 |
sb.searchInput.focus(); |
| 251 |
}, |
| 252 |
"Ctrl-H|Command-Option-F": function (sb) { |
| 253 |
if (sb.editor.getReadOnly()) |
| 254 |
return; |
| 255 |
sb.replaceOption.checked = true; |
| 256 |
sb.$syncOptions(); |
| 257 |
sb.replaceInput.focus(); |
| 258 |
}, |
| 259 |
"Ctrl-G|Command-G": function (sb) { |
| 260 |
sb.findNext(); |
| 261 |
}, |
| 262 |
"Ctrl-Shift-G|Command-Shift-G": function (sb) { |
| 263 |
sb.findPrev(); |
| 264 |
}, |
| 265 |
"esc": function (sb) { |
| 266 |
setTimeout(function () { sb.hide(); }); |
| 267 |
}, |
| 268 |
"Return": function (sb) { |
| 269 |
if (sb.activeInput == sb.replaceInput) |
| 270 |
sb.replace(); |
| 271 |
sb.findNext(); |
| 272 |
}, |
| 273 |
"Shift-Return": function (sb) { |
| 274 |
if (sb.activeInput == sb.replaceInput) |
| 275 |
sb.replace(); |
| 276 |
sb.findPrev(); |
| 277 |
}, |
| 278 |
"Alt-Return": function (sb) { |
| 279 |
if (sb.activeInput == sb.replaceInput) |
| 280 |
sb.replaceAll(); |
| 281 |
sb.findAll(); |
| 282 |
}, |
| 283 |
"Tab": function (sb) { |
| 284 |
(sb.activeInput == sb.replaceInput ? sb.searchInput : sb.replaceInput).focus(); |
| 285 |
} |
| 286 |
}); |
| 287 |
$searchBarKb.addCommands([{ |
| 288 |
name: "toggleRegexpMode", |
| 289 |
bindKey: { win: "Alt-R|Alt-/", mac: "Ctrl-Alt-R|Ctrl-Alt-/" }, |
| 290 |
exec: function (sb) { |
| 291 |
sb.regExpOption.checked = !sb.regExpOption.checked; |
| 292 |
sb.$syncOptions(); |
| 293 |
} |
| 294 |
}, { |
| 295 |
name: "toggleCaseSensitive", |
| 296 |
bindKey: { win: "Alt-C|Alt-I", mac: "Ctrl-Alt-R|Ctrl-Alt-I" }, |
| 297 |
exec: function (sb) { |
| 298 |
sb.caseSensitiveOption.checked = !sb.caseSensitiveOption.checked; |
| 299 |
sb.$syncOptions(); |
| 300 |
} |
| 301 |
}, { |
| 302 |
name: "toggleWholeWords", |
| 303 |
bindKey: { win: "Alt-B|Alt-W", mac: "Ctrl-Alt-B|Ctrl-Alt-W" }, |
| 304 |
exec: function (sb) { |
| 305 |
sb.wholeWordOption.checked = !sb.wholeWordOption.checked; |
| 306 |
sb.$syncOptions(); |
| 307 |
} |
| 308 |
}, { |
| 309 |
name: "toggleReplace", |
| 310 |
exec: function (sb) { |
| 311 |
sb.replaceOption.checked = !sb.replaceOption.checked; |
| 312 |
sb.$syncOptions(); |
| 313 |
} |
| 314 |
}, { |
| 315 |
name: "searchInSelection", |
| 316 |
exec: function (sb) { |
| 317 |
sb.searchOption.checked = !sb.searchRange; |
| 318 |
sb.setSearchRange(sb.searchOption.checked && sb.editor.getSelectionRange()); |
| 319 |
sb.$syncOptions(); |
| 320 |
} |
| 321 |
}]); |
| 322 |
var $closeSearchBarKb = new HashHandler([{ |
| 323 |
bindKey: "Esc", |
| 324 |
name: "closeSearchBar", |
| 325 |
exec: function (editor) { |
| 326 |
editor.searchBox.hide(); |
| 327 |
} |
| 328 |
}]); |
| 329 |
SearchBox.prototype.$searchBarKb = $searchBarKb; |
| 330 |
SearchBox.prototype.$closeSearchBarKb = $closeSearchBarKb; |
| 331 |
exports.SearchBox = SearchBox; |
| 332 |
exports.Search = function (editor, isReplace) { |
| 333 |
var sb = editor.searchBox || new SearchBox(editor); |
| 334 |
sb.show(editor.session.getTextRange(), isReplace); |
| 335 |
}; |
| 336 |
|
| 337 |
}); (function() { |
| 338 |
ace.require(["ace/ext/searchbox"], function(m) { |
| 339 |
if (typeof module == "object" && typeof exports == "object" && module) { |
| 340 |
module.exports = m; |
| 341 |
} |
| 342 |
}); |
| 343 |
})(); |
| 344 |
|