3687db9c0d3858c4315ffb5152198053.js 19 KB

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