-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvim.js
171 lines (145 loc) · 5.05 KB
/
vim.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/**
* Vim mode for the Cloud9 IDE
*
* @author Sergi Mansilla <[email protected]>
* @copyright 2011, Ajax.org B.V.
* @license GPLv3 <http://www.gnu.org/licenses/gpl.txt>
*/
define(function(require, exports, module) {
"use strict";
var ide = require("core/ide");
var ext = require("core/ext");
var editors = require("ext/editors/editors");
var code = require("ext/code/code");
var cli = require("ext/vim/cli");
var menus = require("ext/menus/menus");
var settings = require("ext/settings/settings");
var markupSettings = require("text!ext/vim/settings.xml");
var themes = require("ext/themes/themes");
//var commands = require("ext/commands/commands");
module.exports = ext.register("ext/vim/vim", {
name : "Vim mode",
dev : "Ajax.org",
type : ext.GENERAL,
deps : [editors, code, settings],
nodes : [],
alone : true,
hook : function() {
var _self = this;
var mnuKbModes = menus.addItemByPath("View/Keyboard Mode/", new apf.menu({
"onprop.visible" : function(e){
if (e.value)
mnuKbModes.select(null, settings.model.queryValue("editors/code/@keyboardmode"));
}
}), 150000);
var c = 1000;
function addItem(label) {
menus.addItemByPath("View/Keyboard Mode/" + label, new apf.item({
type: "radio",
value: label.toLowerCase(),
onclick : function(e) {
_self.setMode(mnuKbModes.getValue());
}
}), c+=100);
}
window.mnuKbModes=mnuKbModes
addItem("Default");
addItem("Vim");
addItem("Emacs");
ide.addEventListener("settings.load", function(){
// remove old setting
var codeSettings = settings.model.queryNode("editors/code");
if (codeSettings.hasAttribute("vimmode")) {
codeSettings.removeAttribute("vimmode");
}
settings.setDefaults("editors/code", [
["keyboardmode", "default"]
]);
});
//settings.addSettings("Code Editor", markupSettings);
var tryEnabling = function () {
_self.setMode();
};
ide.addEventListener("init.ext/code/code", tryEnabling);
ide.addEventListener("code.ext:defaultbindingsrestored", tryEnabling);
ide.addEventListener("theme.change", this.updateTheme.bind(this));
},
setMode: function(mode) {
if (!settings.model)
return;
var codeSettings = settings.model.queryNode("editors/code");
if (mode == undefined) {
mode = codeSettings.getAttribute("keyboardmode");
} else {
codeSettings.setAttribute("keyboardmode", mode);
settings.save();
}
ext.initExtension(this);
var editor = code.amlEditor.$editor
if (mode == "emacs" || mode == "vim")
mode = "ace/keyboard/" + mode
else
mode = null;
editor.setKeyboardHandler(mode);
if (mode) {
this.getCommandLine().show();
editor.cmdLine = this.cmdLine.ace;
editor.showCommandLine = function(val) {
editor.cmdLine.editor = editor;
module.exports.cmdLine.show();
editor.cmdLine.focus();
if (typeof val == "string")
editor.cmdLine.setValue(val, 1);
}
} else if (this.cmdLine) {
this.cmdLine.hide();
}
},
init: function() {
},
enable: function() {
},
getCommandLine: function() {
if (!this.cmdLine) {
this.cmdLine = new apf.codebox();
this.cmdLine.setHeight(19);
colMiddle.appendChild(this.cmdLine);
this.cmdLine.$ext.className = "searchbox tb_console";
this.updateTheme();
cli.initCmdLine(this.cmdLine.ace);
}
return this.cmdLine;
},
updateTheme: function() {
if (!this.cmdLine)
return;
var style = this.cmdLine.ace.container.parentNode.style;
style.padding = "2px 1px 1px 3px";
style.border = "none";
style.borderTop = "1px solid rgba(0, 0, 0, .3)";
style.boxShadow = "inset 0 3px 10px 0 rgba(0, 0, 0, .1)";
var activeTheme = themes.getActiveTheme();
if (!activeTheme)
return;
this.cmdLine.ace.setTheme(activeTheme);
style.background = activeTheme.textBg;
},
disable: function() {
var editor = code.amlEditor.$editor;
if (editor) {
editor.keyBinding.removeKeyboardHandler(editor.$vimModeHandler);
editor.keyBinding.removeKeyboardHandler(editor.$emacsModeHandler);
}
this.cmdLine && this.cmdLine.hide()
},
destroy: function() {
menus.remove("Tools/Keyboard Mode");
if (this.cmdLine) {
this.cmdLine.hide();
this.cmdLine.removeNode();
this.cmdLine = null;
}
this.$destroy();
}
});
});