-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.js
83 lines (66 loc) · 3.03 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
define(function (require, exports, module) {
'use strict';
require('src/autocomplete');
require('src/commands');
var CodeMirror = brackets.getModule('thirdparty/CodeMirror2/lib/codemirror'),
Commands = brackets.getModule('command/Commands'),
CommandManager = brackets.getModule('command/CommandManager'),
Dialogs = brackets.getModule('widgets/Dialogs'),
DocumentManager = brackets.getModule('document/DocumentManager'),
EditorManager = brackets.getModule('editor/EditorManager'),
ExtensionUtils = brackets.getModule('utils/ExtensionUtils'),
KeyBindingManager = brackets.getModule('command/KeyBindingManager'),
MainViewManager = brackets.getModule('view/MainViewManager'),
Menus = brackets.getModule('command/Menus'),
ProjectManager = brackets.getModule('project/ProjectManager'),
StatusBar = brackets.getModule('widgets/StatusBar'),
$vimModeIndicator = $(document.createElement('div')).text('normal'),
commandId = 'brackets-vim.toggle',
fileMenu = Menus.getMenu(Menus.AppMenuBar.FILE_MENU),
isEnabled = true;
function handleVimModeChange(event) {
$vimModeIndicator.text(event.mode);
}
// Toggles vim functionality in the editor.
// This function is run by the menu item.
function toggleVim(editor) {
isEnabled = !isEnabled;
CommandManager.get(commandId).setChecked(isEnabled);
updateEditorMode();
}
// Update the active editor with the vim mode.
function updateEditorMode() {
var cm,
activeEditor = EditorManager.getActiveEditor();
if (activeEditor === null) {
return;
}
cm = activeEditor._codeMirror;
if (isEnabled !== cm.getOption('vimMode')) {
cm.setOption('vimMode', isEnabled);
cm[isEnabled ? 'on' : 'off']('vim-mode-change', handleVimModeChange);
}
}
// Register the enable command.
CommandManager.register('Enable Vim', commandId, toggleVim);
CommandManager.get(commandId).setChecked(isEnabled);
// Add the enable command to the file menu.
fileMenu.addMenuDivider();
fileMenu.addMenuItem(commandId);
ExtensionUtils.loadStyleSheet(module, 'main.css');
StatusBar.addIndicator('vim-mode', $vimModeIndicator, true);
$(ProjectManager).on('projectOpen', function (jqEvent, directory) {
// Ensure that at most one file is working when the project opens.
var workingSet = MainViewManager.getWorkingSet();
if (workingSet.length > 1) {
CommandManager.execute(Commands.FILE_CLOSE_LIST, {
PaneId: MainViewManager.ALL_PANES,
fileList: workingSet.slice(1)
});
} else if (workingSet.length === 0) {
return;
}
CommandManager.execute(Commands.CMD_ADD_TO_WORKINGSET_AND_OPEN, {fullPath: workingSet[0]._path});
});
$(DocumentManager).on('currentDocumentChange', updateEditorMode);
});