plugin.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  1. /**
  2. * Copyright (c) Tiny Technologies, Inc. All rights reserved.
  3. * Licensed under the LGPL or a commercial license.
  4. * For LGPL see License.txt in the project root for license information.
  5. * For commercial licenses see https://www.tiny.cloud/
  6. *
  7. * Version: 5.0.1 (2019-02-21)
  8. */
  9. (function () {
  10. var searchreplace = (function () {
  11. 'use strict';
  12. var Cell = function (initial) {
  13. var value = initial;
  14. var get = function () {
  15. return value;
  16. };
  17. var set = function (v) {
  18. value = v;
  19. };
  20. var clone = function () {
  21. return Cell(get());
  22. };
  23. return {
  24. get: get,
  25. set: set,
  26. clone: clone
  27. };
  28. };
  29. var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
  30. var global$1 = tinymce.util.Tools.resolve('tinymce.util.Tools');
  31. function isContentEditableFalse(node) {
  32. return node && node.nodeType === 1 && node.contentEditable === 'false';
  33. }
  34. function findAndReplaceDOMText(regex, node, replacementNode, captureGroup, schema) {
  35. var m;
  36. var matches = [];
  37. var text, count = 0, doc;
  38. var blockElementsMap, hiddenTextElementsMap, shortEndedElementsMap;
  39. doc = node.ownerDocument;
  40. blockElementsMap = schema.getBlockElements();
  41. hiddenTextElementsMap = schema.getWhiteSpaceElements();
  42. shortEndedElementsMap = schema.getShortEndedElements();
  43. function getMatchIndexes(m, captureGroup) {
  44. captureGroup = captureGroup || 0;
  45. if (!m[0]) {
  46. throw new Error('findAndReplaceDOMText cannot handle zero-length matches');
  47. }
  48. var index = m.index;
  49. if (captureGroup > 0) {
  50. var cg = m[captureGroup];
  51. if (!cg) {
  52. throw new Error('Invalid capture group');
  53. }
  54. index += m[0].indexOf(cg);
  55. m[0] = cg;
  56. }
  57. return [
  58. index,
  59. index + m[0].length,
  60. [m[0]]
  61. ];
  62. }
  63. function getText(node) {
  64. var txt;
  65. if (node.nodeType === 3) {
  66. return node.data;
  67. }
  68. if (hiddenTextElementsMap[node.nodeName] && !blockElementsMap[node.nodeName]) {
  69. return '';
  70. }
  71. txt = '';
  72. if (isContentEditableFalse(node)) {
  73. return '\n';
  74. }
  75. if (blockElementsMap[node.nodeName] || shortEndedElementsMap[node.nodeName]) {
  76. txt += '\n';
  77. }
  78. if (node = node.firstChild) {
  79. do {
  80. txt += getText(node);
  81. } while (node = node.nextSibling);
  82. }
  83. return txt;
  84. }
  85. function stepThroughMatches(node, matches, replaceFn) {
  86. var startNode, endNode, startNodeIndex, endNodeIndex, innerNodes = [], atIndex = 0, curNode = node, matchLocation = matches.shift(), matchIndex = 0;
  87. out:
  88. while (true) {
  89. if (blockElementsMap[curNode.nodeName] || shortEndedElementsMap[curNode.nodeName] || isContentEditableFalse(curNode)) {
  90. atIndex++;
  91. }
  92. if (curNode.nodeType === 3) {
  93. if (!endNode && curNode.length + atIndex >= matchLocation[1]) {
  94. endNode = curNode;
  95. endNodeIndex = matchLocation[1] - atIndex;
  96. } else if (startNode) {
  97. innerNodes.push(curNode);
  98. }
  99. if (!startNode && curNode.length + atIndex > matchLocation[0]) {
  100. startNode = curNode;
  101. startNodeIndex = matchLocation[0] - atIndex;
  102. }
  103. atIndex += curNode.length;
  104. }
  105. if (startNode && endNode) {
  106. curNode = replaceFn({
  107. startNode: startNode,
  108. startNodeIndex: startNodeIndex,
  109. endNode: endNode,
  110. endNodeIndex: endNodeIndex,
  111. innerNodes: innerNodes,
  112. match: matchLocation[2],
  113. matchIndex: matchIndex
  114. });
  115. atIndex -= endNode.length - endNodeIndex;
  116. startNode = null;
  117. endNode = null;
  118. innerNodes = [];
  119. matchLocation = matches.shift();
  120. matchIndex++;
  121. if (!matchLocation) {
  122. break;
  123. }
  124. } else if ((!hiddenTextElementsMap[curNode.nodeName] || blockElementsMap[curNode.nodeName]) && curNode.firstChild) {
  125. if (!isContentEditableFalse(curNode)) {
  126. curNode = curNode.firstChild;
  127. continue;
  128. }
  129. } else if (curNode.nextSibling) {
  130. curNode = curNode.nextSibling;
  131. continue;
  132. }
  133. while (true) {
  134. if (curNode.nextSibling) {
  135. curNode = curNode.nextSibling;
  136. break;
  137. } else if (curNode.parentNode !== node) {
  138. curNode = curNode.parentNode;
  139. } else {
  140. break out;
  141. }
  142. }
  143. }
  144. }
  145. function genReplacer(nodeName) {
  146. var makeReplacementNode;
  147. if (typeof nodeName !== 'function') {
  148. var stencilNode_1 = nodeName.nodeType ? nodeName : doc.createElement(nodeName);
  149. makeReplacementNode = function (fill, matchIndex) {
  150. var clone = stencilNode_1.cloneNode(false);
  151. clone.setAttribute('data-mce-index', matchIndex);
  152. if (fill) {
  153. clone.appendChild(doc.createTextNode(fill));
  154. }
  155. return clone;
  156. };
  157. } else {
  158. makeReplacementNode = nodeName;
  159. }
  160. return function (range) {
  161. var before;
  162. var after;
  163. var parentNode;
  164. var startNode = range.startNode;
  165. var endNode = range.endNode;
  166. var matchIndex = range.matchIndex;
  167. if (startNode === endNode) {
  168. var node_1 = startNode;
  169. parentNode = node_1.parentNode;
  170. if (range.startNodeIndex > 0) {
  171. before = doc.createTextNode(node_1.data.substring(0, range.startNodeIndex));
  172. parentNode.insertBefore(before, node_1);
  173. }
  174. var el = makeReplacementNode(range.match[0], matchIndex);
  175. parentNode.insertBefore(el, node_1);
  176. if (range.endNodeIndex < node_1.length) {
  177. after = doc.createTextNode(node_1.data.substring(range.endNodeIndex));
  178. parentNode.insertBefore(after, node_1);
  179. }
  180. node_1.parentNode.removeChild(node_1);
  181. return el;
  182. }
  183. before = doc.createTextNode(startNode.data.substring(0, range.startNodeIndex));
  184. after = doc.createTextNode(endNode.data.substring(range.endNodeIndex));
  185. var elA = makeReplacementNode(startNode.data.substring(range.startNodeIndex), matchIndex);
  186. for (var i = 0, l = range.innerNodes.length; i < l; ++i) {
  187. var innerNode = range.innerNodes[i];
  188. var innerEl = makeReplacementNode(innerNode.data, matchIndex);
  189. innerNode.parentNode.replaceChild(innerEl, innerNode);
  190. }
  191. var elB = makeReplacementNode(endNode.data.substring(0, range.endNodeIndex), matchIndex);
  192. parentNode = startNode.parentNode;
  193. parentNode.insertBefore(before, startNode);
  194. parentNode.insertBefore(elA, startNode);
  195. parentNode.removeChild(startNode);
  196. parentNode = endNode.parentNode;
  197. parentNode.insertBefore(elB, endNode);
  198. parentNode.insertBefore(after, endNode);
  199. parentNode.removeChild(endNode);
  200. return elB;
  201. };
  202. }
  203. text = getText(node);
  204. if (!text) {
  205. return;
  206. }
  207. if (regex.global) {
  208. while (m = regex.exec(text)) {
  209. matches.push(getMatchIndexes(m, captureGroup));
  210. }
  211. } else {
  212. m = text.match(regex);
  213. matches.push(getMatchIndexes(m, captureGroup));
  214. }
  215. if (matches.length) {
  216. count = matches.length;
  217. stepThroughMatches(node, matches, genReplacer(replacementNode));
  218. }
  219. return count;
  220. }
  221. var FindReplaceText = { findAndReplaceDOMText: findAndReplaceDOMText };
  222. var getElmIndex = function (elm) {
  223. var value = elm.getAttribute('data-mce-index');
  224. if (typeof value === 'number') {
  225. return '' + value;
  226. }
  227. return value;
  228. };
  229. var markAllMatches = function (editor, currentIndexState, regex) {
  230. var node, marker;
  231. marker = editor.dom.create('span', { 'data-mce-bogus': 1 });
  232. marker.className = 'mce-match-marker';
  233. node = editor.getBody();
  234. done(editor, currentIndexState, false);
  235. return FindReplaceText.findAndReplaceDOMText(regex, node, marker, false, editor.schema);
  236. };
  237. var unwrap = function (node) {
  238. var parentNode = node.parentNode;
  239. if (node.firstChild) {
  240. parentNode.insertBefore(node.firstChild, node);
  241. }
  242. node.parentNode.removeChild(node);
  243. };
  244. var findSpansByIndex = function (editor, index) {
  245. var nodes;
  246. var spans = [];
  247. nodes = global$1.toArray(editor.getBody().getElementsByTagName('span'));
  248. if (nodes.length) {
  249. for (var i = 0; i < nodes.length; i++) {
  250. var nodeIndex = getElmIndex(nodes[i]);
  251. if (nodeIndex === null || !nodeIndex.length) {
  252. continue;
  253. }
  254. if (nodeIndex === index.toString()) {
  255. spans.push(nodes[i]);
  256. }
  257. }
  258. }
  259. return spans;
  260. };
  261. var moveSelection = function (editor, currentIndexState, forward) {
  262. var testIndex = currentIndexState.get();
  263. var dom = editor.dom;
  264. forward = forward !== false;
  265. if (forward) {
  266. testIndex++;
  267. } else {
  268. testIndex--;
  269. }
  270. dom.removeClass(findSpansByIndex(editor, currentIndexState.get()), 'mce-match-marker-selected');
  271. var spans = findSpansByIndex(editor, testIndex);
  272. if (spans.length) {
  273. dom.addClass(findSpansByIndex(editor, testIndex), 'mce-match-marker-selected');
  274. editor.selection.scrollIntoView(spans[0]);
  275. return testIndex;
  276. }
  277. return -1;
  278. };
  279. var removeNode = function (dom, node) {
  280. var parent = node.parentNode;
  281. dom.remove(node);
  282. if (dom.isEmpty(parent)) {
  283. dom.remove(parent);
  284. }
  285. };
  286. var find = function (editor, currentIndexState, text, matchCase, wholeWord) {
  287. text = text.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
  288. text = text.replace(/\s/g, '[^\\S\\r\\n]');
  289. text = wholeWord ? '\\b' + text + '\\b' : text;
  290. var count = markAllMatches(editor, currentIndexState, new RegExp(text, matchCase ? 'g' : 'gi'));
  291. if (count) {
  292. currentIndexState.set(-1);
  293. currentIndexState.set(moveSelection(editor, currentIndexState, true));
  294. }
  295. return count;
  296. };
  297. var next = function (editor, currentIndexState) {
  298. var index = moveSelection(editor, currentIndexState, true);
  299. if (index !== -1) {
  300. currentIndexState.set(index);
  301. }
  302. };
  303. var prev = function (editor, currentIndexState) {
  304. var index = moveSelection(editor, currentIndexState, false);
  305. if (index !== -1) {
  306. currentIndexState.set(index);
  307. }
  308. };
  309. var isMatchSpan = function (node) {
  310. var matchIndex = getElmIndex(node);
  311. return matchIndex !== null && matchIndex.length > 0;
  312. };
  313. var replace = function (editor, currentIndexState, text, forward, all) {
  314. var i, nodes, node, matchIndex, currentMatchIndex, nextIndex = currentIndexState.get(), hasMore;
  315. forward = forward !== false;
  316. node = editor.getBody();
  317. nodes = global$1.grep(global$1.toArray(node.getElementsByTagName('span')), isMatchSpan);
  318. for (i = 0; i < nodes.length; i++) {
  319. var nodeIndex = getElmIndex(nodes[i]);
  320. matchIndex = currentMatchIndex = parseInt(nodeIndex, 10);
  321. if (all || matchIndex === currentIndexState.get()) {
  322. if (text.length) {
  323. nodes[i].firstChild.nodeValue = text;
  324. unwrap(nodes[i]);
  325. } else {
  326. removeNode(editor.dom, nodes[i]);
  327. }
  328. while (nodes[++i]) {
  329. matchIndex = parseInt(getElmIndex(nodes[i]), 10);
  330. if (matchIndex === currentMatchIndex) {
  331. removeNode(editor.dom, nodes[i]);
  332. } else {
  333. i--;
  334. break;
  335. }
  336. }
  337. if (forward) {
  338. nextIndex--;
  339. }
  340. } else if (currentMatchIndex > currentIndexState.get()) {
  341. nodes[i].setAttribute('data-mce-index', currentMatchIndex - 1);
  342. }
  343. }
  344. currentIndexState.set(nextIndex);
  345. if (forward) {
  346. hasMore = hasNext(editor, currentIndexState);
  347. next(editor, currentIndexState);
  348. } else {
  349. hasMore = hasPrev(editor, currentIndexState);
  350. prev(editor, currentIndexState);
  351. }
  352. return !all && hasMore;
  353. };
  354. var done = function (editor, currentIndexState, keepEditorSelection) {
  355. var i, nodes, startContainer, endContainer;
  356. nodes = global$1.toArray(editor.getBody().getElementsByTagName('span'));
  357. for (i = 0; i < nodes.length; i++) {
  358. var nodeIndex = getElmIndex(nodes[i]);
  359. if (nodeIndex !== null && nodeIndex.length) {
  360. if (nodeIndex === currentIndexState.get().toString()) {
  361. if (!startContainer) {
  362. startContainer = nodes[i].firstChild;
  363. }
  364. endContainer = nodes[i].firstChild;
  365. }
  366. unwrap(nodes[i]);
  367. }
  368. }
  369. if (startContainer && endContainer) {
  370. var rng = editor.dom.createRng();
  371. rng.setStart(startContainer, 0);
  372. rng.setEnd(endContainer, endContainer.data.length);
  373. if (keepEditorSelection !== false) {
  374. editor.selection.setRng(rng);
  375. }
  376. return rng;
  377. }
  378. };
  379. var hasNext = function (editor, currentIndexState) {
  380. return findSpansByIndex(editor, currentIndexState.get() + 1).length > 0;
  381. };
  382. var hasPrev = function (editor, currentIndexState) {
  383. return findSpansByIndex(editor, currentIndexState.get() - 1).length > 0;
  384. };
  385. var Actions = {
  386. done: done,
  387. find: find,
  388. next: next,
  389. prev: prev,
  390. replace: replace,
  391. hasNext: hasNext,
  392. hasPrev: hasPrev
  393. };
  394. var get = function (editor, currentIndexState) {
  395. var done = function (keepEditorSelection) {
  396. return Actions.done(editor, currentIndexState, keepEditorSelection);
  397. };
  398. var find = function (text, matchCase, wholeWord) {
  399. return Actions.find(editor, currentIndexState, text, matchCase, wholeWord);
  400. };
  401. var next = function () {
  402. return Actions.next(editor, currentIndexState);
  403. };
  404. var prev = function () {
  405. return Actions.prev(editor, currentIndexState);
  406. };
  407. var replace = function (text, forward, all) {
  408. return Actions.replace(editor, currentIndexState, text, forward, all);
  409. };
  410. return {
  411. done: done,
  412. find: find,
  413. next: next,
  414. prev: prev,
  415. replace: replace
  416. };
  417. };
  418. var Api = { get: get };
  419. var constant = function (value) {
  420. return function () {
  421. return value;
  422. };
  423. };
  424. var never = constant(false);
  425. var always = constant(true);
  426. var never$1 = never;
  427. var always$1 = always;
  428. var none = function () {
  429. return NONE;
  430. };
  431. var NONE = function () {
  432. var eq = function (o) {
  433. return o.isNone();
  434. };
  435. var call = function (thunk) {
  436. return thunk();
  437. };
  438. var id = function (n) {
  439. return n;
  440. };
  441. var noop = function () {
  442. };
  443. var nul = function () {
  444. return null;
  445. };
  446. var undef = function () {
  447. return undefined;
  448. };
  449. var me = {
  450. fold: function (n, s) {
  451. return n();
  452. },
  453. is: never$1,
  454. isSome: never$1,
  455. isNone: always$1,
  456. getOr: id,
  457. getOrThunk: call,
  458. getOrDie: function (msg) {
  459. throw new Error(msg || 'error: getOrDie called on none.');
  460. },
  461. getOrNull: nul,
  462. getOrUndefined: undef,
  463. or: id,
  464. orThunk: call,
  465. map: none,
  466. ap: none,
  467. each: noop,
  468. bind: none,
  469. flatten: none,
  470. exists: never$1,
  471. forall: always$1,
  472. filter: none,
  473. equals: eq,
  474. equals_: eq,
  475. toArray: function () {
  476. return [];
  477. },
  478. toString: constant('none()')
  479. };
  480. if (Object.freeze)
  481. Object.freeze(me);
  482. return me;
  483. }();
  484. var typeOf = function (x) {
  485. if (x === null)
  486. return 'null';
  487. var t = typeof x;
  488. if (t === 'object' && Array.prototype.isPrototypeOf(x))
  489. return 'array';
  490. if (t === 'object' && String.prototype.isPrototypeOf(x))
  491. return 'string';
  492. return t;
  493. };
  494. var isType = function (type) {
  495. return function (value) {
  496. return typeOf(value) === type;
  497. };
  498. };
  499. var isFunction = isType('function');
  500. var each = function (xs, f) {
  501. for (var i = 0, len = xs.length; i < len; i++) {
  502. var x = xs[i];
  503. f(x, i, xs);
  504. }
  505. };
  506. var slice = Array.prototype.slice;
  507. var from = isFunction(Array.from) ? Array.from : function (x) {
  508. return slice.call(x);
  509. };
  510. var open = function (editor, currentIndexState) {
  511. var last = {}, selectedText;
  512. editor.undoManager.add();
  513. selectedText = global$1.trim(editor.selection.getContent({ format: 'text' }));
  514. function updateButtonStates(api) {
  515. var updateNext = Actions.hasNext(editor, currentIndexState) ? api.enable : api.disable;
  516. updateNext('next');
  517. var updatePrev = Actions.hasPrev(editor, currentIndexState) ? api.enable : api.disable;
  518. updatePrev('prev');
  519. }
  520. var disableAll = function (api, disable) {
  521. var buttons = [
  522. 'replace',
  523. 'replaceall',
  524. 'prev',
  525. 'next'
  526. ];
  527. var toggle = disable ? api.disable : api.enable;
  528. each(buttons, toggle);
  529. };
  530. function notFoundAlert(api) {
  531. editor.windowManager.alert('Could not find the specified string.', function () {
  532. api.focus('findtext');
  533. });
  534. }
  535. var doSubmit = function (api) {
  536. var data = api.getData();
  537. if (!data.findtext.length) {
  538. Actions.done(editor, currentIndexState, false);
  539. disableAll(api, true);
  540. updateButtonStates(api);
  541. return;
  542. }
  543. if (last.text === data.findtext && last.caseState === data.matchcase && last.wholeWord === data.wholewords) {
  544. if (!Actions.hasNext(editor, currentIndexState)) {
  545. notFoundAlert(api);
  546. return;
  547. }
  548. Actions.next(editor, currentIndexState);
  549. updateButtonStates(api);
  550. return;
  551. }
  552. var count = Actions.find(editor, currentIndexState, data.findtext, data.matchcase, data.wholewords);
  553. if (!count) {
  554. notFoundAlert(api);
  555. }
  556. disableAll(api, count === 0);
  557. updateButtonStates(api);
  558. last = {
  559. text: data.findtext,
  560. caseState: data.matchcase,
  561. wholeWord: data.wholewords
  562. };
  563. };
  564. var initialData = {
  565. findtext: selectedText,
  566. replacetext: '',
  567. matchcase: false,
  568. wholewords: false
  569. };
  570. editor.windowManager.open({
  571. title: 'Find and Replace',
  572. size: 'normal',
  573. body: {
  574. type: 'panel',
  575. items: [
  576. {
  577. type: 'input',
  578. name: 'findtext',
  579. label: 'Find'
  580. },
  581. {
  582. type: 'input',
  583. name: 'replacetext',
  584. label: 'Replace with'
  585. },
  586. {
  587. type: 'grid',
  588. columns: 2,
  589. items: [
  590. {
  591. type: 'checkbox',
  592. name: 'matchcase',
  593. label: 'Match case'
  594. },
  595. {
  596. type: 'checkbox',
  597. name: 'wholewords',
  598. label: 'Find whole words only'
  599. }
  600. ]
  601. }
  602. ]
  603. },
  604. buttons: [
  605. {
  606. type: 'custom',
  607. name: 'find',
  608. text: 'Find',
  609. align: 'start',
  610. primary: true
  611. },
  612. {
  613. type: 'custom',
  614. name: 'replace',
  615. text: 'Replace',
  616. align: 'start',
  617. disabled: true
  618. },
  619. {
  620. type: 'custom',
  621. name: 'replaceall',
  622. text: 'Replace All',
  623. align: 'start',
  624. disabled: true
  625. },
  626. {
  627. type: 'custom',
  628. name: 'prev',
  629. text: 'Previous',
  630. align: 'end',
  631. icon: 'arrow-left',
  632. disabled: true
  633. },
  634. {
  635. type: 'custom',
  636. name: 'next',
  637. text: 'Next',
  638. align: 'end',
  639. icon: 'arrow-right',
  640. disabled: true
  641. }
  642. ],
  643. initialData: initialData,
  644. onAction: function (api, details) {
  645. var data = api.getData();
  646. switch (details.name) {
  647. case 'find':
  648. doSubmit(api);
  649. break;
  650. case 'replace':
  651. if (!Actions.replace(editor, currentIndexState, data.replacetext)) {
  652. disableAll(api, true);
  653. currentIndexState.set(-1);
  654. last = {};
  655. }
  656. break;
  657. case 'replaceall':
  658. Actions.replace(editor, currentIndexState, data.replacetext, true, true);
  659. disableAll(api, true);
  660. last = {};
  661. break;
  662. case 'prev':
  663. Actions.prev(editor, currentIndexState);
  664. updateButtonStates(api);
  665. break;
  666. case 'next':
  667. Actions.next(editor, currentIndexState);
  668. updateButtonStates(api);
  669. break;
  670. default:
  671. break;
  672. }
  673. },
  674. onSubmit: doSubmit,
  675. onClose: function () {
  676. editor.focus();
  677. Actions.done(editor, currentIndexState);
  678. editor.undoManager.add();
  679. }
  680. });
  681. };
  682. var Dialog = { open: open };
  683. var register = function (editor, currentIndexState) {
  684. editor.addCommand('SearchReplace', function () {
  685. Dialog.open(editor, currentIndexState);
  686. });
  687. };
  688. var Commands = { register: register };
  689. var showDialog = function (editor, currentIndexState) {
  690. return function () {
  691. Dialog.open(editor, currentIndexState);
  692. };
  693. };
  694. var register$1 = function (editor, currentIndexState) {
  695. editor.ui.registry.addMenuItem('searchreplace', {
  696. text: 'Find and replace...',
  697. shortcut: 'Meta+F',
  698. onAction: showDialog(editor, currentIndexState),
  699. icon: 'search'
  700. });
  701. editor.ui.registry.addButton('searchreplace', {
  702. tooltip: 'Find and replace',
  703. onAction: showDialog(editor, currentIndexState),
  704. icon: 'search'
  705. });
  706. editor.shortcuts.add('Meta+F', '', showDialog(editor, currentIndexState));
  707. };
  708. var Buttons = { register: register$1 };
  709. global.add('searchreplace', function (editor) {
  710. var currentIndexState = Cell(-1);
  711. Commands.register(editor, currentIndexState);
  712. Buttons.register(editor, currentIndexState);
  713. return Api.get(editor, currentIndexState);
  714. });
  715. function Plugin () {
  716. }
  717. return Plugin;
  718. }());
  719. })();