default_commands.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  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. var Range = require("../range").Range;
  35. function bindKey(win, mac) {
  36. return {win: win, mac: mac};
  37. }
  38. /*
  39. multiSelectAction: "forEach"|"forEachLine"|function|undefined,
  40. scrollIntoView: true|"cursor"|"center"|"selectionPart"
  41. */
  42. exports.commands = [{
  43. name: "showSettingsMenu",
  44. bindKey: bindKey("Ctrl-,", "Command-,"),
  45. exec: function(editor) {
  46. config.loadModule("ace/ext/settings_menu", function(module) {
  47. module.init(editor);
  48. editor.showSettingsMenu();
  49. });
  50. },
  51. readOnly: true
  52. }, {
  53. name: "goToNextError",
  54. bindKey: bindKey("Alt-E", "Ctrl-E"),
  55. exec: function(editor) {
  56. config.loadModule("ace/ext/error_marker", function(module) {
  57. module.showErrorMarker(editor, 1);
  58. });
  59. },
  60. scrollIntoView: "animate",
  61. readOnly: true
  62. }, {
  63. name: "goToPreviousError",
  64. bindKey: bindKey("Alt-Shift-E", "Ctrl-Shift-E"),
  65. exec: function(editor) {
  66. config.loadModule("ace/ext/error_marker", function(module) {
  67. module.showErrorMarker(editor, -1);
  68. });
  69. },
  70. scrollIntoView: "animate",
  71. readOnly: true
  72. }, {
  73. name: "selectall",
  74. bindKey: bindKey("Ctrl-A", "Command-A"),
  75. exec: function(editor) { editor.selectAll(); },
  76. readOnly: true
  77. }, {
  78. name: "centerselection",
  79. bindKey: bindKey(null, "Ctrl-L"),
  80. exec: function(editor) { editor.centerSelection(); },
  81. readOnly: true
  82. }, {
  83. name: "gotoline",
  84. bindKey: bindKey("Ctrl-L", "Command-L"),
  85. exec: function(editor) {
  86. var line = parseInt(prompt("Enter line number:"), 10);
  87. if (!isNaN(line)) {
  88. editor.gotoLine(line);
  89. }
  90. },
  91. readOnly: true
  92. }, {
  93. name: "fold",
  94. bindKey: bindKey("Alt-L|Ctrl-F1", "Command-Alt-L|Command-F1"),
  95. exec: function(editor) { editor.session.toggleFold(false); },
  96. multiSelectAction: "forEach",
  97. scrollIntoView: "center",
  98. readOnly: true
  99. }, {
  100. name: "unfold",
  101. bindKey: bindKey("Alt-Shift-L|Ctrl-Shift-F1", "Command-Alt-Shift-L|Command-Shift-F1"),
  102. exec: function(editor) { editor.session.toggleFold(true); },
  103. multiSelectAction: "forEach",
  104. scrollIntoView: "center",
  105. readOnly: true
  106. }, {
  107. name: "toggleFoldWidget",
  108. bindKey: bindKey("F2", "F2"),
  109. exec: function(editor) { editor.session.toggleFoldWidget(); },
  110. multiSelectAction: "forEach",
  111. scrollIntoView: "center",
  112. readOnly: true
  113. }, {
  114. name: "toggleParentFoldWidget",
  115. bindKey: bindKey("Alt-F2", "Alt-F2"),
  116. exec: function(editor) { editor.session.toggleFoldWidget(true); },
  117. multiSelectAction: "forEach",
  118. scrollIntoView: "center",
  119. readOnly: true
  120. }, {
  121. name: "foldall",
  122. bindKey: bindKey(null, "Ctrl-Command-Option-0"),
  123. exec: function(editor) { editor.session.foldAll(); },
  124. scrollIntoView: "center",
  125. readOnly: true
  126. }, {
  127. name: "foldOther",
  128. bindKey: bindKey("Alt-0", "Command-Option-0"),
  129. exec: function(editor) {
  130. editor.session.foldAll();
  131. editor.session.unfold(editor.selection.getAllRanges());
  132. },
  133. scrollIntoView: "center",
  134. readOnly: true
  135. }, {
  136. name: "unfoldall",
  137. bindKey: bindKey("Alt-Shift-0", "Command-Option-Shift-0"),
  138. exec: function(editor) { editor.session.unfold(); },
  139. scrollIntoView: "center",
  140. readOnly: true
  141. }, {
  142. name: "findnext",
  143. bindKey: bindKey("Ctrl-K", "Command-G"),
  144. exec: function(editor) { editor.findNext(); },
  145. multiSelectAction: "forEach",
  146. scrollIntoView: "center",
  147. readOnly: true
  148. }, {
  149. name: "findprevious",
  150. bindKey: bindKey("Ctrl-Shift-K", "Command-Shift-G"),
  151. exec: function(editor) { editor.findPrevious(); },
  152. multiSelectAction: "forEach",
  153. scrollIntoView: "center",
  154. readOnly: true
  155. }, {
  156. name: "selectOrFindNext",
  157. bindKey: bindKey("Alt-K", "Ctrl-G"),
  158. exec: function(editor) {
  159. if (editor.selection.isEmpty())
  160. editor.selection.selectWord();
  161. else
  162. editor.findNext();
  163. },
  164. readOnly: true
  165. }, {
  166. name: "selectOrFindPrevious",
  167. bindKey: bindKey("Alt-Shift-K", "Ctrl-Shift-G"),
  168. exec: function(editor) {
  169. if (editor.selection.isEmpty())
  170. editor.selection.selectWord();
  171. else
  172. editor.findPrevious();
  173. },
  174. readOnly: true
  175. }, {
  176. name: "find",
  177. bindKey: bindKey("Ctrl-F", "Command-F"),
  178. exec: function(editor) {
  179. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor)});
  180. },
  181. readOnly: true
  182. }, {
  183. name: "overwrite",
  184. bindKey: "Insert",
  185. exec: function(editor) { editor.toggleOverwrite(); },
  186. readOnly: true
  187. }, {
  188. name: "selecttostart",
  189. bindKey: bindKey("Ctrl-Shift-Home", "Command-Shift-Up"),
  190. exec: function(editor) { editor.getSelection().selectFileStart(); },
  191. multiSelectAction: "forEach",
  192. readOnly: true,
  193. scrollIntoView: "animate",
  194. aceCommandGroup: "fileJump"
  195. }, {
  196. name: "gotostart",
  197. bindKey: bindKey("Ctrl-Home", "Command-Home|Command-Up"),
  198. exec: function(editor) { editor.navigateFileStart(); },
  199. multiSelectAction: "forEach",
  200. readOnly: true,
  201. scrollIntoView: "animate",
  202. aceCommandGroup: "fileJump"
  203. }, {
  204. name: "selectup",
  205. bindKey: bindKey("Shift-Up", "Shift-Up"),
  206. exec: function(editor) { editor.getSelection().selectUp(); },
  207. multiSelectAction: "forEach",
  208. scrollIntoView: "cursor",
  209. readOnly: true
  210. }, {
  211. name: "golineup",
  212. bindKey: bindKey("Up", "Up|Ctrl-P"),
  213. exec: function(editor, args) { editor.navigateUp(args.times); },
  214. multiSelectAction: "forEach",
  215. scrollIntoView: "cursor",
  216. readOnly: true
  217. }, {
  218. name: "selecttoend",
  219. bindKey: bindKey("Ctrl-Shift-End", "Command-Shift-Down"),
  220. exec: function(editor) { editor.getSelection().selectFileEnd(); },
  221. multiSelectAction: "forEach",
  222. readOnly: true,
  223. scrollIntoView: "animate",
  224. aceCommandGroup: "fileJump"
  225. }, {
  226. name: "gotoend",
  227. bindKey: bindKey("Ctrl-End", "Command-End|Command-Down"),
  228. exec: function(editor) { editor.navigateFileEnd(); },
  229. multiSelectAction: "forEach",
  230. readOnly: true,
  231. scrollIntoView: "animate",
  232. aceCommandGroup: "fileJump"
  233. }, {
  234. name: "selectdown",
  235. bindKey: bindKey("Shift-Down", "Shift-Down"),
  236. exec: function(editor) { editor.getSelection().selectDown(); },
  237. multiSelectAction: "forEach",
  238. scrollIntoView: "cursor",
  239. readOnly: true
  240. }, {
  241. name: "golinedown",
  242. bindKey: bindKey("Down", "Down|Ctrl-N"),
  243. exec: function(editor, args) { editor.navigateDown(args.times); },
  244. multiSelectAction: "forEach",
  245. scrollIntoView: "cursor",
  246. readOnly: true
  247. }, {
  248. name: "selectwordleft",
  249. bindKey: bindKey("Ctrl-Shift-Left", "Option-Shift-Left"),
  250. exec: function(editor) { editor.getSelection().selectWordLeft(); },
  251. multiSelectAction: "forEach",
  252. scrollIntoView: "cursor",
  253. readOnly: true
  254. }, {
  255. name: "gotowordleft",
  256. bindKey: bindKey("Ctrl-Left", "Option-Left"),
  257. exec: function(editor) { editor.navigateWordLeft(); },
  258. multiSelectAction: "forEach",
  259. scrollIntoView: "cursor",
  260. readOnly: true
  261. }, {
  262. name: "selecttolinestart",
  263. bindKey: bindKey("Alt-Shift-Left", "Command-Shift-Left"),
  264. exec: function(editor) { editor.getSelection().selectLineStart(); },
  265. multiSelectAction: "forEach",
  266. scrollIntoView: "cursor",
  267. readOnly: true
  268. }, {
  269. name: "gotolinestart",
  270. bindKey: bindKey("Alt-Left|Home", "Command-Left|Home|Ctrl-A"),
  271. exec: function(editor) { editor.navigateLineStart(); },
  272. multiSelectAction: "forEach",
  273. scrollIntoView: "cursor",
  274. readOnly: true
  275. }, {
  276. name: "selectleft",
  277. bindKey: bindKey("Shift-Left", "Shift-Left"),
  278. exec: function(editor) { editor.getSelection().selectLeft(); },
  279. multiSelectAction: "forEach",
  280. scrollIntoView: "cursor",
  281. readOnly: true
  282. }, {
  283. name: "gotoleft",
  284. bindKey: bindKey("Left", "Left|Ctrl-B"),
  285. exec: function(editor, args) { editor.navigateLeft(args.times); },
  286. multiSelectAction: "forEach",
  287. scrollIntoView: "cursor",
  288. readOnly: true
  289. }, {
  290. name: "selectwordright",
  291. bindKey: bindKey("Ctrl-Shift-Right", "Option-Shift-Right"),
  292. exec: function(editor) { editor.getSelection().selectWordRight(); },
  293. multiSelectAction: "forEach",
  294. scrollIntoView: "cursor",
  295. readOnly: true
  296. }, {
  297. name: "gotowordright",
  298. bindKey: bindKey("Ctrl-Right", "Option-Right"),
  299. exec: function(editor) { editor.navigateWordRight(); },
  300. multiSelectAction: "forEach",
  301. scrollIntoView: "cursor",
  302. readOnly: true
  303. }, {
  304. name: "selecttolineend",
  305. bindKey: bindKey("Alt-Shift-Right", "Command-Shift-Right"),
  306. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  307. multiSelectAction: "forEach",
  308. scrollIntoView: "cursor",
  309. readOnly: true
  310. }, {
  311. name: "gotolineend",
  312. bindKey: bindKey("Alt-Right|End", "Command-Right|End|Ctrl-E"),
  313. exec: function(editor) { editor.navigateLineEnd(); },
  314. multiSelectAction: "forEach",
  315. scrollIntoView: "cursor",
  316. readOnly: true
  317. }, {
  318. name: "selectright",
  319. bindKey: bindKey("Shift-Right", "Shift-Right"),
  320. exec: function(editor) { editor.getSelection().selectRight(); },
  321. multiSelectAction: "forEach",
  322. scrollIntoView: "cursor",
  323. readOnly: true
  324. }, {
  325. name: "gotoright",
  326. bindKey: bindKey("Right", "Right|Ctrl-F"),
  327. exec: function(editor, args) { editor.navigateRight(args.times); },
  328. multiSelectAction: "forEach",
  329. scrollIntoView: "cursor",
  330. readOnly: true
  331. }, {
  332. name: "selectpagedown",
  333. bindKey: "Shift-PageDown",
  334. exec: function(editor) { editor.selectPageDown(); },
  335. readOnly: true
  336. }, {
  337. name: "pagedown",
  338. bindKey: bindKey(null, "Option-PageDown"),
  339. exec: function(editor) { editor.scrollPageDown(); },
  340. readOnly: true
  341. }, {
  342. name: "gotopagedown",
  343. bindKey: bindKey("PageDown", "PageDown|Ctrl-V"),
  344. exec: function(editor) { editor.gotoPageDown(); },
  345. readOnly: true
  346. }, {
  347. name: "selectpageup",
  348. bindKey: "Shift-PageUp",
  349. exec: function(editor) { editor.selectPageUp(); },
  350. readOnly: true
  351. }, {
  352. name: "pageup",
  353. bindKey: bindKey(null, "Option-PageUp"),
  354. exec: function(editor) { editor.scrollPageUp(); },
  355. readOnly: true
  356. }, {
  357. name: "gotopageup",
  358. bindKey: "PageUp",
  359. exec: function(editor) { editor.gotoPageUp(); },
  360. readOnly: true
  361. }, {
  362. name: "scrollup",
  363. bindKey: bindKey("Ctrl-Up", null),
  364. exec: function(e) { e.renderer.scrollBy(0, -2 * e.renderer.layerConfig.lineHeight); },
  365. readOnly: true
  366. }, {
  367. name: "scrolldown",
  368. bindKey: bindKey("Ctrl-Down", null),
  369. exec: function(e) { e.renderer.scrollBy(0, 2 * e.renderer.layerConfig.lineHeight); },
  370. readOnly: true
  371. }, {
  372. name: "selectlinestart",
  373. bindKey: "Shift-Home",
  374. exec: function(editor) { editor.getSelection().selectLineStart(); },
  375. multiSelectAction: "forEach",
  376. scrollIntoView: "cursor",
  377. readOnly: true
  378. }, {
  379. name: "selectlineend",
  380. bindKey: "Shift-End",
  381. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  382. multiSelectAction: "forEach",
  383. scrollIntoView: "cursor",
  384. readOnly: true
  385. }, {
  386. name: "togglerecording",
  387. bindKey: bindKey("Ctrl-Alt-E", "Command-Option-E"),
  388. exec: function(editor) { editor.commands.toggleRecording(editor); },
  389. readOnly: true
  390. }, {
  391. name: "replaymacro",
  392. bindKey: bindKey("Ctrl-Shift-E", "Command-Shift-E"),
  393. exec: function(editor) { editor.commands.replay(editor); },
  394. readOnly: true
  395. }, {
  396. name: "jumptomatching",
  397. bindKey: bindKey("Ctrl-P", "Ctrl-P"),
  398. exec: function(editor) { editor.jumpToMatching(); },
  399. multiSelectAction: "forEach",
  400. scrollIntoView: "animate",
  401. readOnly: true
  402. }, {
  403. name: "selecttomatching",
  404. bindKey: bindKey("Ctrl-Shift-P", "Ctrl-Shift-P"),
  405. exec: function(editor) { editor.jumpToMatching(true); },
  406. multiSelectAction: "forEach",
  407. scrollIntoView: "animate",
  408. readOnly: true
  409. }, {
  410. name: "expandToMatching",
  411. bindKey: bindKey("Ctrl-Shift-M", "Ctrl-Shift-M"),
  412. exec: function(editor) { editor.jumpToMatching(true, true); },
  413. multiSelectAction: "forEach",
  414. scrollIntoView: "animate",
  415. readOnly: true
  416. }, {
  417. name: "passKeysToBrowser",
  418. bindKey: bindKey(null, null),
  419. exec: function() {},
  420. passEvent: true,
  421. readOnly: true
  422. }, {
  423. name: "copy",
  424. exec: function(editor) {
  425. // placeholder for replay macro
  426. },
  427. readOnly: true
  428. },
  429. // commands disabled in readOnly mode
  430. {
  431. name: "cut",
  432. exec: function(editor) {
  433. var range = editor.getSelectionRange();
  434. editor._emit("cut", range);
  435. if (!editor.selection.isEmpty()) {
  436. editor.session.remove(range);
  437. editor.clearSelection();
  438. }
  439. },
  440. scrollIntoView: "cursor",
  441. multiSelectAction: "forEach"
  442. }, {
  443. name: "paste",
  444. exec: function(editor, args) {
  445. editor.$handlePaste(args);
  446. },
  447. scrollIntoView: "cursor"
  448. }, {
  449. name: "removeline",
  450. bindKey: bindKey("Ctrl-D", "Command-D"),
  451. exec: function(editor) { editor.removeLines(); },
  452. scrollIntoView: "cursor",
  453. multiSelectAction: "forEachLine"
  454. }, {
  455. name: "duplicateSelection",
  456. bindKey: bindKey("Ctrl-Shift-D", "Command-Shift-D"),
  457. exec: function(editor) { editor.duplicateSelection(); },
  458. scrollIntoView: "cursor",
  459. multiSelectAction: "forEach"
  460. }, {
  461. name: "sortlines",
  462. bindKey: bindKey("Ctrl-Alt-S", "Command-Alt-S"),
  463. exec: function(editor) { editor.sortLines(); },
  464. scrollIntoView: "selection",
  465. multiSelectAction: "forEachLine"
  466. }, {
  467. name: "togglecomment",
  468. bindKey: bindKey("Ctrl-/", "Command-/"),
  469. exec: function(editor) { editor.toggleCommentLines(); },
  470. multiSelectAction: "forEachLine",
  471. scrollIntoView: "selectionPart"
  472. }, {
  473. name: "toggleBlockComment",
  474. bindKey: bindKey("Ctrl-Shift-/", "Command-Shift-/"),
  475. exec: function(editor) { editor.toggleBlockComment(); },
  476. multiSelectAction: "forEach",
  477. scrollIntoView: "selectionPart"
  478. }, {
  479. name: "modifyNumberUp",
  480. bindKey: bindKey("Ctrl-Shift-Up", "Alt-Shift-Up"),
  481. exec: function(editor) { editor.modifyNumber(1); },
  482. scrollIntoView: "cursor",
  483. multiSelectAction: "forEach"
  484. }, {
  485. name: "modifyNumberDown",
  486. bindKey: bindKey("Ctrl-Shift-Down", "Alt-Shift-Down"),
  487. exec: function(editor) { editor.modifyNumber(-1); },
  488. scrollIntoView: "cursor",
  489. multiSelectAction: "forEach"
  490. }, {
  491. name: "replace",
  492. bindKey: bindKey("Ctrl-H", "Command-Option-F"),
  493. exec: function(editor) {
  494. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor, true)});
  495. }
  496. }, {
  497. name: "undo",
  498. bindKey: bindKey("Ctrl-Z", "Command-Z"),
  499. exec: function(editor) { editor.undo(); }
  500. }, {
  501. name: "redo",
  502. bindKey: bindKey("Ctrl-Shift-Z|Ctrl-Y", "Command-Shift-Z|Command-Y"),
  503. exec: function(editor) { editor.redo(); }
  504. }, {
  505. name: "copylinesup",
  506. bindKey: bindKey("Alt-Shift-Up", "Command-Option-Up"),
  507. exec: function(editor) { editor.copyLinesUp(); },
  508. scrollIntoView: "cursor"
  509. }, {
  510. name: "movelinesup",
  511. bindKey: bindKey("Alt-Up", "Option-Up"),
  512. exec: function(editor) { editor.moveLinesUp(); },
  513. scrollIntoView: "cursor"
  514. }, {
  515. name: "copylinesdown",
  516. bindKey: bindKey("Alt-Shift-Down", "Command-Option-Down"),
  517. exec: function(editor) { editor.copyLinesDown(); },
  518. scrollIntoView: "cursor"
  519. }, {
  520. name: "movelinesdown",
  521. bindKey: bindKey("Alt-Down", "Option-Down"),
  522. exec: function(editor) { editor.moveLinesDown(); },
  523. scrollIntoView: "cursor"
  524. }, {
  525. name: "del",
  526. bindKey: bindKey("Delete", "Delete|Ctrl-D|Shift-Delete"),
  527. exec: function(editor) { editor.remove("right"); },
  528. multiSelectAction: "forEach",
  529. scrollIntoView: "cursor"
  530. }, {
  531. name: "backspace",
  532. bindKey: bindKey(
  533. "Shift-Backspace|Backspace",
  534. "Ctrl-Backspace|Shift-Backspace|Backspace|Ctrl-H"
  535. ),
  536. exec: function(editor) { editor.remove("left"); },
  537. multiSelectAction: "forEach",
  538. scrollIntoView: "cursor"
  539. }, {
  540. name: "cut_or_delete",
  541. bindKey: bindKey("Shift-Delete", null),
  542. exec: function(editor) {
  543. if (editor.selection.isEmpty()) {
  544. editor.remove("left");
  545. } else {
  546. return false;
  547. }
  548. },
  549. multiSelectAction: "forEach",
  550. scrollIntoView: "cursor"
  551. }, {
  552. name: "removetolinestart",
  553. bindKey: bindKey("Alt-Backspace", "Command-Backspace"),
  554. exec: function(editor) { editor.removeToLineStart(); },
  555. multiSelectAction: "forEach",
  556. scrollIntoView: "cursor"
  557. }, {
  558. name: "removetolineend",
  559. bindKey: bindKey("Alt-Delete", "Ctrl-K"),
  560. exec: function(editor) { editor.removeToLineEnd(); },
  561. multiSelectAction: "forEach",
  562. scrollIntoView: "cursor"
  563. }, {
  564. name: "removewordleft",
  565. bindKey: bindKey("Ctrl-Backspace", "Alt-Backspace|Ctrl-Alt-Backspace"),
  566. exec: function(editor) { editor.removeWordLeft(); },
  567. multiSelectAction: "forEach",
  568. scrollIntoView: "cursor"
  569. }, {
  570. name: "removewordright",
  571. bindKey: bindKey("Ctrl-Delete", "Alt-Delete"),
  572. exec: function(editor) { editor.removeWordRight(); },
  573. multiSelectAction: "forEach",
  574. scrollIntoView: "cursor"
  575. }, {
  576. name: "outdent",
  577. bindKey: bindKey("Shift-Tab", "Shift-Tab"),
  578. exec: function(editor) { editor.blockOutdent(); },
  579. multiSelectAction: "forEach",
  580. scrollIntoView: "selectionPart"
  581. }, {
  582. name: "indent",
  583. bindKey: bindKey("Tab", "Tab"),
  584. exec: function(editor) { editor.indent(); },
  585. multiSelectAction: "forEach",
  586. scrollIntoView: "selectionPart"
  587. }, {
  588. name: "blockoutdent",
  589. bindKey: bindKey("Ctrl-[", "Ctrl-["),
  590. exec: function(editor) { editor.blockOutdent(); },
  591. multiSelectAction: "forEachLine",
  592. scrollIntoView: "selectionPart"
  593. }, {
  594. name: "blockindent",
  595. bindKey: bindKey("Ctrl-]", "Ctrl-]"),
  596. exec: function(editor) { editor.blockIndent(); },
  597. multiSelectAction: "forEachLine",
  598. scrollIntoView: "selectionPart"
  599. }, {
  600. name: "insertstring",
  601. exec: function(editor, str) { editor.insert(str); },
  602. multiSelectAction: "forEach",
  603. scrollIntoView: "cursor"
  604. }, {
  605. name: "inserttext",
  606. exec: function(editor, args) {
  607. editor.insert(lang.stringRepeat(args.text || "", args.times || 1));
  608. },
  609. multiSelectAction: "forEach",
  610. scrollIntoView: "cursor"
  611. }, {
  612. name: "splitline",
  613. bindKey: bindKey(null, "Ctrl-O"),
  614. exec: function(editor) { editor.splitLine(); },
  615. multiSelectAction: "forEach",
  616. scrollIntoView: "cursor"
  617. }, {
  618. name: "transposeletters",
  619. bindKey: bindKey("Ctrl-T", "Ctrl-T"),
  620. exec: function(editor) { editor.transposeLetters(); },
  621. multiSelectAction: function(editor) {editor.transposeSelections(1); },
  622. scrollIntoView: "cursor"
  623. }, {
  624. name: "touppercase",
  625. bindKey: bindKey("Ctrl-U", "Ctrl-U"),
  626. exec: function(editor) { editor.toUpperCase(); },
  627. multiSelectAction: "forEach",
  628. scrollIntoView: "cursor"
  629. }, {
  630. name: "tolowercase",
  631. bindKey: bindKey("Ctrl-Shift-U", "Ctrl-Shift-U"),
  632. exec: function(editor) { editor.toLowerCase(); },
  633. multiSelectAction: "forEach",
  634. scrollIntoView: "cursor"
  635. }, {
  636. name: "expandtoline",
  637. bindKey: bindKey("Ctrl-Shift-L", "Command-Shift-L"),
  638. exec: function(editor) {
  639. var range = editor.selection.getRange();
  640. range.start.column = range.end.column = 0;
  641. range.end.row++;
  642. editor.selection.setRange(range, false);
  643. },
  644. multiSelectAction: "forEach",
  645. scrollIntoView: "cursor",
  646. readOnly: true
  647. }, {
  648. name: "joinlines",
  649. bindKey: bindKey(null, null),
  650. exec: function(editor) {
  651. var isBackwards = editor.selection.isBackwards();
  652. var selectionStart = isBackwards ? editor.selection.getSelectionLead() : editor.selection.getSelectionAnchor();
  653. var selectionEnd = isBackwards ? editor.selection.getSelectionAnchor() : editor.selection.getSelectionLead();
  654. var firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length;
  655. var selectedText = editor.session.doc.getTextRange(editor.selection.getRange());
  656. var selectedCount = selectedText.replace(/\n\s*/, " ").length;
  657. var insertLine = editor.session.doc.getLine(selectionStart.row);
  658. for (var i = selectionStart.row + 1; i <= selectionEnd.row + 1; i++) {
  659. var curLine = lang.stringTrimLeft(lang.stringTrimRight(editor.session.doc.getLine(i)));
  660. if (curLine.length !== 0) {
  661. curLine = " " + curLine;
  662. }
  663. insertLine += curLine;
  664. }
  665. if (selectionEnd.row + 1 < (editor.session.doc.getLength() - 1)) {
  666. // Don't insert a newline at the end of the document
  667. insertLine += editor.session.doc.getNewLineCharacter();
  668. }
  669. editor.clearSelection();
  670. editor.session.doc.replace(new Range(selectionStart.row, 0, selectionEnd.row + 2, 0), insertLine);
  671. if (selectedCount > 0) {
  672. // Select the text that was previously selected
  673. editor.selection.moveCursorTo(selectionStart.row, selectionStart.column);
  674. editor.selection.selectTo(selectionStart.row, selectionStart.column + selectedCount);
  675. } else {
  676. // If the joined line had something in it, start the cursor at that something
  677. firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length > firstLineEndCol ? (firstLineEndCol + 1) : firstLineEndCol;
  678. editor.selection.moveCursorTo(selectionStart.row, firstLineEndCol);
  679. }
  680. },
  681. multiSelectAction: "forEach",
  682. readOnly: true
  683. }, {
  684. name: "invertSelection",
  685. bindKey: bindKey(null, null),
  686. exec: function(editor) {
  687. var endRow = editor.session.doc.getLength() - 1;
  688. var endCol = editor.session.doc.getLine(endRow).length;
  689. var ranges = editor.selection.rangeList.ranges;
  690. var newRanges = [];
  691. // If multiple selections don't exist, rangeList will return 0 so replace with single range
  692. if (ranges.length < 1) {
  693. ranges = [editor.selection.getRange()];
  694. }
  695. for (var i = 0; i < ranges.length; i++) {
  696. if (i == (ranges.length - 1)) {
  697. // The last selection must connect to the end of the document, unless it already does
  698. if (!(ranges[i].end.row === endRow && ranges[i].end.column === endCol)) {
  699. newRanges.push(new Range(ranges[i].end.row, ranges[i].end.column, endRow, endCol));
  700. }
  701. }
  702. if (i === 0) {
  703. // The first selection must connect to the start of the document, unless it already does
  704. if (!(ranges[i].start.row === 0 && ranges[i].start.column === 0)) {
  705. newRanges.push(new Range(0, 0, ranges[i].start.row, ranges[i].start.column));
  706. }
  707. } else {
  708. newRanges.push(new Range(ranges[i-1].end.row, ranges[i-1].end.column, ranges[i].start.row, ranges[i].start.column));
  709. }
  710. }
  711. editor.exitMultiSelectMode();
  712. editor.clearSelection();
  713. for(var i = 0; i < newRanges.length; i++) {
  714. editor.selection.addRange(newRanges[i], false);
  715. }
  716. },
  717. readOnly: true,
  718. scrollIntoView: "none"
  719. }];
  720. });