keybinding-vscode.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. ace.define("ace/keyboard/vscode",["require","exports","module","ace/keyboard/hash_handler","ace/config"], function(require, exports, module) {
  2. "use strict";
  3. var HashHandler = require("../keyboard/hash_handler").HashHandler;
  4. var config = require("../config");
  5. exports.handler = new HashHandler();
  6. exports.handler.$id = "ace/keyboard/vscode";
  7. exports.handler.addCommands([{
  8. name: "toggleWordWrap",
  9. exec: function(editor) {
  10. var wrapUsed = editor.session.getUseWrapMode();
  11. editor.session.setUseWrapMode(!wrapUsed);
  12. },
  13. readOnly: true
  14. }, {
  15. name: "navigateToLastEditLocation",
  16. exec: function(editor) {
  17. var lastDelta = editor.session.getUndoManager().$lastDelta;
  18. var range = (lastDelta.action == "remove")? lastDelta.start: lastDelta.end;
  19. editor.moveCursorTo(range.row, range.column);
  20. editor.clearSelection();
  21. }
  22. }, {
  23. name: "replaceAll",
  24. exec: function (editor) {
  25. if (!editor.searchBox) {
  26. config.loadModule("ace/ext/searchbox", function(e) {
  27. e.Search(editor, true);
  28. });
  29. } else {
  30. if (editor.searchBox.active === true && editor.searchBox.replaceOption.checked === true) {
  31. editor.searchBox.replaceAll();
  32. }
  33. }
  34. }
  35. }, {
  36. name: "replaceOne",
  37. exec: function (editor) {
  38. if (!editor.searchBox) {
  39. config.loadModule("ace/ext/searchbox", function(e) {
  40. e.Search(editor, true);
  41. });
  42. } else {
  43. if (editor.searchBox.active === true && editor.searchBox.replaceOption.checked === true) {
  44. editor.searchBox.replace();
  45. }
  46. }
  47. }
  48. }, {
  49. name: "selectAllMatches",
  50. exec: function (editor) {
  51. if (!editor.searchBox) {
  52. config.loadModule("ace/ext/searchbox", function(e) {
  53. e.Search(editor, false);
  54. });
  55. } else {
  56. if (editor.searchBox.active === true) {
  57. editor.searchBox.findAll();
  58. }
  59. }
  60. }
  61. }, {
  62. name: "toggleFindCaseSensitive",
  63. exec: function (editor) {
  64. config.loadModule("ace/ext/searchbox", function(e) {
  65. e.Search(editor, false);
  66. var sb = editor.searchBox;
  67. sb.caseSensitiveOption.checked = !sb.caseSensitiveOption.checked;
  68. sb.$syncOptions();
  69. });
  70. }
  71. }, {
  72. name: "toggleFindInSelection",
  73. exec: function (editor) {
  74. config.loadModule("ace/ext/searchbox", function(e) {
  75. e.Search(editor, false);
  76. var sb = editor.searchBox;
  77. sb.searchOption.checked = !sb.searchRange;
  78. sb.setSearchRange(sb.searchOption.checked && sb.editor.getSelectionRange());
  79. sb.$syncOptions();
  80. });
  81. }
  82. }, {
  83. name: "toggleFindRegex",
  84. exec: function (editor) {
  85. config.loadModule("ace/ext/searchbox", function(e) {
  86. e.Search(editor, false);
  87. var sb = editor.searchBox;
  88. sb.regExpOption.checked = !sb.regExpOption.checked;
  89. sb.$syncOptions();
  90. });
  91. }
  92. }, {
  93. name: "toggleFindWholeWord",
  94. exec: function (editor) {
  95. config.loadModule("ace/ext/searchbox", function(e) {
  96. e.Search(editor, false);
  97. var sb = editor.searchBox;
  98. sb.wholeWordOption.checked = !sb.wholeWordOption.checked;
  99. sb.$syncOptions();
  100. });
  101. }
  102. }, {
  103. name: "removeSecondaryCursors",
  104. exec: function (editor) {
  105. var ranges = editor.selection.ranges;
  106. if (ranges && ranges.length > 1)
  107. editor.selection.toSingleRange(ranges[ranges.length - 1]);
  108. else
  109. editor.selection.clearSelection();
  110. }
  111. }]);
  112. [{
  113. bindKey: {mac: "Ctrl-G", win: "Ctrl-G"},
  114. name: "gotoline"
  115. }, {
  116. bindKey: {mac: "Command-Shift-L|Command-F2", win: "Ctrl-Shift-L|Ctrl-F2"},
  117. name: "findAll"
  118. }, {
  119. bindKey: {mac: "Shift-F8|Shift-Option-F8", win: "Shift-F8|Shift-Alt-F8"},
  120. name: "goToPreviousError"
  121. }, {
  122. bindKey: {mac: "F8|Option-F8", win: "F8|Alt-F8"},
  123. name: "goToNextError"
  124. }, {
  125. bindKey: {mac: "Command-Shift-P|F1", win: "Ctrl-Shift-P|F1"},
  126. name: "openCommandPallete"
  127. }, {
  128. bindKey: {mac: "Command-K|Command-S", win: "Ctrl-K|Ctrl-S"},
  129. name: "showKeyboardShortcuts"
  130. }, {
  131. bindKey: {mac: "Shift-Option-Up", win: "Alt-Shift-Up"},
  132. name: "copylinesup"
  133. }, {
  134. bindKey: {mac: "Shift-Option-Down", win: "Alt-Shift-Down"},
  135. name: "copylinesdown"
  136. }, {
  137. bindKey: {mac: "Command-Shift-K", win: "Ctrl-Shift-K"},
  138. name: "removeline"
  139. }, {
  140. bindKey: {mac: "Command-Enter", win: "Ctrl-Enter"},
  141. name: "addLineAfter"
  142. }, {
  143. bindKey: {mac: "Command-Shift-Enter", win: "Ctrl-Shift-Enter"},
  144. name: "addLineBefore"
  145. }, {
  146. bindKey: {mac: "Command-Shift-\\", win: "Ctrl-Shift-\\"},
  147. name: "jumptomatching"
  148. }, {
  149. bindKey: {mac: "Command-]", win: "Ctrl-]"},
  150. name: "blockindent"
  151. }, {
  152. bindKey: {mac: "Command-[", win: "Ctrl-["},
  153. name: "blockoutdent"
  154. }, {
  155. bindKey: {mac: "Ctrl-PageDown", win: "Alt-PageDown"},
  156. name: "pagedown"
  157. }, {
  158. bindKey: {mac: "Ctrl-PageUp", win: "Alt-PageUp"},
  159. name: "pageup"
  160. }, {
  161. bindKey: {mac: "Shift-Option-A", win: "Shift-Alt-A"},
  162. name: "toggleBlockComment"
  163. }, {
  164. bindKey: {mac: "Option-Z", win: "Alt-Z"},
  165. name: "toggleWordWrap"
  166. }, {
  167. bindKey: {mac: "Command-G", win: "F3|Ctrl-K Ctrl-D"},
  168. name: "findnext"
  169. }, {
  170. bindKey: {mac: "Command-Shift-G", win: "Shift-F3"},
  171. name: "findprevious"
  172. }, {
  173. bindKey: {mac: "Option-Enter", win: "Alt-Enter"},
  174. name: "selectAllMatches"
  175. }, {
  176. bindKey: {mac: "Command-D", win: "Ctrl-D"},
  177. name: "selectMoreAfter"
  178. }, {
  179. bindKey: {mac: "Command-K Command-D", win: "Ctrl-K Ctrl-D"},
  180. name: "selectOrFindNext"
  181. }, {
  182. bindKey: {mac: "Shift-Option-I", win: "Shift-Alt-I"},
  183. name: "splitSelectionIntoLines"
  184. }, {
  185. bindKey: {mac: "Command-K M", win: "Ctrl-K M"},
  186. name: "modeSelect"
  187. }, {
  188. bindKey: {mac: "Command-Option-[", win: "Ctrl-Shift-["},
  189. name: "toggleFoldWidget"
  190. }, {
  191. bindKey: {mac: "Command-Option-]", win: "Ctrl-Shift-]"},
  192. name: "toggleFoldWidget"
  193. }, {
  194. bindKey: {mac: "Command-K Command-0", win: "Ctrl-K Ctrl-0"},
  195. name: "foldall"
  196. }, {
  197. bindKey: {mac: "Command-K Command-J", win: "Ctrl-K Ctrl-J"},
  198. name: "unfoldall"
  199. }, {
  200. bindKey: { mac: "Command-K Command-1", win: "Ctrl-K Ctrl-1" },
  201. name: "foldOther"
  202. }, {
  203. bindKey: { mac: "Command-K Command-Q", win: "Ctrl-K Ctrl-Q" },
  204. name: "navigateToLastEditLocation"
  205. }, {
  206. bindKey: { mac: "Command-K Command-R|Command-K Command-S", win: "Ctrl-K Ctrl-R|Ctrl-K Ctrl-S" },
  207. name: "showKeyboardShortcuts"
  208. }, {
  209. bindKey: { mac: "Command-K Command-X", win: "Ctrl-K Ctrl-X" },
  210. name: "trimTrailingSpace"
  211. }, {
  212. bindKey: {mac: "Shift-Down|Command-Shift-Down", win: "Shift-Down|Ctrl-Shift-Down"},
  213. name: "selectdown"
  214. }, {
  215. bindKey: {mac: "Shift-Up|Command-Shift-Up", win: "Shift-Up|Ctrl-Shift-Up"},
  216. name: "selectup"
  217. }, {
  218. bindKey: {mac: "Command-Alt-Enter", win: "Ctrl-Alt-Enter"},
  219. name: "replaceAll"
  220. }, {
  221. bindKey: {mac: "Command-Shift-1", win: "Ctrl-Shift-1"},
  222. name: "replaceOne"
  223. }, {
  224. bindKey: {mac: "Option-C", win: "Alt-C"},
  225. name: "toggleFindCaseSensitive"
  226. }, {
  227. bindKey: {mac: "Option-L", win: "Alt-L"},
  228. name: "toggleFindInSelection"
  229. }, {
  230. bindKey: {mac: "Option-R", win: "Alt-R"},
  231. name: "toggleFindRegex"
  232. }, {
  233. bindKey: {mac: "Option-W", win: "Alt-W"},
  234. name: "toggleFindWholeWord"
  235. }, {
  236. bindKey: {mac: "Command-L", win: "Ctrl-L"},
  237. name: "expandtoline"
  238. }, {
  239. bindKey: {mac: "Shift-Esc", win: "Shift-Esc"},
  240. name: "removeSecondaryCursors"
  241. }
  242. ].forEach(function(binding) {
  243. var command = exports.handler.commands[binding.name];
  244. if (command)
  245. command.bindKey = binding.bindKey;
  246. exports.handler.bindKey(binding.bindKey, command || binding.name);
  247. });
  248. }); (function() {
  249. ace.require(["ace/keyboard/vscode"], function(m) {
  250. if (typeof module == "object" && typeof exports == "object" && module) {
  251. module.exports = m;
  252. }
  253. });
  254. })();