769ae488953faab19b33deee8331b789.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. ace.define("ace/keyboard/sublime",["require","exports","module","ace/keyboard/hash_handler"], function(require, exports, module){"use strict";
  2. var HashHandler = require("../keyboard/hash_handler").HashHandler;
  3. function moveBySubWords(editor, direction, extend) {
  4. var selection = editor.selection;
  5. var row = selection.lead.row;
  6. var column = selection.lead.column;
  7. var line = editor.session.getLine(row);
  8. if (!line[column + direction]) {
  9. var method = (extend ? "selectWord" : "moveCursorShortWord")
  10. + (direction == 1 ? "Right" : "Left");
  11. return editor.selection[method]();
  12. }
  13. if (direction == -1)
  14. column--;
  15. while (line[column]) {
  16. var type = getType(line[column]) + getType(line[column + direction]);
  17. column += direction;
  18. if (direction == 1) {
  19. if (type == "WW" && getType(line[column + 1]) == "w")
  20. break;
  21. }
  22. else {
  23. if (type == "wW") {
  24. if (getType(line[column - 1]) == "W") {
  25. column -= 1;
  26. break;
  27. }
  28. else {
  29. continue;
  30. }
  31. }
  32. if (type == "Ww")
  33. break;
  34. }
  35. if (/w[s_oW]|_[sWo]|o[s_wW]|s[W]|W[so]/.test(type))
  36. break;
  37. }
  38. if (direction == -1)
  39. column++;
  40. if (extend)
  41. editor.selection.moveCursorTo(row, column);
  42. else
  43. editor.selection.moveTo(row, column);
  44. function getType(x) {
  45. if (!x)
  46. return "-";
  47. if (/\s/.test(x))
  48. return "s";
  49. if (x == "_")
  50. return "_";
  51. if (x.toUpperCase() == x && x.toLowerCase() != x)
  52. return "W";
  53. if (x.toUpperCase() != x && x.toLowerCase() == x)
  54. return "w";
  55. return "o";
  56. }
  57. }
  58. exports.handler = new HashHandler();
  59. exports.handler.addCommands([{
  60. name: "find_all_under",
  61. exec: function (editor) {
  62. if (editor.selection.isEmpty())
  63. editor.selection.selectWord();
  64. editor.findAll();
  65. },
  66. readOnly: true
  67. }, {
  68. name: "find_under",
  69. exec: function (editor) {
  70. if (editor.selection.isEmpty())
  71. editor.selection.selectWord();
  72. editor.findNext();
  73. },
  74. readOnly: true
  75. }, {
  76. name: "find_under_prev",
  77. exec: function (editor) {
  78. if (editor.selection.isEmpty())
  79. editor.selection.selectWord();
  80. editor.findPrevious();
  81. },
  82. readOnly: true
  83. }, {
  84. name: "find_under_expand",
  85. exec: function (editor) {
  86. editor.selectMore(1, false, true);
  87. },
  88. scrollIntoView: "animate",
  89. readOnly: true
  90. }, {
  91. name: "find_under_expand_skip",
  92. exec: function (editor) {
  93. editor.selectMore(1, true, true);
  94. },
  95. scrollIntoView: "animate",
  96. readOnly: true
  97. }, {
  98. name: "delete_to_hard_bol",
  99. exec: function (editor) {
  100. var pos = editor.selection.getCursor();
  101. editor.session.remove({
  102. start: { row: pos.row, column: 0 },
  103. end: pos
  104. });
  105. },
  106. multiSelectAction: "forEach",
  107. scrollIntoView: "cursor"
  108. }, {
  109. name: "delete_to_hard_eol",
  110. exec: function (editor) {
  111. var pos = editor.selection.getCursor();
  112. editor.session.remove({
  113. start: pos,
  114. end: { row: pos.row, column: Infinity }
  115. });
  116. },
  117. multiSelectAction: "forEach",
  118. scrollIntoView: "cursor"
  119. }, {
  120. name: "moveToWordStartLeft",
  121. exec: function (editor) {
  122. editor.selection.moveCursorLongWordLeft();
  123. editor.clearSelection();
  124. },
  125. multiSelectAction: "forEach",
  126. scrollIntoView: "cursor"
  127. }, {
  128. name: "moveToWordEndRight",
  129. exec: function (editor) {
  130. editor.selection.moveCursorLongWordRight();
  131. editor.clearSelection();
  132. },
  133. multiSelectAction: "forEach",
  134. scrollIntoView: "cursor"
  135. }, {
  136. name: "selectToWordStartLeft",
  137. exec: function (editor) {
  138. var sel = editor.selection;
  139. sel.$moveSelection(sel.moveCursorLongWordLeft);
  140. },
  141. multiSelectAction: "forEach",
  142. scrollIntoView: "cursor"
  143. }, {
  144. name: "selectToWordEndRight",
  145. exec: function (editor) {
  146. var sel = editor.selection;
  147. sel.$moveSelection(sel.moveCursorLongWordRight);
  148. },
  149. multiSelectAction: "forEach",
  150. scrollIntoView: "cursor"
  151. }, {
  152. name: "selectSubWordRight",
  153. exec: function (editor) {
  154. moveBySubWords(editor, 1, true);
  155. },
  156. multiSelectAction: "forEach",
  157. scrollIntoView: "cursor",
  158. readOnly: true
  159. }, {
  160. name: "selectSubWordLeft",
  161. exec: function (editor) {
  162. moveBySubWords(editor, -1, true);
  163. },
  164. multiSelectAction: "forEach",
  165. scrollIntoView: "cursor",
  166. readOnly: true
  167. }, {
  168. name: "moveSubWordRight",
  169. exec: function (editor) {
  170. moveBySubWords(editor, 1);
  171. },
  172. multiSelectAction: "forEach",
  173. scrollIntoView: "cursor",
  174. readOnly: true
  175. }, {
  176. name: "moveSubWordLeft",
  177. exec: function (editor) {
  178. moveBySubWords(editor, -1);
  179. },
  180. multiSelectAction: "forEach",
  181. scrollIntoView: "cursor",
  182. readOnly: true
  183. }]);
  184. [{
  185. bindKey: { mac: "cmd-k cmd-backspace|cmd-backspace", win: "ctrl-shift-backspace|ctrl-k ctrl-backspace" },
  186. name: "removetolinestarthard"
  187. }, {
  188. bindKey: { mac: "cmd-k cmd-k|cmd-delete|ctrl-k", win: "ctrl-shift-delete|ctrl-k ctrl-k" },
  189. name: "removetolineendhard"
  190. }, {
  191. bindKey: { mac: "cmd-shift-d", win: "ctrl-shift-d" },
  192. name: "duplicateSelection"
  193. }, {
  194. bindKey: { mac: "cmd-l", win: "ctrl-l" },
  195. name: "expandtoline"
  196. },
  197. {
  198. bindKey: { mac: "cmd-shift-a", win: "ctrl-shift-a" },
  199. name: "expandSelection",
  200. args: { to: "tag" }
  201. }, {
  202. bindKey: { mac: "cmd-shift-j", win: "ctrl-shift-j" },
  203. name: "expandSelection",
  204. args: { to: "indentation" }
  205. }, {
  206. bindKey: { mac: "ctrl-shift-m", win: "ctrl-shift-m" },
  207. name: "expandSelection",
  208. args: { to: "brackets" }
  209. }, {
  210. bindKey: { mac: "cmd-shift-space", win: "ctrl-shift-space" },
  211. name: "expandSelection",
  212. args: { to: "scope" }
  213. },
  214. {
  215. bindKey: { mac: "ctrl-cmd-g", win: "alt-f3" },
  216. name: "find_all_under"
  217. }, {
  218. bindKey: { mac: "alt-cmd-g", win: "ctrl-f3" },
  219. name: "find_under"
  220. }, {
  221. bindKey: { mac: "shift-alt-cmd-g", win: "ctrl-shift-f3" },
  222. name: "find_under_prev"
  223. }, {
  224. bindKey: { mac: "cmd-g", win: "f3" },
  225. name: "findnext"
  226. }, {
  227. bindKey: { mac: "shift-cmd-g", win: "shift-f3" },
  228. name: "findprevious"
  229. }, {
  230. bindKey: { mac: "cmd-d", win: "ctrl-d" },
  231. name: "find_under_expand"
  232. }, {
  233. bindKey: { mac: "cmd-k cmd-d", win: "ctrl-k ctrl-d" },
  234. name: "find_under_expand_skip"
  235. },
  236. {
  237. bindKey: { mac: "cmd-alt-[", win: "ctrl-shift-[" },
  238. name: "toggleFoldWidget"
  239. }, {
  240. bindKey: { mac: "cmd-alt-]", win: "ctrl-shift-]" },
  241. name: "unfold"
  242. }, {
  243. bindKey: { mac: "cmd-k cmd-0|cmd-k cmd-j", win: "ctrl-k ctrl-0|ctrl-k ctrl-j" },
  244. name: "unfoldall"
  245. }, {
  246. bindKey: { mac: "cmd-k cmd-1", win: "ctrl-k ctrl-1" },
  247. name: "foldOther",
  248. args: { level: 1 }
  249. },
  250. {
  251. bindKey: { win: "ctrl-left", mac: "alt-left" },
  252. name: "moveToWordStartLeft"
  253. }, {
  254. bindKey: { win: "ctrl-right", mac: "alt-right" },
  255. name: "moveToWordEndRight"
  256. }, {
  257. bindKey: { win: "ctrl-shift-left", mac: "alt-shift-left" },
  258. name: "selectToWordStartLeft"
  259. }, {
  260. bindKey: { win: "ctrl-shift-right", mac: "alt-shift-right" },
  261. name: "selectToWordEndRight"
  262. },
  263. {
  264. bindKey: { mac: "ctrl-alt-shift-right|ctrl-shift-right", win: "alt-shift-right" },
  265. name: "selectSubWordRight"
  266. }, {
  267. bindKey: { mac: "ctrl-alt-shift-left|ctrl-shift-left", win: "alt-shift-left" },
  268. name: "selectSubWordLeft"
  269. }, {
  270. bindKey: { mac: "ctrl-alt-right|ctrl-right", win: "alt-right" },
  271. name: "moveSubWordRight"
  272. }, {
  273. bindKey: { mac: "ctrl-alt-left|ctrl-left", win: "alt-left" },
  274. name: "moveSubWordLeft"
  275. },
  276. {
  277. bindKey: { mac: "ctrl-m", win: "ctrl-m" },
  278. name: "jumptomatching",
  279. args: { to: "brackets" }
  280. },
  281. {
  282. bindKey: { mac: "ctrl-f6", win: "ctrl-f6" },
  283. name: "goToNextError"
  284. }, {
  285. bindKey: { mac: "ctrl-shift-f6", win: "ctrl-shift-f6" },
  286. name: "goToPreviousError"
  287. },
  288. {
  289. bindKey: { mac: "ctrl-o" },
  290. name: "splitline"
  291. },
  292. {
  293. bindKey: { mac: "ctrl-shift-w", win: "alt-shift-w" },
  294. name: "surrowndWithTag"
  295. }, {
  296. bindKey: { mac: "cmd-alt-.", win: "alt-." },
  297. name: "close_tag"
  298. },
  299. {
  300. bindKey: { mac: "cmd-j", win: "ctrl-j" },
  301. name: "joinlines"
  302. },
  303. {
  304. bindKey: { mac: "ctrl--", win: "alt--" },
  305. name: "jumpBack"
  306. }, {
  307. bindKey: { mac: "ctrl-shift--", win: "alt-shift--" },
  308. name: "jumpForward"
  309. },
  310. {
  311. bindKey: { mac: "cmd-k cmd-l", win: "ctrl-k ctrl-l" },
  312. name: "tolowercase"
  313. }, {
  314. bindKey: { mac: "cmd-k cmd-u", win: "ctrl-k ctrl-u" },
  315. name: "touppercase"
  316. },
  317. {
  318. bindKey: { mac: "cmd-shift-v", win: "ctrl-shift-v" },
  319. name: "paste_and_indent"
  320. }, {
  321. bindKey: { mac: "cmd-k cmd-v|cmd-alt-v", win: "ctrl-k ctrl-v" },
  322. name: "paste_from_history"
  323. },
  324. {
  325. bindKey: { mac: "cmd-shift-enter", win: "ctrl-shift-enter" },
  326. name: "addLineBefore"
  327. }, {
  328. bindKey: { mac: "cmd-enter", win: "ctrl-enter" },
  329. name: "addLineAfter"
  330. }, {
  331. bindKey: { mac: "ctrl-shift-k", win: "ctrl-shift-k" },
  332. name: "removeline"
  333. }, {
  334. bindKey: { mac: "ctrl-alt-up", win: "ctrl-up" },
  335. name: "scrollup"
  336. }, {
  337. bindKey: { mac: "ctrl-alt-down", win: "ctrl-down" },
  338. name: "scrolldown"
  339. }, {
  340. bindKey: { mac: "cmd-a", win: "ctrl-a" },
  341. name: "selectall"
  342. }, {
  343. bindKey: { linux: "alt-shift-down", mac: "ctrl-shift-down", win: "ctrl-alt-down" },
  344. name: "addCursorBelow"
  345. }, {
  346. bindKey: { linux: "alt-shift-up", mac: "ctrl-shift-up", win: "ctrl-alt-up" },
  347. name: "addCursorAbove"
  348. },
  349. {
  350. bindKey: { mac: "cmd-k cmd-c|ctrl-l", win: "ctrl-k ctrl-c" },
  351. name: "centerselection"
  352. },
  353. {
  354. bindKey: { mac: "f5", win: "f9" },
  355. name: "sortlines"
  356. },
  357. {
  358. bindKey: { mac: "ctrl-f5", win: "ctrl-f9" },
  359. name: "sortlines",
  360. args: { caseSensitive: true }
  361. },
  362. {
  363. bindKey: { mac: "cmd-shift-l", win: "ctrl-shift-l" },
  364. name: "splitSelectionIntoLines"
  365. }, {
  366. bindKey: { mac: "ctrl-cmd-down", win: "ctrl-shift-down" },
  367. name: "movelinesdown"
  368. }, {
  369. bindKey: { mac: "ctrl-cmd-up", win: "ctrl-shift-up" },
  370. name: "movelinesup"
  371. }, {
  372. bindKey: { mac: "alt-down", win: "alt-down" },
  373. name: "modifyNumberDown"
  374. }, {
  375. bindKey: { mac: "alt-up", win: "alt-up" },
  376. name: "modifyNumberUp"
  377. }, {
  378. bindKey: { mac: "cmd-/", win: "ctrl-/" },
  379. name: "togglecomment"
  380. }, {
  381. bindKey: { mac: "cmd-alt-/", win: "ctrl-shift-/" },
  382. name: "toggleBlockComment"
  383. },
  384. {
  385. bindKey: { linux: "ctrl-alt-q", mac: "ctrl-q", win: "ctrl-q" },
  386. name: "togglerecording"
  387. }, {
  388. bindKey: { linux: "ctrl-alt-shift-q", mac: "ctrl-shift-q", win: "ctrl-shift-q" },
  389. name: "replaymacro"
  390. },
  391. {
  392. bindKey: { mac: "ctrl-t", win: "ctrl-t" },
  393. name: "transpose"
  394. }
  395. ].forEach(function (binding) {
  396. var command = exports.handler.commands[binding.name];
  397. if (command)
  398. command.bindKey = binding.bindKey;
  399. exports.handler.bindKey(binding.bindKey, command || binding.name);
  400. });
  401. }); (function() {
  402. ace.require(["ace/keyboard/sublime"], function(m) {
  403. if (typeof module == "object" && typeof exports == "object" && module) {
  404. module.exports = m;
  405. }
  406. });
  407. })();