default_commands.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Distributed under the BSD license:
  3. *
  4. * Copyright (c) 2010, Ajax.org B.V.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * * Neither the name of Ajax.org B.V. nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * ***** END LICENSE BLOCK ***** */
  30. define(function(require, exports, module) {
  31. "use strict";
  32. var lang = require("../lib/lang");
  33. var config = require("../config");
  34. function bindKey(win, mac) {
  35. return {win: win, mac: mac};
  36. }
  37. /*
  38. multiSelectAction: "forEach"|"forEachLine"|function|undefined,
  39. scrollIntoView: true|"cursor"|"center"|"selectionPart"
  40. */
  41. exports.commands = [{
  42. name: "showSettingsMenu",
  43. bindKey: bindKey("Ctrl-,", "Command-,"),
  44. exec: function(editor) {
  45. config.loadModule("ace/ext/settings_menu", function(module) {
  46. module.init(editor);
  47. editor.showSettingsMenu();
  48. });
  49. },
  50. readOnly: true
  51. }, {
  52. name: "selectall",
  53. bindKey: bindKey("Ctrl-A", "Command-A"),
  54. exec: function(editor) { editor.selectAll(); },
  55. readOnly: true
  56. }, {
  57. name: "centerselection",
  58. bindKey: bindKey(null, "Ctrl-L"),
  59. exec: function(editor) { editor.centerSelection(); },
  60. readOnly: true
  61. }, {
  62. name: "gotoline",
  63. bindKey: bindKey("Ctrl-L", "Command-L"),
  64. exec: function(editor) {
  65. var line = parseInt(prompt("Enter line number:"), 10);
  66. if (!isNaN(line)) {
  67. editor.gotoLine(line);
  68. }
  69. },
  70. readOnly: true
  71. }, {
  72. name: "fold",
  73. bindKey: bindKey("Alt-L|Ctrl-F1", "Command-Alt-L|Command-F1"),
  74. exec: function(editor) { editor.session.toggleFold(false); },
  75. scrollIntoView: "center",
  76. readOnly: true
  77. }, {
  78. name: "unfold",
  79. bindKey: bindKey("Alt-Shift-L|Ctrl-Shift-F1", "Command-Alt-Shift-L|Command-Shift-F1"),
  80. exec: function(editor) { editor.session.toggleFold(true); },
  81. scrollIntoView: "center",
  82. readOnly: true
  83. }, {
  84. name: "toggleFoldWidget",
  85. bindKey: bindKey("F2", "F2"),
  86. exec: function(editor) { editor.session.toggleFoldWidget(); },
  87. scrollIntoView: "center",
  88. readOnly: true
  89. }, {
  90. name: "toggleParentFoldWidget",
  91. bindKey: bindKey("Alt-F2", "Alt-F2"),
  92. exec: function(editor) { editor.session.toggleFoldWidget(true); },
  93. scrollIntoView: "center",
  94. readOnly: true
  95. }, {
  96. name: "foldall",
  97. bindKey: bindKey("Ctrl-Alt-0", "Ctrl-Command-Option-0"),
  98. exec: function(editor) { editor.session.foldAll(); },
  99. scrollIntoView: "center",
  100. readOnly: true
  101. }, {
  102. name: "foldOther",
  103. bindKey: bindKey("Alt-0", "Command-Option-0"),
  104. exec: function(editor) {
  105. editor.session.foldAll();
  106. editor.session.unfold(editor.selection.getAllRanges());
  107. },
  108. scrollIntoView: "center",
  109. readOnly: true
  110. }, {
  111. name: "unfoldall",
  112. bindKey: bindKey("Alt-Shift-0", "Command-Option-Shift-0"),
  113. exec: function(editor) { editor.session.unfold(); },
  114. scrollIntoView: "center",
  115. readOnly: true
  116. }, {
  117. name: "findnext",
  118. bindKey: bindKey("Ctrl-K", "Command-G"),
  119. exec: function(editor) { editor.findNext(); },
  120. readOnly: true
  121. }, {
  122. name: "findprevious",
  123. bindKey: bindKey("Ctrl-Shift-K", "Command-Shift-G"),
  124. exec: function(editor) { editor.findPrevious(); },
  125. readOnly: true
  126. }, {
  127. name: "selectOrFindNext",
  128. bindKey: bindKey("ALt-K", "Ctrl-G"),
  129. exec: function(editor) {
  130. if (editor.selection.isEmpty())
  131. editor.selection.selectWord();
  132. else
  133. editor.findNext();
  134. },
  135. readOnly: true
  136. }, {
  137. name: "selectOrFindPrevious",
  138. bindKey: bindKey("Alt-Shift-K", "Ctrl-Shift-G"),
  139. exec: function(editor) {
  140. if (editor.selection.isEmpty())
  141. editor.selection.selectWord();
  142. else
  143. editor.findPrevious();
  144. },
  145. readOnly: true
  146. }, {
  147. name: "find",
  148. bindKey: bindKey("Ctrl-F", "Command-F"),
  149. exec: function(editor) {
  150. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor)});
  151. },
  152. readOnly: true
  153. }, {
  154. name: "overwrite",
  155. bindKey: "Insert",
  156. exec: function(editor) { editor.toggleOverwrite(); },
  157. readOnly: true
  158. }, {
  159. name: "selecttostart",
  160. bindKey: bindKey("Ctrl-Shift-Home", "Command-Shift-Up"),
  161. exec: function(editor) { editor.getSelection().selectFileStart(); },
  162. multiSelectAction: "forEach",
  163. readOnly: true,
  164. aceCommandGroup: "fileJump"
  165. }, {
  166. name: "gotostart",
  167. bindKey: bindKey("Ctrl-Home", "Command-Home|Command-Up"),
  168. exec: function(editor) { editor.navigateFileStart(); },
  169. multiSelectAction: "forEach",
  170. readOnly: true,
  171. aceCommandGroup: "fileJump"
  172. }, {
  173. name: "selectup",
  174. bindKey: bindKey("Shift-Up", "Shift-Up"),
  175. exec: function(editor) { editor.getSelection().selectUp(); },
  176. multiSelectAction: "forEach",
  177. readOnly: true
  178. }, {
  179. name: "golineup",
  180. bindKey: bindKey("Up", "Up|Ctrl-P"),
  181. exec: function(editor, args) { editor.navigateUp(args.times); },
  182. multiSelectAction: "forEach",
  183. readOnly: true
  184. }, {
  185. name: "selecttoend",
  186. bindKey: bindKey("Ctrl-Shift-End", "Command-Shift-Down"),
  187. exec: function(editor) { editor.getSelection().selectFileEnd(); },
  188. multiSelectAction: "forEach",
  189. readOnly: true,
  190. aceCommandGroup: "fileJump"
  191. }, {
  192. name: "gotoend",
  193. bindKey: bindKey("Ctrl-End", "Command-End|Command-Down"),
  194. exec: function(editor) { editor.navigateFileEnd(); },
  195. multiSelectAction: "forEach",
  196. readOnly: true,
  197. aceCommandGroup: "fileJump"
  198. }, {
  199. name: "selectdown",
  200. bindKey: bindKey("Shift-Down", "Shift-Down"),
  201. exec: function(editor) { editor.getSelection().selectDown(); },
  202. multiSelectAction: "forEach",
  203. readOnly: true
  204. }, {
  205. name: "golinedown",
  206. bindKey: bindKey("Down", "Down|Ctrl-N"),
  207. exec: function(editor, args) { editor.navigateDown(args.times); },
  208. multiSelectAction: "forEach",
  209. readOnly: true
  210. }, {
  211. name: "selectwordleft",
  212. bindKey: bindKey("Ctrl-Shift-Left", "Option-Shift-Left"),
  213. exec: function(editor) { editor.getSelection().selectWordLeft(); },
  214. multiSelectAction: "forEach",
  215. readOnly: true
  216. }, {
  217. name: "gotowordleft",
  218. bindKey: bindKey("Ctrl-Left", "Option-Left"),
  219. exec: function(editor) { editor.navigateWordLeft(); },
  220. multiSelectAction: "forEach",
  221. readOnly: true
  222. }, {
  223. name: "selecttolinestart",
  224. bindKey: bindKey("Alt-Shift-Left", "Command-Shift-Left"),
  225. exec: function(editor) { editor.getSelection().selectLineStart(); },
  226. multiSelectAction: "forEach",
  227. readOnly: true
  228. }, {
  229. name: "gotolinestart",
  230. bindKey: bindKey("Alt-Left|Home", "Command-Left|Home|Ctrl-A"),
  231. exec: function(editor) { editor.navigateLineStart(); },
  232. multiSelectAction: "forEach",
  233. readOnly: true
  234. }, {
  235. name: "selectleft",
  236. bindKey: bindKey("Shift-Left", "Shift-Left"),
  237. exec: function(editor) { editor.getSelection().selectLeft(); },
  238. multiSelectAction: "forEach",
  239. readOnly: true
  240. }, {
  241. name: "gotoleft",
  242. bindKey: bindKey("Left", "Left|Ctrl-B"),
  243. exec: function(editor, args) { editor.navigateLeft(args.times); },
  244. multiSelectAction: "forEach",
  245. readOnly: true
  246. }, {
  247. name: "selectwordright",
  248. bindKey: bindKey("Ctrl-Shift-Right", "Option-Shift-Right"),
  249. exec: function(editor) { editor.getSelection().selectWordRight(); },
  250. multiSelectAction: "forEach",
  251. readOnly: true
  252. }, {
  253. name: "gotowordright",
  254. bindKey: bindKey("Ctrl-Right", "Option-Right"),
  255. exec: function(editor) { editor.navigateWordRight(); },
  256. multiSelectAction: "forEach",
  257. readOnly: true
  258. }, {
  259. name: "selecttolineend",
  260. bindKey: bindKey("Alt-Shift-Right", "Command-Shift-Right"),
  261. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  262. multiSelectAction: "forEach",
  263. readOnly: true
  264. }, {
  265. name: "gotolineend",
  266. bindKey: bindKey("Alt-Right|End", "Command-Right|End|Ctrl-E"),
  267. exec: function(editor) { editor.navigateLineEnd(); },
  268. multiSelectAction: "forEach",
  269. readOnly: true
  270. }, {
  271. name: "selectright",
  272. bindKey: bindKey("Shift-Right", "Shift-Right"),
  273. exec: function(editor) { editor.getSelection().selectRight(); },
  274. multiSelectAction: "forEach",
  275. readOnly: true
  276. }, {
  277. name: "gotoright",
  278. bindKey: bindKey("Right", "Right|Ctrl-F"),
  279. exec: function(editor, args) { editor.navigateRight(args.times); },
  280. multiSelectAction: "forEach",
  281. readOnly: true
  282. }, {
  283. name: "selectpagedown",
  284. bindKey: "Shift-PageDown",
  285. exec: function(editor) { editor.selectPageDown(); },
  286. readOnly: true
  287. }, {
  288. name: "pagedown",
  289. bindKey: bindKey(null, "Option-PageDown"),
  290. exec: function(editor) { editor.scrollPageDown(); },
  291. readOnly: true
  292. }, {
  293. name: "gotopagedown",
  294. bindKey: bindKey("PageDown", "PageDown|Ctrl-V"),
  295. exec: function(editor) { editor.gotoPageDown(); },
  296. readOnly: true
  297. }, {
  298. name: "selectpageup",
  299. bindKey: "Shift-PageUp",
  300. exec: function(editor) { editor.selectPageUp(); },
  301. readOnly: true
  302. }, {
  303. name: "pageup",
  304. bindKey: bindKey(null, "Option-PageUp"),
  305. exec: function(editor) { editor.scrollPageUp(); },
  306. readOnly: true
  307. }, {
  308. name: "gotopageup",
  309. bindKey: "PageUp",
  310. exec: function(editor) { editor.gotoPageUp(); },
  311. readOnly: true
  312. }, {
  313. name: "scrollup",
  314. bindKey: bindKey("Ctrl-Up", null),
  315. exec: function(e) { e.renderer.scrollBy(0, -2 * e.renderer.layerConfig.lineHeight); },
  316. readOnly: true
  317. }, {
  318. name: "scrolldown",
  319. bindKey: bindKey("Ctrl-Down", null),
  320. exec: function(e) { e.renderer.scrollBy(0, 2 * e.renderer.layerConfig.lineHeight); },
  321. readOnly: true
  322. }, {
  323. name: "selectlinestart",
  324. bindKey: "Shift-Home",
  325. exec: function(editor) { editor.getSelection().selectLineStart(); },
  326. multiSelectAction: "forEach",
  327. readOnly: true
  328. }, {
  329. name: "selectlineend",
  330. bindKey: "Shift-End",
  331. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  332. multiSelectAction: "forEach",
  333. readOnly: true
  334. }, {
  335. name: "togglerecording",
  336. bindKey: bindKey("Ctrl-Alt-E", "Command-Option-E"),
  337. exec: function(editor) { editor.commands.toggleRecording(editor); },
  338. readOnly: true
  339. }, {
  340. name: "replaymacro",
  341. bindKey: bindKey("Ctrl-Shift-E", "Command-Shift-E"),
  342. exec: function(editor) { editor.commands.replay(editor); },
  343. readOnly: true
  344. }, {
  345. name: "jumptomatching",
  346. bindKey: bindKey("Ctrl-P", "Ctrl-Shift-P"),
  347. exec: function(editor) { editor.jumpToMatching(); },
  348. multiSelectAction: "forEach",
  349. readOnly: true
  350. }, {
  351. name: "selecttomatching",
  352. bindKey: bindKey("Ctrl-Shift-P", null),
  353. exec: function(editor) { editor.jumpToMatching(true); },
  354. multiSelectAction: "forEach",
  355. readOnly: true
  356. },
  357. // commands disabled in readOnly mode
  358. {
  359. name: "cut",
  360. exec: function(editor) {
  361. var range = editor.getSelectionRange();
  362. editor._emit("cut", range);
  363. if (!editor.selection.isEmpty()) {
  364. editor.session.remove(range);
  365. editor.clearSelection();
  366. }
  367. },
  368. multiSelectAction: "forEach"
  369. }, {
  370. name: "removeline",
  371. bindKey: bindKey("Ctrl-D", "Command-D"),
  372. exec: function(editor) { editor.removeLines(); },
  373. multiSelectAction: "forEachLine"
  374. }, {
  375. name: "duplicateSelection",
  376. bindKey: bindKey("Ctrl-Shift-D", "Command-Shift-D"),
  377. exec: function(editor) { editor.duplicateSelection(); },
  378. multiSelectAction: "forEach"
  379. }, {
  380. name: "sortlines",
  381. bindKey: bindKey("Ctrl-Alt-S", "Command-Alt-S"),
  382. exec: function(editor) { editor.sortLines(); },
  383. multiSelectAction: "forEachLine"
  384. }, {
  385. name: "togglecomment",
  386. bindKey: bindKey("Ctrl-/", "Command-/"),
  387. exec: function(editor) { editor.toggleCommentLines(); },
  388. multiSelectAction: "forEachLine",
  389. scrollIntoView: "selectionPart"
  390. }, {
  391. name: "toggleBlockComment",
  392. bindKey: bindKey("Ctrl-Shift-/", "Command-Shift-/"),
  393. exec: function(editor) { editor.toggleBlockComment(); },
  394. multiSelectAction: "forEach"
  395. }, {
  396. name: "modifyNumberUp",
  397. bindKey: bindKey("Ctrl-Shift-Up", "Alt-Shift-Up"),
  398. exec: function(editor) { editor.modifyNumber(1); },
  399. multiSelectAction: "forEach"
  400. }, {
  401. name: "modifyNumberDown",
  402. bindKey: bindKey("Ctrl-Shift-Down", "Alt-Shift-Down"),
  403. exec: function(editor) { editor.modifyNumber(-1); },
  404. multiSelectAction: "forEach"
  405. }, {
  406. name: "replace",
  407. bindKey: bindKey("Ctrl-H", "Command-Option-F"),
  408. exec: function(editor) {
  409. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor, true)});
  410. }
  411. }, {
  412. name: "undo",
  413. bindKey: bindKey("Ctrl-Z", "Command-Z"),
  414. exec: function(editor) { editor.undo(); }
  415. }, {
  416. name: "redo",
  417. bindKey: bindKey("Ctrl-Shift-Z|Ctrl-Y", "Command-Shift-Z|Command-Y"),
  418. exec: function(editor) { editor.redo(); }
  419. }, {
  420. name: "copylinesup",
  421. bindKey: bindKey("Alt-Shift-Up", "Command-Option-Up"),
  422. exec: function(editor) { editor.copyLinesUp(); }
  423. }, {
  424. name: "movelinesup",
  425. bindKey: bindKey("Alt-Up", "Option-Up"),
  426. exec: function(editor) { editor.moveLinesUp(); }
  427. }, {
  428. name: "copylinesdown",
  429. bindKey: bindKey("Alt-Shift-Down", "Command-Option-Down"),
  430. exec: function(editor) { editor.copyLinesDown(); }
  431. }, {
  432. name: "movelinesdown",
  433. bindKey: bindKey("Alt-Down", "Option-Down"),
  434. exec: function(editor) { editor.moveLinesDown(); }
  435. }, {
  436. name: "del",
  437. bindKey: bindKey("Delete", "Delete|Ctrl-D|Shift-Delete"),
  438. exec: function(editor) { editor.remove("right"); },
  439. multiSelectAction: "forEach"
  440. }, {
  441. name: "backspace",
  442. bindKey: bindKey(
  443. "Shift-Backspace|Backspace",
  444. "Ctrl-Backspace|Shift-Backspace|Backspace|Ctrl-H"
  445. ),
  446. exec: function(editor) { editor.remove("left"); },
  447. multiSelectAction: "forEach"
  448. }, {
  449. name: "cut_or_delete",
  450. bindKey: bindKey("Shift-Delete", null),
  451. exec: function(editor) {
  452. if (editor.selection.isEmpty()) {
  453. editor.remove("left");
  454. } else {
  455. return false;
  456. }
  457. },
  458. multiSelectAction: "forEach"
  459. }, {
  460. name: "removetolinestart",
  461. bindKey: bindKey("Alt-Backspace", "Command-Backspace"),
  462. exec: function(editor) { editor.removeToLineStart(); },
  463. multiSelectAction: "forEach"
  464. }, {
  465. name: "removetolineend",
  466. bindKey: bindKey("Alt-Delete", "Ctrl-K"),
  467. exec: function(editor) { editor.removeToLineEnd(); },
  468. multiSelectAction: "forEach"
  469. }, {
  470. name: "removewordleft",
  471. bindKey: bindKey("Ctrl-Backspace", "Alt-Backspace|Ctrl-Alt-Backspace"),
  472. exec: function(editor) { editor.removeWordLeft(); },
  473. multiSelectAction: "forEach"
  474. }, {
  475. name: "removewordright",
  476. bindKey: bindKey("Ctrl-Delete", "Alt-Delete"),
  477. exec: function(editor) { editor.removeWordRight(); },
  478. multiSelectAction: "forEach"
  479. }, {
  480. name: "outdent",
  481. bindKey: bindKey("Shift-Tab", "Shift-Tab"),
  482. exec: function(editor) { editor.blockOutdent(); },
  483. multiSelectAction: "forEach",
  484. scrollIntoView: "selectionPart"
  485. }, {
  486. name: "indent",
  487. bindKey: bindKey("Tab", "Tab"),
  488. exec: function(editor) { editor.indent(); },
  489. multiSelectAction: "forEach",
  490. scrollIntoView: "selectionPart"
  491. }, {
  492. name: "blockoutdent",
  493. bindKey: bindKey("Ctrl-[", "Ctrl-["),
  494. exec: function(editor) { editor.blockOutdent(); },
  495. multiSelectAction: "forEachLine",
  496. scrollIntoView: "selectionPart"
  497. }, {
  498. name: "blockindent",
  499. bindKey: bindKey("Ctrl-]", "Ctrl-]"),
  500. exec: function(editor) { editor.blockIndent(); },
  501. multiSelectAction: "forEachLine",
  502. scrollIntoView: "selectionPart"
  503. }, {
  504. name: "insertstring",
  505. exec: function(editor, str) { editor.insert(str); },
  506. multiSelectAction: "forEach",
  507. scrollIntoView: "cursor"
  508. }, {
  509. name: "inserttext",
  510. exec: function(editor, args) {
  511. editor.insert(lang.stringRepeat(args.text || "", args.times || 1));
  512. },
  513. multiSelectAction: "forEach"
  514. }, {
  515. name: "splitline",
  516. bindKey: bindKey(null, "Ctrl-O"),
  517. exec: function(editor) { editor.splitLine(); },
  518. multiSelectAction: "forEach"
  519. }, {
  520. name: "transposeletters",
  521. bindKey: bindKey("Ctrl-T", "Ctrl-T"),
  522. exec: function(editor) { editor.transposeLetters(); },
  523. multiSelectAction: function(editor) {editor.transposeSelections(1); }
  524. }, {
  525. name: "touppercase",
  526. bindKey: bindKey("Ctrl-U", "Ctrl-U"),
  527. exec: function(editor) { editor.toUpperCase(); },
  528. multiSelectAction: "forEach"
  529. }, {
  530. name: "tolowercase",
  531. bindKey: bindKey("Ctrl-Shift-U", "Ctrl-Shift-U"),
  532. exec: function(editor) { editor.toLowerCase(); },
  533. multiSelectAction: "forEach"
  534. }];
  535. });