index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.initVimMode = initVimMode;
  6. Object.defineProperty(exports, "VimMode", {
  7. enumerable: true,
  8. get: function get() {
  9. return _keymap_vim["default"];
  10. }
  11. });
  12. Object.defineProperty(exports, "StatusBar", {
  13. enumerable: true,
  14. get: function get() {
  15. return _statusbar["default"];
  16. }
  17. });
  18. var _keymap_vim = _interopRequireDefault(require("./cm/keymap_vim"));
  19. var _statusbar = _interopRequireDefault(require("./statusbar"));
  20. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  21. function initVimMode(editor) {
  22. var statusbarNode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  23. var StatusBarClass = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _statusbar["default"];
  24. var sanitizer = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
  25. // 注册 读取 键盘 、光标、处理事件函数 . 创建 vim 专用插入模式文本光标
  26. var vimAdapter = new _keymap_vim["default"](editor); // vim适配器 -> CMAdapter
  27. if (!statusbarNode) {
  28. vimAdapter.attach();
  29. return vimAdapter;
  30. }
  31. // 状态描述器配置
  32. var statusBar = new StatusBarClass(statusbarNode, editor, sanitizer); // vim 状态描述面板
  33. var keyBuffer = '';
  34. // vi 模式改变
  35. vimAdapter.on('vim-mode-change', function (mode) {
  36. statusBar.setMode(mode);
  37. });
  38. // vi 输入命令模式
  39. vimAdapter.on('vim-keypress', function (key) {
  40. if (key === ':') {
  41. keyBuffer = '';
  42. } else {
  43. keyBuffer += key;
  44. }
  45. statusBar.setKeyBuffer(keyBuffer);
  46. });
  47. // vi 命令输入完成
  48. vimAdapter.on('vim-command-done', function () {
  49. keyBuffer = '';
  50. statusBar.setKeyBuffer(keyBuffer);
  51. });
  52. // vi 适配器释放
  53. vimAdapter.on('dispose', function () {
  54. statusBar.toggleVisibility(false);
  55. statusBar.closeInput();
  56. statusBar.clear();
  57. });
  58. statusBar.toggleVisibility(true);
  59. vimAdapter.setStatusBar(statusBar);
  60. // 激活vi -> attachVimMap
  61. vimAdapter.attach();
  62. return vimAdapter;
  63. }