keybinding-sublime.js 11 KB

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