keybinding-sublime.js 11 KB

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