PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/ace/commands/default_commands.js

https://github.com/lbl52001/ace
JavaScript | 459 lines | 422 code | 7 blank | 30 comment | 4 complexity | 27ac918b07cf209fb5fef69ecb6587a5 MD5 | raw file
Possible License(s): BSD-3-Clause
  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 {
  36. win: win,
  37. mac: mac
  38. };
  39. }
  40. exports.commands = [{
  41. name: "selectall",
  42. bindKey: bindKey("Ctrl-A", "Command-A"),
  43. exec: function(editor) { editor.selectAll(); },
  44. readOnly: true
  45. }, {
  46. name: "centerselection",
  47. bindKey: bindKey(null, "Ctrl-L"),
  48. exec: function(editor) { editor.centerSelection(); },
  49. readOnly: true
  50. }, {
  51. name: "gotoline",
  52. bindKey: bindKey("Ctrl-L", "Command-L"),
  53. exec: function(editor) {
  54. var line = parseInt(prompt("Enter line number:"), 10);
  55. if (!isNaN(line)) {
  56. editor.gotoLine(line);
  57. }
  58. },
  59. readOnly: true
  60. }, {
  61. name: "fold",
  62. bindKey: bindKey("Alt-L|Ctrl-F1", "Command-Alt-L|Command-F1"),
  63. exec: function(editor) { editor.session.toggleFold(false); },
  64. readOnly: true
  65. }, {
  66. name: "unfold",
  67. bindKey: bindKey("Alt-Shift-L|Ctrl-Shift-F1", "Command-Alt-Shift-L|Command-Shift-F1"),
  68. exec: function(editor) { editor.session.toggleFold(true); },
  69. readOnly: true
  70. }, {
  71. name: "foldall",
  72. bindKey: bindKey("Alt-0", "Command-Option-0"),
  73. exec: function(editor) { editor.session.foldAll(); },
  74. readOnly: true
  75. }, {
  76. name: "unfoldall",
  77. bindKey: bindKey("Alt-Shift-0", "Command-Option-Shift-0"),
  78. exec: function(editor) { editor.session.unfold(); },
  79. readOnly: true
  80. }, {
  81. name: "findnext",
  82. bindKey: bindKey("Ctrl-K", "Command-G"),
  83. exec: function(editor) { editor.findNext(); },
  84. readOnly: true
  85. }, {
  86. name: "findprevious",
  87. bindKey: bindKey("Ctrl-Shift-K", "Command-Shift-G"),
  88. exec: function(editor) { editor.findPrevious(); },
  89. readOnly: true
  90. }, {
  91. name: "find",
  92. bindKey: bindKey("Ctrl-F", "Command-F"),
  93. exec: function(editor) {
  94. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor)});
  95. },
  96. readOnly: true
  97. }, {
  98. name: "overwrite",
  99. bindKey: "Insert",
  100. exec: function(editor) { editor.toggleOverwrite(); },
  101. readOnly: true
  102. }, {
  103. name: "selecttostart",
  104. bindKey: bindKey("Ctrl-Shift-Home", "Command-Shift-Up"),
  105. exec: function(editor) { editor.getSelection().selectFileStart(); },
  106. multiSelectAction: "forEach",
  107. readOnly: true
  108. }, {
  109. name: "gotostart",
  110. bindKey: bindKey("Ctrl-Home", "Command-Home|Command-Up"),
  111. exec: function(editor) { editor.navigateFileStart(); },
  112. multiSelectAction: "forEach",
  113. readOnly: true
  114. }, {
  115. name: "selectup",
  116. bindKey: bindKey("Shift-Up", "Shift-Up"),
  117. exec: function(editor) { editor.getSelection().selectUp(); },
  118. multiSelectAction: "forEach",
  119. readOnly: true
  120. }, {
  121. name: "golineup",
  122. bindKey: bindKey("Up", "Up|Ctrl-P"),
  123. exec: function(editor, args) { editor.navigateUp(args.times); },
  124. multiSelectAction: "forEach",
  125. readOnly: true
  126. }, {
  127. name: "selecttoend",
  128. bindKey: bindKey("Ctrl-Shift-End", "Command-Shift-Down"),
  129. exec: function(editor) { editor.getSelection().selectFileEnd(); },
  130. multiSelectAction: "forEach",
  131. readOnly: true
  132. }, {
  133. name: "gotoend",
  134. bindKey: bindKey("Ctrl-End", "Command-End|Command-Down"),
  135. exec: function(editor) { editor.navigateFileEnd(); },
  136. multiSelectAction: "forEach",
  137. readOnly: true
  138. }, {
  139. name: "selectdown",
  140. bindKey: bindKey("Shift-Down", "Shift-Down"),
  141. exec: function(editor) { editor.getSelection().selectDown(); },
  142. multiSelectAction: "forEach",
  143. readOnly: true
  144. }, {
  145. name: "golinedown",
  146. bindKey: bindKey("Down", "Down|Ctrl-N"),
  147. exec: function(editor, args) { editor.navigateDown(args.times); },
  148. multiSelectAction: "forEach",
  149. readOnly: true
  150. }, {
  151. name: "selectwordleft",
  152. bindKey: bindKey("Ctrl-Shift-Left", "Option-Shift-Left"),
  153. exec: function(editor) { editor.getSelection().selectWordLeft(); },
  154. multiSelectAction: "forEach",
  155. readOnly: true
  156. }, {
  157. name: "gotowordleft",
  158. bindKey: bindKey("Ctrl-Left", "Option-Left"),
  159. exec: function(editor) { editor.navigateWordLeft(); },
  160. multiSelectAction: "forEach",
  161. readOnly: true
  162. }, {
  163. name: "selecttolinestart",
  164. bindKey: bindKey("Alt-Shift-Left", "Command-Shift-Left"),
  165. exec: function(editor) { editor.getSelection().selectLineStart(); },
  166. multiSelectAction: "forEach",
  167. readOnly: true
  168. }, {
  169. name: "gotolinestart",
  170. bindKey: bindKey("Alt-Left|Home", "Command-Left|Home|Ctrl-A"),
  171. exec: function(editor) { editor.navigateLineStart(); },
  172. multiSelectAction: "forEach",
  173. readOnly: true
  174. }, {
  175. name: "selectleft",
  176. bindKey: bindKey("Shift-Left", "Shift-Left"),
  177. exec: function(editor) { editor.getSelection().selectLeft(); },
  178. multiSelectAction: "forEach",
  179. readOnly: true
  180. }, {
  181. name: "gotoleft",
  182. bindKey: bindKey("Left", "Left|Ctrl-B"),
  183. exec: function(editor, args) { editor.navigateLeft(args.times); },
  184. multiSelectAction: "forEach",
  185. readOnly: true
  186. }, {
  187. name: "selectwordright",
  188. bindKey: bindKey("Ctrl-Shift-Right", "Option-Shift-Right"),
  189. exec: function(editor) { editor.getSelection().selectWordRight(); },
  190. multiSelectAction: "forEach",
  191. readOnly: true
  192. }, {
  193. name: "gotowordright",
  194. bindKey: bindKey("Ctrl-Right", "Option-Right"),
  195. exec: function(editor) { editor.navigateWordRight(); },
  196. multiSelectAction: "forEach",
  197. readOnly: true
  198. }, {
  199. name: "selecttolineend",
  200. bindKey: bindKey("Alt-Shift-Right", "Command-Shift-Right"),
  201. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  202. multiSelectAction: "forEach",
  203. readOnly: true
  204. }, {
  205. name: "gotolineend",
  206. bindKey: bindKey("Alt-Right|End", "Command-Right|End|Ctrl-E"),
  207. exec: function(editor) { editor.navigateLineEnd(); },
  208. multiSelectAction: "forEach",
  209. readOnly: true
  210. }, {
  211. name: "selectright",
  212. bindKey: bindKey("Shift-Right", "Shift-Right"),
  213. exec: function(editor) { editor.getSelection().selectRight(); },
  214. multiSelectAction: "forEach",
  215. readOnly: true
  216. }, {
  217. name: "gotoright",
  218. bindKey: bindKey("Right", "Right|Ctrl-F"),
  219. exec: function(editor, args) { editor.navigateRight(args.times); },
  220. multiSelectAction: "forEach",
  221. readOnly: true
  222. }, {
  223. name: "selectpagedown",
  224. bindKey: "Shift-PageDown",
  225. exec: function(editor) { editor.selectPageDown(); },
  226. readOnly: true
  227. }, {
  228. name: "pagedown",
  229. bindKey: bindKey(null, "Option-PageDown"),
  230. exec: function(editor) { editor.scrollPageDown(); },
  231. readOnly: true
  232. }, {
  233. name: "gotopagedown",
  234. bindKey: bindKey("PageDown", "PageDown|Ctrl-V"),
  235. exec: function(editor) { editor.gotoPageDown(); },
  236. readOnly: true
  237. }, {
  238. name: "selectpageup",
  239. bindKey: "Shift-PageUp",
  240. exec: function(editor) { editor.selectPageUp(); },
  241. readOnly: true
  242. }, {
  243. name: "pageup",
  244. bindKey: bindKey(null, "Option-PageUp"),
  245. exec: function(editor) { editor.scrollPageUp(); },
  246. readOnly: true
  247. }, {
  248. name: "gotopageup",
  249. bindKey: "PageUp",
  250. exec: function(editor) { editor.gotoPageUp(); },
  251. readOnly: true
  252. }, {
  253. name: "scrollup",
  254. bindKey: bindKey("Ctrl-Up", null),
  255. exec: function(e) { e.renderer.scrollBy(0, -2 * e.renderer.layerConfig.lineHeight); },
  256. readOnly: true
  257. }, {
  258. name: "scrolldown",
  259. bindKey: bindKey("Ctrl-Down", null),
  260. exec: function(e) { e.renderer.scrollBy(0, 2 * e.renderer.layerConfig.lineHeight); },
  261. readOnly: true
  262. }, {
  263. name: "selectlinestart",
  264. bindKey: "Shift-Home",
  265. exec: function(editor) { editor.getSelection().selectLineStart(); },
  266. multiSelectAction: "forEach",
  267. readOnly: true
  268. }, {
  269. name: "selectlineend",
  270. bindKey: "Shift-End",
  271. exec: function(editor) { editor.getSelection().selectLineEnd(); },
  272. multiSelectAction: "forEach",
  273. readOnly: true
  274. }, {
  275. name: "togglerecording",
  276. bindKey: bindKey("Ctrl-Alt-E", "Command-Option-E"),
  277. exec: function(editor) { editor.commands.toggleRecording(editor); },
  278. readOnly: true
  279. }, {
  280. name: "replaymacro",
  281. bindKey: bindKey("Ctrl-Shift-E", "Command-Shift-E"),
  282. exec: function(editor) { editor.commands.replay(editor); },
  283. readOnly: true
  284. }, {
  285. name: "jumptomatching",
  286. bindKey: bindKey("Ctrl-P", "Ctrl-Shift-P"),
  287. exec: function(editor) { editor.jumpToMatching(); },
  288. multiSelectAction: "forEach",
  289. readOnly: true
  290. }, {
  291. name: "selecttomatching",
  292. bindKey: bindKey("Ctrl-Shift-P", null),
  293. exec: function(editor) { editor.jumpToMatching(true); },
  294. readOnly: true
  295. },
  296. // commands disabled in readOnly mode
  297. {
  298. name: "cut",
  299. exec: function(editor) {
  300. var range = editor.getSelectionRange();
  301. editor._emit("cut", range);
  302. if (!editor.selection.isEmpty()) {
  303. editor.session.remove(range);
  304. editor.clearSelection();
  305. }
  306. },
  307. multiSelectAction: "forEach"
  308. }, {
  309. name: "removeline",
  310. bindKey: bindKey("Ctrl-D", "Command-D"),
  311. exec: function(editor) { editor.removeLines(); },
  312. multiSelectAction: "forEach"
  313. }, {
  314. name: "duplicateSelection",
  315. bindKey: bindKey("Ctrl-Shift-D", "Command-Shift-D"),
  316. exec: function(editor) { editor.duplicateSelection(); },
  317. multiSelectAction: "forEach"
  318. }, {
  319. name: "sortlines",
  320. bindKey: bindKey("Ctrl-Alt-S", "Command-Alt-S"),
  321. exec: function(editor) { editor.sortLines(); },
  322. multiSelectAction: "forEach"
  323. }, {
  324. name: "togglecomment",
  325. bindKey: bindKey("Ctrl-/", "Command-/"),
  326. exec: function(editor) { editor.toggleCommentLines(); },
  327. multiSelectAction: "forEach"
  328. }, {
  329. name: "modifyNumberUp",
  330. bindKey: bindKey("Ctrl-Shift-Up", "Alt-Shift-Up"),
  331. exec: function(editor) { editor.modifyNumber(1); },
  332. multiSelectAction: "forEach"
  333. }, {
  334. name: "modifyNumberDown",
  335. bindKey: bindKey("Ctrl-Shift-Down", "Alt-Shift-Down"),
  336. exec: function(editor) { editor.modifyNumber(-1); },
  337. multiSelectAction: "forEach"
  338. }, {
  339. name: "replace",
  340. bindKey: bindKey("Ctrl-H", "Command-Option-F"),
  341. exec: function(editor) {
  342. config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor, true)});
  343. }
  344. }, {
  345. name: "undo",
  346. bindKey: bindKey("Ctrl-Z", "Command-Z"),
  347. exec: function(editor) { editor.undo(); }
  348. }, {
  349. name: "redo",
  350. bindKey: bindKey("Ctrl-Shift-Z|Ctrl-Y", "Command-Shift-Z|Command-Y"),
  351. exec: function(editor) { editor.redo(); }
  352. }, {
  353. name: "copylinesup",
  354. bindKey: bindKey("Alt-Shift-Up", "Command-Option-Up"),
  355. exec: function(editor) { editor.copyLinesUp(); }
  356. }, {
  357. name: "movelinesup",
  358. bindKey: bindKey("Alt-Up", "Option-Up"),
  359. exec: function(editor) { editor.moveLinesUp(); }
  360. }, {
  361. name: "copylinesdown",
  362. bindKey: bindKey("Alt-Shift-Down", "Command-Option-Down"),
  363. exec: function(editor) { editor.copyLinesDown(); }
  364. }, {
  365. name: "movelinesdown",
  366. bindKey: bindKey("Alt-Down", "Option-Down"),
  367. exec: function(editor) { editor.moveLinesDown(); }
  368. }, {
  369. name: "del",
  370. bindKey: bindKey("Delete", "Delete|Ctrl-D"),
  371. exec: function(editor) { editor.remove("right"); },
  372. multiSelectAction: "forEach"
  373. }, {
  374. name: "backspace",
  375. bindKey: bindKey(
  376. "Command-Backspace|Option-Backspace|Shift-Backspace|Backspace",
  377. "Ctrl-Backspace|Command-Backspace|Shift-Backspace|Backspace|Ctrl-H"
  378. ),
  379. exec: function(editor) { editor.remove("left"); },
  380. multiSelectAction: "forEach"
  381. }, {
  382. name: "removetolinestart",
  383. bindKey: bindKey("Alt-Backspace", "Command-Backspace"),
  384. exec: function(editor) { editor.removeToLineStart(); },
  385. multiSelectAction: "forEach"
  386. }, {
  387. name: "removetolineend",
  388. bindKey: bindKey("Alt-Delete", "Ctrl-K"),
  389. exec: function(editor) { editor.removeToLineEnd(); },
  390. multiSelectAction: "forEach"
  391. }, {
  392. name: "removewordleft",
  393. bindKey: bindKey("Ctrl-Backspace", "Alt-Backspace|Ctrl-Alt-Backspace"),
  394. exec: function(editor) { editor.removeWordLeft(); },
  395. multiSelectAction: "forEach"
  396. }, {
  397. name: "removewordright",
  398. bindKey: bindKey("Ctrl-Delete", "Alt-Delete"),
  399. exec: function(editor) { editor.removeWordRight(); },
  400. multiSelectAction: "forEach"
  401. }, {
  402. name: "outdent",
  403. bindKey: bindKey("Shift-Tab", "Shift-Tab"),
  404. exec: function(editor) { editor.blockOutdent(); },
  405. multiSelectAction: "forEach"
  406. }, {
  407. name: "indent",
  408. bindKey: bindKey("Tab", "Tab"),
  409. exec: function(editor) { editor.indent(); },
  410. multiSelectAction: "forEach"
  411. },{
  412. name: "blockoutdent",
  413. bindKey: bindKey("Ctrl-[", "Ctrl-["),
  414. exec: function(editor) { editor.blockOutdent(); },
  415. multiSelectAction: "forEach"
  416. },{
  417. name: "blockindent",
  418. bindKey: bindKey("Ctrl-]", "Ctrl-]"),
  419. exec: function(editor) { editor.blockIndent(); },
  420. multiSelectAction: "forEach"
  421. }, {
  422. name: "insertstring",
  423. exec: function(editor, str) { editor.insert(str); },
  424. multiSelectAction: "forEach"
  425. }, {
  426. name: "inserttext",
  427. exec: function(editor, args) {
  428. editor.insert(lang.stringRepeat(args.text || "", args.times || 1));
  429. },
  430. multiSelectAction: "forEach"
  431. }, {
  432. name: "splitline",
  433. bindKey: bindKey(null, "Ctrl-O"),
  434. exec: function(editor) { editor.splitLine(); },
  435. multiSelectAction: "forEach"
  436. }, {
  437. name: "transposeletters",
  438. bindKey: bindKey("Ctrl-T", "Ctrl-T"),
  439. exec: function(editor) { editor.transposeLetters(); },
  440. multiSelectAction: function(editor) {editor.transposeSelections(1); }
  441. }, {
  442. name: "touppercase",
  443. bindKey: bindKey("Ctrl-U", "Ctrl-U"),
  444. exec: function(editor) { editor.toUpperCase(); },
  445. multiSelectAction: "forEach"
  446. }, {
  447. name: "tolowercase",
  448. bindKey: bindKey("Ctrl-Shift-U", "Ctrl-Shift-U"),
  449. exec: function(editor) { editor.toLowerCase(); },
  450. multiSelectAction: "forEach"
  451. }];
  452. });