stackprofiler 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/README.md +1 -1
- data/config.ru +3 -2
- data/lib/stackprofiler.rb +0 -1
- data/lib/stackprofiler/filters/build_tree.rb +3 -4
- data/lib/stackprofiler/filters/gem_removal.rb +3 -0
- data/lib/stackprofiler/web_ui.rb +34 -11
- data/lib/stackprofiler/web_ui/public/css/stackprofiler.css +77 -0
- data/lib/stackprofiler/web_ui/public/js/stackprofiler.js +129 -58
- data/lib/stackprofiler/web_ui/public/vendor/ace/ace.js +18298 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-beautify.js +334 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-chromevox.js +541 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-elastic_tabstops_lite.js +275 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-emmet.js +1190 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-error_marker.js +6 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-keybinding_menu.js +170 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-language_tools.js +1934 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-linking.js +52 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-modelist.js +187 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-old_ie.js +494 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-searchbox.js +409 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-settings_menu.js +637 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-spellcheck.js +71 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-split.js +246 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-static_highlight.js +154 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-statusbar.js +51 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-textarea.js +632 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-themelist.js +58 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/ext-whitespace.js +181 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/keybinding-emacs.js +1182 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/keybinding-vim.js +5320 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/mode-haml.js +525 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/mode-html.js +2427 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/mode-html_ruby.js +2955 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/mode-javascript.js +1025 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/mode-json.js +668 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/mode-ruby.js +839 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/mode-xml.js +637 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/mode-yaml.js +256 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/theme-xcode.js +89 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/worker-coffee.js +7599 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/worker-css.js +8682 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/worker-html.js +11527 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/worker-javascript.js +10429 -0
- data/lib/stackprofiler/web_ui/public/vendor/ace/worker-json.js +2319 -0
- data/lib/stackprofiler/web_ui/views/index.erb +1 -1
- data/lib/stackprofiler/web_ui/views/layout.erb +2 -55
- data/stackprofiler.gemspec +2 -4
- metadata +42 -19
- data/lib/stackprofiler/web_ui/views/code.erb +0 -17
@@ -0,0 +1,58 @@
|
|
1
|
+
ace.define("ace/ext/themelist",["require","exports","module","ace/lib/fixoldbrowsers"], function(require, exports, module) {
|
2
|
+
"use strict";
|
3
|
+
require("ace/lib/fixoldbrowsers");
|
4
|
+
|
5
|
+
var themeData = [
|
6
|
+
["Chrome" ],
|
7
|
+
["Clouds" ],
|
8
|
+
["Crimson Editor" ],
|
9
|
+
["Dawn" ],
|
10
|
+
["Dreamweaver" ],
|
11
|
+
["Eclipse" ],
|
12
|
+
["GitHub" ],
|
13
|
+
["Solarized Light"],
|
14
|
+
["TextMate" ],
|
15
|
+
["Tomorrow" ],
|
16
|
+
["XCode" ],
|
17
|
+
["Kuroir"],
|
18
|
+
["KatzenMilch"],
|
19
|
+
["Ambiance" ,"ambiance" , "dark"],
|
20
|
+
["Chaos" ,"chaos" , "dark"],
|
21
|
+
["Clouds Midnight" ,"clouds_midnight" , "dark"],
|
22
|
+
["Cobalt" ,"cobalt" , "dark"],
|
23
|
+
["idle Fingers" ,"idle_fingers" , "dark"],
|
24
|
+
["krTheme" ,"kr_theme" , "dark"],
|
25
|
+
["Merbivore" ,"merbivore" , "dark"],
|
26
|
+
["Merbivore Soft" ,"merbivore_soft" , "dark"],
|
27
|
+
["Mono Industrial" ,"mono_industrial" , "dark"],
|
28
|
+
["Monokai" ,"monokai" , "dark"],
|
29
|
+
["Pastel on dark" ,"pastel_on_dark" , "dark"],
|
30
|
+
["Solarized Dark" ,"solarized_dark" , "dark"],
|
31
|
+
["Terminal" ,"terminal" , "dark"],
|
32
|
+
["Tomorrow Night" ,"tomorrow_night" , "dark"],
|
33
|
+
["Tomorrow Night Blue" ,"tomorrow_night_blue" , "dark"],
|
34
|
+
["Tomorrow Night Bright","tomorrow_night_bright" , "dark"],
|
35
|
+
["Tomorrow Night 80s" ,"tomorrow_night_eighties" , "dark"],
|
36
|
+
["Twilight" ,"twilight" , "dark"],
|
37
|
+
["Vibrant Ink" ,"vibrant_ink" , "dark"]
|
38
|
+
];
|
39
|
+
|
40
|
+
|
41
|
+
exports.themesByName = {};
|
42
|
+
exports.themes = themeData.map(function(data) {
|
43
|
+
var name = data[1] || data[0].replace(/ /g, "_").toLowerCase();
|
44
|
+
var theme = {
|
45
|
+
caption: data[0],
|
46
|
+
theme: "ace/theme/" + name,
|
47
|
+
isDark: data[2] == "dark",
|
48
|
+
name: name
|
49
|
+
};
|
50
|
+
exports.themesByName[name] = theme;
|
51
|
+
return theme;
|
52
|
+
});
|
53
|
+
|
54
|
+
});
|
55
|
+
(function() {
|
56
|
+
ace.require(["ace/ext/themelist"], function() {});
|
57
|
+
})();
|
58
|
+
|
@@ -0,0 +1,181 @@
|
|
1
|
+
ace.define("ace/ext/whitespace",["require","exports","module","ace/lib/lang"], function(require, exports, module) {
|
2
|
+
"use strict";
|
3
|
+
|
4
|
+
var lang = require("../lib/lang");
|
5
|
+
exports.$detectIndentation = function(lines, fallback) {
|
6
|
+
var stats = [];
|
7
|
+
var changes = [];
|
8
|
+
var tabIndents = 0;
|
9
|
+
var prevSpaces = 0;
|
10
|
+
var max = Math.min(lines.length, 1000);
|
11
|
+
for (var i = 0; i < max; i++) {
|
12
|
+
var line = lines[i];
|
13
|
+
if (!/^\s*[^*+\-\s]/.test(line))
|
14
|
+
continue;
|
15
|
+
|
16
|
+
if (line[0] == "\t")
|
17
|
+
tabIndents++;
|
18
|
+
|
19
|
+
var spaces = line.match(/^ */)[0].length;
|
20
|
+
if (spaces && line[spaces] != "\t") {
|
21
|
+
var diff = spaces - prevSpaces;
|
22
|
+
if (diff > 0 && !(prevSpaces%diff) && !(spaces%diff))
|
23
|
+
changes[diff] = (changes[diff] || 0) + 1;
|
24
|
+
|
25
|
+
stats[spaces] = (stats[spaces] || 0) + 1;
|
26
|
+
}
|
27
|
+
prevSpaces = spaces;
|
28
|
+
while (i < max && line[line.length - 1] == "\\")
|
29
|
+
line = lines[i++];
|
30
|
+
}
|
31
|
+
|
32
|
+
function getScore(indent) {
|
33
|
+
var score = 0;
|
34
|
+
for (var i = indent; i < stats.length; i += indent)
|
35
|
+
score += stats[i] || 0;
|
36
|
+
return score;
|
37
|
+
}
|
38
|
+
|
39
|
+
var changesTotal = changes.reduce(function(a,b){return a+b}, 0);
|
40
|
+
|
41
|
+
var first = {score: 0, length: 0};
|
42
|
+
var spaceIndents = 0;
|
43
|
+
for (var i = 1; i < 12; i++) {
|
44
|
+
var score = getScore(i);
|
45
|
+
if (i == 1) {
|
46
|
+
spaceIndents = score;
|
47
|
+
score = stats[1] ? 0.9 : 0.8;
|
48
|
+
if (!stats.length)
|
49
|
+
score = 0
|
50
|
+
} else
|
51
|
+
score /= spaceIndents;
|
52
|
+
|
53
|
+
if (changes[i])
|
54
|
+
score += changes[i] / changesTotal;
|
55
|
+
|
56
|
+
if (score > first.score)
|
57
|
+
first = {score: score, length: i};
|
58
|
+
}
|
59
|
+
|
60
|
+
if (first.score && first.score > 1.4)
|
61
|
+
var tabLength = first.length;
|
62
|
+
|
63
|
+
if (tabIndents > spaceIndents + 1)
|
64
|
+
return {ch: "\t", length: tabLength};
|
65
|
+
|
66
|
+
if (spaceIndents > tabIndents + 1)
|
67
|
+
return {ch: " ", length: tabLength};
|
68
|
+
};
|
69
|
+
|
70
|
+
exports.detectIndentation = function(session) {
|
71
|
+
var lines = session.getLines(0, 1000);
|
72
|
+
var indent = exports.$detectIndentation(lines) || {};
|
73
|
+
|
74
|
+
if (indent.ch)
|
75
|
+
session.setUseSoftTabs(indent.ch == " ");
|
76
|
+
|
77
|
+
if (indent.length)
|
78
|
+
session.setTabSize(indent.length);
|
79
|
+
return indent;
|
80
|
+
};
|
81
|
+
|
82
|
+
exports.trimTrailingSpace = function(session, trimEmpty) {
|
83
|
+
var doc = session.getDocument();
|
84
|
+
var lines = doc.getAllLines();
|
85
|
+
|
86
|
+
var min = trimEmpty ? -1 : 0;
|
87
|
+
|
88
|
+
for (var i = 0, l=lines.length; i < l; i++) {
|
89
|
+
var line = lines[i];
|
90
|
+
var index = line.search(/\s+$/);
|
91
|
+
|
92
|
+
if (index > min)
|
93
|
+
doc.removeInLine(i, index, line.length);
|
94
|
+
}
|
95
|
+
};
|
96
|
+
|
97
|
+
exports.convertIndentation = function(session, ch, len) {
|
98
|
+
var oldCh = session.getTabString()[0];
|
99
|
+
var oldLen = session.getTabSize();
|
100
|
+
if (!len) len = oldLen;
|
101
|
+
if (!ch) ch = oldCh;
|
102
|
+
|
103
|
+
var tab = ch == "\t" ? ch: lang.stringRepeat(ch, len);
|
104
|
+
|
105
|
+
var doc = session.doc;
|
106
|
+
var lines = doc.getAllLines();
|
107
|
+
|
108
|
+
var cache = {};
|
109
|
+
var spaceCache = {};
|
110
|
+
for (var i = 0, l=lines.length; i < l; i++) {
|
111
|
+
var line = lines[i];
|
112
|
+
var match = line.match(/^\s*/)[0];
|
113
|
+
if (match) {
|
114
|
+
var w = session.$getStringScreenWidth(match)[0];
|
115
|
+
var tabCount = Math.floor(w/oldLen);
|
116
|
+
var reminder = w%oldLen;
|
117
|
+
var toInsert = cache[tabCount] || (cache[tabCount] = lang.stringRepeat(tab, tabCount));
|
118
|
+
toInsert += spaceCache[reminder] || (spaceCache[reminder] = lang.stringRepeat(" ", reminder));
|
119
|
+
|
120
|
+
if (toInsert != match) {
|
121
|
+
doc.removeInLine(i, 0, match.length);
|
122
|
+
doc.insertInLine({row: i, column: 0}, toInsert);
|
123
|
+
}
|
124
|
+
}
|
125
|
+
}
|
126
|
+
session.setTabSize(len);
|
127
|
+
session.setUseSoftTabs(ch == " ");
|
128
|
+
};
|
129
|
+
|
130
|
+
exports.$parseStringArg = function(text) {
|
131
|
+
var indent = {};
|
132
|
+
if (/t/.test(text))
|
133
|
+
indent.ch = "\t";
|
134
|
+
else if (/s/.test(text))
|
135
|
+
indent.ch = " ";
|
136
|
+
var m = text.match(/\d+/);
|
137
|
+
if (m)
|
138
|
+
indent.length = parseInt(m[0], 10);
|
139
|
+
return indent;
|
140
|
+
};
|
141
|
+
|
142
|
+
exports.$parseArg = function(arg) {
|
143
|
+
if (!arg)
|
144
|
+
return {};
|
145
|
+
if (typeof arg == "string")
|
146
|
+
return exports.$parseStringArg(arg);
|
147
|
+
if (typeof arg.text == "string")
|
148
|
+
return exports.$parseStringArg(arg.text);
|
149
|
+
return arg;
|
150
|
+
};
|
151
|
+
|
152
|
+
exports.commands = [{
|
153
|
+
name: "detectIndentation",
|
154
|
+
exec: function(editor) {
|
155
|
+
exports.detectIndentation(editor.session);
|
156
|
+
}
|
157
|
+
}, {
|
158
|
+
name: "trimTrailingSpace",
|
159
|
+
exec: function(editor) {
|
160
|
+
exports.trimTrailingSpace(editor.session);
|
161
|
+
}
|
162
|
+
}, {
|
163
|
+
name: "convertIndentation",
|
164
|
+
exec: function(editor, arg) {
|
165
|
+
var indent = exports.$parseArg(arg);
|
166
|
+
exports.convertIndentation(editor.session, indent.ch, indent.length);
|
167
|
+
}
|
168
|
+
}, {
|
169
|
+
name: "setIndentation",
|
170
|
+
exec: function(editor, arg) {
|
171
|
+
var indent = exports.$parseArg(arg);
|
172
|
+
indent.length && editor.session.setTabSize(indent.length);
|
173
|
+
indent.ch && editor.session.setUseSoftTabs(indent.ch == " ");
|
174
|
+
}
|
175
|
+
}];
|
176
|
+
|
177
|
+
});
|
178
|
+
(function() {
|
179
|
+
ace.require(["ace/ext/whitespace"], function() {});
|
180
|
+
})();
|
181
|
+
|
@@ -0,0 +1,1182 @@
|
|
1
|
+
ace.define("ace/occur",["require","exports","module","ace/lib/oop","ace/range","ace/search","ace/edit_session","ace/search_highlight","ace/lib/dom"], function(require, exports, module) {
|
2
|
+
"use strict";
|
3
|
+
|
4
|
+
var oop = require("./lib/oop");
|
5
|
+
var Range = require("./range").Range;
|
6
|
+
var Search = require("./search").Search;
|
7
|
+
var EditSession = require("./edit_session").EditSession;
|
8
|
+
var SearchHighlight = require("./search_highlight").SearchHighlight;
|
9
|
+
function Occur() {}
|
10
|
+
|
11
|
+
oop.inherits(Occur, Search);
|
12
|
+
|
13
|
+
(function() {
|
14
|
+
this.enter = function(editor, options) {
|
15
|
+
if (!options.needle) return false;
|
16
|
+
var pos = editor.getCursorPosition();
|
17
|
+
this.displayOccurContent(editor, options);
|
18
|
+
var translatedPos = this.originalToOccurPosition(editor.session, pos);
|
19
|
+
editor.moveCursorToPosition(translatedPos);
|
20
|
+
return true;
|
21
|
+
}
|
22
|
+
this.exit = function(editor, options) {
|
23
|
+
var pos = options.translatePosition && editor.getCursorPosition();
|
24
|
+
var translatedPos = pos && this.occurToOriginalPosition(editor.session, pos);
|
25
|
+
this.displayOriginalContent(editor);
|
26
|
+
if (translatedPos)
|
27
|
+
editor.moveCursorToPosition(translatedPos);
|
28
|
+
return true;
|
29
|
+
}
|
30
|
+
|
31
|
+
this.highlight = function(sess, regexp) {
|
32
|
+
var hl = sess.$occurHighlight = sess.$occurHighlight || sess.addDynamicMarker(
|
33
|
+
new SearchHighlight(null, "ace_occur-highlight", "text"));
|
34
|
+
hl.setRegexp(regexp);
|
35
|
+
sess._emit("changeBackMarker"); // force highlight layer redraw
|
36
|
+
}
|
37
|
+
|
38
|
+
this.displayOccurContent = function(editor, options) {
|
39
|
+
this.$originalSession = editor.session;
|
40
|
+
var found = this.matchingLines(editor.session, options);
|
41
|
+
var lines = found.map(function(foundLine) { return foundLine.content; });
|
42
|
+
var occurSession = new EditSession(lines.join('\n'));
|
43
|
+
occurSession.$occur = this;
|
44
|
+
occurSession.$occurMatchingLines = found;
|
45
|
+
editor.setSession(occurSession);
|
46
|
+
this.$useEmacsStyleLineStart = this.$originalSession.$useEmacsStyleLineStart;
|
47
|
+
occurSession.$useEmacsStyleLineStart = this.$useEmacsStyleLineStart;
|
48
|
+
this.highlight(occurSession, options.re);
|
49
|
+
occurSession._emit('changeBackMarker');
|
50
|
+
}
|
51
|
+
|
52
|
+
this.displayOriginalContent = function(editor) {
|
53
|
+
editor.setSession(this.$originalSession);
|
54
|
+
this.$originalSession.$useEmacsStyleLineStart = this.$useEmacsStyleLineStart;
|
55
|
+
}
|
56
|
+
this.originalToOccurPosition = function(session, pos) {
|
57
|
+
var lines = session.$occurMatchingLines;
|
58
|
+
var nullPos = {row: 0, column: 0};
|
59
|
+
if (!lines) return nullPos;
|
60
|
+
for (var i = 0; i < lines.length; i++) {
|
61
|
+
if (lines[i].row === pos.row)
|
62
|
+
return {row: i, column: pos.column};
|
63
|
+
}
|
64
|
+
return nullPos;
|
65
|
+
}
|
66
|
+
this.occurToOriginalPosition = function(session, pos) {
|
67
|
+
var lines = session.$occurMatchingLines;
|
68
|
+
if (!lines || !lines[pos.row])
|
69
|
+
return pos;
|
70
|
+
return {row: lines[pos.row].row, column: pos.column};
|
71
|
+
}
|
72
|
+
|
73
|
+
this.matchingLines = function(session, options) {
|
74
|
+
options = oop.mixin({}, options);
|
75
|
+
if (!session || !options.needle) return [];
|
76
|
+
var search = new Search();
|
77
|
+
search.set(options);
|
78
|
+
return search.findAll(session).reduce(function(lines, range) {
|
79
|
+
var row = range.start.row;
|
80
|
+
var last = lines[lines.length-1];
|
81
|
+
return last && last.row === row ?
|
82
|
+
lines :
|
83
|
+
lines.concat({row: row, content: session.getLine(row)});
|
84
|
+
}, []);
|
85
|
+
}
|
86
|
+
|
87
|
+
}).call(Occur.prototype);
|
88
|
+
|
89
|
+
var dom = require('./lib/dom');
|
90
|
+
dom.importCssString(".ace_occur-highlight {\n\
|
91
|
+
border-radius: 4px;\n\
|
92
|
+
background-color: rgba(87, 255, 8, 0.25);\n\
|
93
|
+
position: absolute;\n\
|
94
|
+
z-index: 4;\n\
|
95
|
+
-moz-box-sizing: border-box;\n\
|
96
|
+
-webkit-box-sizing: border-box;\n\
|
97
|
+
box-sizing: border-box;\n\
|
98
|
+
box-shadow: 0 0 4px rgb(91, 255, 50);\n\
|
99
|
+
}\n\
|
100
|
+
.ace_dark .ace_occur-highlight {\n\
|
101
|
+
background-color: rgb(80, 140, 85);\n\
|
102
|
+
box-shadow: 0 0 4px rgb(60, 120, 70);\n\
|
103
|
+
}\n", "incremental-occur-highlighting");
|
104
|
+
|
105
|
+
exports.Occur = Occur;
|
106
|
+
|
107
|
+
});
|
108
|
+
|
109
|
+
ace.define("ace/commands/occur_commands",["require","exports","module","ace/config","ace/occur","ace/keyboard/hash_handler","ace/lib/oop"], function(require, exports, module) {
|
110
|
+
|
111
|
+
var config = require("../config"),
|
112
|
+
Occur = require("../occur").Occur;
|
113
|
+
var occurStartCommand = {
|
114
|
+
name: "occur",
|
115
|
+
exec: function(editor, options) {
|
116
|
+
var alreadyInOccur = !!editor.session.$occur;
|
117
|
+
var occurSessionActive = new Occur().enter(editor, options);
|
118
|
+
if (occurSessionActive && !alreadyInOccur)
|
119
|
+
OccurKeyboardHandler.installIn(editor);
|
120
|
+
},
|
121
|
+
readOnly: true
|
122
|
+
};
|
123
|
+
|
124
|
+
var occurCommands = [{
|
125
|
+
name: "occurexit",
|
126
|
+
bindKey: 'esc|Ctrl-G',
|
127
|
+
exec: function(editor) {
|
128
|
+
var occur = editor.session.$occur;
|
129
|
+
if (!occur) return;
|
130
|
+
occur.exit(editor, {});
|
131
|
+
if (!editor.session.$occur) OccurKeyboardHandler.uninstallFrom(editor);
|
132
|
+
},
|
133
|
+
readOnly: true
|
134
|
+
}, {
|
135
|
+
name: "occuraccept",
|
136
|
+
bindKey: 'enter',
|
137
|
+
exec: function(editor) {
|
138
|
+
var occur = editor.session.$occur;
|
139
|
+
if (!occur) return;
|
140
|
+
occur.exit(editor, {translatePosition: true});
|
141
|
+
if (!editor.session.$occur) OccurKeyboardHandler.uninstallFrom(editor);
|
142
|
+
},
|
143
|
+
readOnly: true
|
144
|
+
}];
|
145
|
+
|
146
|
+
var HashHandler = require("../keyboard/hash_handler").HashHandler;
|
147
|
+
var oop = require("../lib/oop");
|
148
|
+
|
149
|
+
|
150
|
+
function OccurKeyboardHandler() {}
|
151
|
+
|
152
|
+
oop.inherits(OccurKeyboardHandler, HashHandler);
|
153
|
+
|
154
|
+
;(function() {
|
155
|
+
|
156
|
+
this.isOccurHandler = true;
|
157
|
+
|
158
|
+
this.attach = function(editor) {
|
159
|
+
HashHandler.call(this, occurCommands, editor.commands.platform);
|
160
|
+
this.$editor = editor;
|
161
|
+
}
|
162
|
+
|
163
|
+
var handleKeyboard$super = this.handleKeyboard;
|
164
|
+
this.handleKeyboard = function(data, hashId, key, keyCode) {
|
165
|
+
var cmd = handleKeyboard$super.call(this, data, hashId, key, keyCode);
|
166
|
+
return (cmd && cmd.command) ? cmd : undefined;
|
167
|
+
}
|
168
|
+
|
169
|
+
}).call(OccurKeyboardHandler.prototype);
|
170
|
+
|
171
|
+
OccurKeyboardHandler.installIn = function(editor) {
|
172
|
+
var handler = new this();
|
173
|
+
editor.keyBinding.addKeyboardHandler(handler);
|
174
|
+
editor.commands.addCommands(occurCommands);
|
175
|
+
}
|
176
|
+
|
177
|
+
OccurKeyboardHandler.uninstallFrom = function(editor) {
|
178
|
+
editor.commands.removeCommands(occurCommands);
|
179
|
+
var handler = editor.getKeyboardHandler();
|
180
|
+
if (handler.isOccurHandler)
|
181
|
+
editor.keyBinding.removeKeyboardHandler(handler);
|
182
|
+
}
|
183
|
+
|
184
|
+
exports.occurStartCommand = occurStartCommand;
|
185
|
+
|
186
|
+
});
|
187
|
+
|
188
|
+
ace.define("ace/commands/incremental_search_commands",["require","exports","module","ace/config","ace/lib/oop","ace/keyboard/hash_handler","ace/commands/occur_commands"], function(require, exports, module) {
|
189
|
+
|
190
|
+
var config = require("../config");
|
191
|
+
var oop = require("../lib/oop");
|
192
|
+
var HashHandler = require("../keyboard/hash_handler").HashHandler;
|
193
|
+
var occurStartCommand = require("./occur_commands").occurStartCommand;
|
194
|
+
exports.iSearchStartCommands = [{
|
195
|
+
name: "iSearch",
|
196
|
+
bindKey: {win: "Ctrl-F", mac: "Command-F"},
|
197
|
+
exec: function(editor, options) {
|
198
|
+
config.loadModule(["core", "ace/incremental_search"], function(e) {
|
199
|
+
var iSearch = e.iSearch = e.iSearch || new e.IncrementalSearch();
|
200
|
+
iSearch.activate(editor, options.backwards);
|
201
|
+
if (options.jumpToFirstMatch) iSearch.next(options);
|
202
|
+
});
|
203
|
+
},
|
204
|
+
readOnly: true
|
205
|
+
}, {
|
206
|
+
name: "iSearchBackwards",
|
207
|
+
exec: function(editor, jumpToNext) { editor.execCommand('iSearch', {backwards: true}); },
|
208
|
+
readOnly: true
|
209
|
+
}, {
|
210
|
+
name: "iSearchAndGo",
|
211
|
+
bindKey: {win: "Ctrl-K", mac: "Command-G"},
|
212
|
+
exec: function(editor, jumpToNext) { editor.execCommand('iSearch', {jumpToFirstMatch: true, useCurrentOrPrevSearch: true}); },
|
213
|
+
readOnly: true
|
214
|
+
}, {
|
215
|
+
name: "iSearchBackwardsAndGo",
|
216
|
+
bindKey: {win: "Ctrl-Shift-K", mac: "Command-Shift-G"},
|
217
|
+
exec: function(editor) { editor.execCommand('iSearch', {jumpToFirstMatch: true, backwards: true, useCurrentOrPrevSearch: true}); },
|
218
|
+
readOnly: true
|
219
|
+
}];
|
220
|
+
exports.iSearchCommands = [{
|
221
|
+
name: "restartSearch",
|
222
|
+
bindKey: {win: "Ctrl-F", mac: "Command-F"},
|
223
|
+
exec: function(iSearch) {
|
224
|
+
iSearch.cancelSearch(true);
|
225
|
+
},
|
226
|
+
readOnly: true,
|
227
|
+
isIncrementalSearchCommand: true
|
228
|
+
}, {
|
229
|
+
name: "searchForward",
|
230
|
+
bindKey: {win: "Ctrl-S|Ctrl-K", mac: "Ctrl-S|Command-G"},
|
231
|
+
exec: function(iSearch, options) {
|
232
|
+
options.useCurrentOrPrevSearch = true;
|
233
|
+
iSearch.next(options);
|
234
|
+
},
|
235
|
+
readOnly: true,
|
236
|
+
isIncrementalSearchCommand: true
|
237
|
+
}, {
|
238
|
+
name: "searchBackward",
|
239
|
+
bindKey: {win: "Ctrl-R|Ctrl-Shift-K", mac: "Ctrl-R|Command-Shift-G"},
|
240
|
+
exec: function(iSearch, options) {
|
241
|
+
options.useCurrentOrPrevSearch = true;
|
242
|
+
options.backwards = true;
|
243
|
+
iSearch.next(options);
|
244
|
+
},
|
245
|
+
readOnly: true,
|
246
|
+
isIncrementalSearchCommand: true
|
247
|
+
}, {
|
248
|
+
name: "extendSearchTerm",
|
249
|
+
exec: function(iSearch, string) {
|
250
|
+
iSearch.addString(string);
|
251
|
+
},
|
252
|
+
readOnly: true,
|
253
|
+
isIncrementalSearchCommand: true
|
254
|
+
}, {
|
255
|
+
name: "extendSearchTermSpace",
|
256
|
+
bindKey: "space",
|
257
|
+
exec: function(iSearch) { iSearch.addString(' '); },
|
258
|
+
readOnly: true,
|
259
|
+
isIncrementalSearchCommand: true
|
260
|
+
}, {
|
261
|
+
name: "shrinkSearchTerm",
|
262
|
+
bindKey: "backspace",
|
263
|
+
exec: function(iSearch) {
|
264
|
+
iSearch.removeChar();
|
265
|
+
},
|
266
|
+
readOnly: true,
|
267
|
+
isIncrementalSearchCommand: true
|
268
|
+
}, {
|
269
|
+
name: 'confirmSearch',
|
270
|
+
bindKey: 'return',
|
271
|
+
exec: function(iSearch) { iSearch.deactivate(); },
|
272
|
+
readOnly: true,
|
273
|
+
isIncrementalSearchCommand: true
|
274
|
+
}, {
|
275
|
+
name: 'cancelSearch',
|
276
|
+
bindKey: 'esc|Ctrl-G',
|
277
|
+
exec: function(iSearch) { iSearch.deactivate(true); },
|
278
|
+
readOnly: true,
|
279
|
+
isIncrementalSearchCommand: true
|
280
|
+
}, {
|
281
|
+
name: 'occurisearch',
|
282
|
+
bindKey: 'Ctrl-O',
|
283
|
+
exec: function(iSearch) {
|
284
|
+
var options = oop.mixin({}, iSearch.$options);
|
285
|
+
iSearch.deactivate();
|
286
|
+
occurStartCommand.exec(iSearch.$editor, options);
|
287
|
+
},
|
288
|
+
readOnly: true,
|
289
|
+
isIncrementalSearchCommand: true
|
290
|
+
}, {
|
291
|
+
name: "yankNextWord",
|
292
|
+
bindKey: "Ctrl-w",
|
293
|
+
exec: function(iSearch) {
|
294
|
+
var ed = iSearch.$editor,
|
295
|
+
range = ed.selection.getRangeOfMovements(function(sel) { sel.moveCursorWordRight(); }),
|
296
|
+
string = ed.session.getTextRange(range);
|
297
|
+
iSearch.addString(string);
|
298
|
+
},
|
299
|
+
readOnly: true,
|
300
|
+
isIncrementalSearchCommand: true
|
301
|
+
}, {
|
302
|
+
name: "yankNextChar",
|
303
|
+
bindKey: "Ctrl-Alt-y",
|
304
|
+
exec: function(iSearch) {
|
305
|
+
var ed = iSearch.$editor,
|
306
|
+
range = ed.selection.getRangeOfMovements(function(sel) { sel.moveCursorRight(); }),
|
307
|
+
string = ed.session.getTextRange(range);
|
308
|
+
iSearch.addString(string);
|
309
|
+
},
|
310
|
+
readOnly: true,
|
311
|
+
isIncrementalSearchCommand: true
|
312
|
+
}, {
|
313
|
+
name: 'recenterTopBottom',
|
314
|
+
bindKey: 'Ctrl-l',
|
315
|
+
exec: function(iSearch) { iSearch.$editor.execCommand('recenterTopBottom'); },
|
316
|
+
readOnly: true,
|
317
|
+
isIncrementalSearchCommand: true
|
318
|
+
}, {
|
319
|
+
name: 'selectAllMatches',
|
320
|
+
bindKey: 'Ctrl-space',
|
321
|
+
exec: function(iSearch) {
|
322
|
+
var ed = iSearch.$editor,
|
323
|
+
hl = ed.session.$isearchHighlight,
|
324
|
+
ranges = hl && hl.cache ? hl.cache
|
325
|
+
.reduce(function(ranges, ea) {
|
326
|
+
return ranges.concat(ea ? ea : []); }, []) : [];
|
327
|
+
iSearch.deactivate(false);
|
328
|
+
ranges.forEach(ed.selection.addRange.bind(ed.selection));
|
329
|
+
},
|
330
|
+
readOnly: true,
|
331
|
+
isIncrementalSearchCommand: true
|
332
|
+
}, {
|
333
|
+
name: 'searchAsRegExp',
|
334
|
+
bindKey: 'Alt-r',
|
335
|
+
exec: function(iSearch) {
|
336
|
+
iSearch.convertNeedleToRegExp();
|
337
|
+
},
|
338
|
+
readOnly: true,
|
339
|
+
isIncrementalSearchCommand: true
|
340
|
+
}];
|
341
|
+
|
342
|
+
function IncrementalSearchKeyboardHandler(iSearch) {
|
343
|
+
this.$iSearch = iSearch;
|
344
|
+
}
|
345
|
+
|
346
|
+
oop.inherits(IncrementalSearchKeyboardHandler, HashHandler);
|
347
|
+
|
348
|
+
;(function() {
|
349
|
+
|
350
|
+
this.attach = function(editor) {
|
351
|
+
var iSearch = this.$iSearch;
|
352
|
+
HashHandler.call(this, exports.iSearchCommands, editor.commands.platform);
|
353
|
+
this.$commandExecHandler = editor.commands.addEventListener('exec', function(e) {
|
354
|
+
if (!e.command.isIncrementalSearchCommand) return undefined;
|
355
|
+
e.stopPropagation();
|
356
|
+
e.preventDefault();
|
357
|
+
return e.command.exec(iSearch, e.args || {});
|
358
|
+
});
|
359
|
+
}
|
360
|
+
|
361
|
+
this.detach = function(editor) {
|
362
|
+
if (!this.$commandExecHandler) return;
|
363
|
+
editor.commands.removeEventListener('exec', this.$commandExecHandler);
|
364
|
+
delete this.$commandExecHandler;
|
365
|
+
}
|
366
|
+
|
367
|
+
var handleKeyboard$super = this.handleKeyboard;
|
368
|
+
this.handleKeyboard = function(data, hashId, key, keyCode) {
|
369
|
+
if (((hashId === 1/*ctrl*/ || hashId === 8/*command*/) && key === 'v')
|
370
|
+
|| (hashId === 1/*ctrl*/ && key === 'y')) return null;
|
371
|
+
var cmd = handleKeyboard$super.call(this, data, hashId, key, keyCode);
|
372
|
+
if (cmd.command) { return cmd; }
|
373
|
+
if (hashId == -1) {
|
374
|
+
var extendCmd = this.commands.extendSearchTerm;
|
375
|
+
if (extendCmd) { return {command: extendCmd, args: key}; }
|
376
|
+
}
|
377
|
+
return {command: "null", passEvent: hashId == 0 || hashId == 4};
|
378
|
+
}
|
379
|
+
|
380
|
+
}).call(IncrementalSearchKeyboardHandler.prototype);
|
381
|
+
|
382
|
+
|
383
|
+
exports.IncrementalSearchKeyboardHandler = IncrementalSearchKeyboardHandler;
|
384
|
+
|
385
|
+
});
|
386
|
+
|
387
|
+
ace.define("ace/incremental_search",["require","exports","module","ace/lib/oop","ace/range","ace/search","ace/search_highlight","ace/commands/incremental_search_commands","ace/lib/dom","ace/commands/command_manager","ace/editor","ace/config"], function(require, exports, module) {
|
388
|
+
"use strict";
|
389
|
+
|
390
|
+
var oop = require("./lib/oop");
|
391
|
+
var Range = require("./range").Range;
|
392
|
+
var Search = require("./search").Search;
|
393
|
+
var SearchHighlight = require("./search_highlight").SearchHighlight;
|
394
|
+
var iSearchCommandModule = require("./commands/incremental_search_commands");
|
395
|
+
var ISearchKbd = iSearchCommandModule.IncrementalSearchKeyboardHandler;
|
396
|
+
function IncrementalSearch() {
|
397
|
+
this.$options = {wrap: false, skipCurrent: false};
|
398
|
+
this.$keyboardHandler = new ISearchKbd(this);
|
399
|
+
}
|
400
|
+
|
401
|
+
oop.inherits(IncrementalSearch, Search);
|
402
|
+
|
403
|
+
function isRegExp(obj) {
|
404
|
+
return obj instanceof RegExp;
|
405
|
+
}
|
406
|
+
|
407
|
+
function regExpToObject(re) {
|
408
|
+
var string = String(re),
|
409
|
+
start = string.indexOf('/'),
|
410
|
+
flagStart = string.lastIndexOf('/');
|
411
|
+
return {
|
412
|
+
expression: string.slice(start+1, flagStart),
|
413
|
+
flags: string.slice(flagStart+1)
|
414
|
+
}
|
415
|
+
}
|
416
|
+
|
417
|
+
function stringToRegExp(string, flags) {
|
418
|
+
try {
|
419
|
+
return new RegExp(string, flags);
|
420
|
+
} catch (e) { return string; }
|
421
|
+
}
|
422
|
+
|
423
|
+
function objectToRegExp(obj) {
|
424
|
+
return stringToRegExp(obj.expression, obj.flags);
|
425
|
+
}
|
426
|
+
|
427
|
+
;(function() {
|
428
|
+
|
429
|
+
this.activate = function(ed, backwards) {
|
430
|
+
this.$editor = ed;
|
431
|
+
this.$startPos = this.$currentPos = ed.getCursorPosition();
|
432
|
+
this.$options.needle = '';
|
433
|
+
this.$options.backwards = backwards;
|
434
|
+
ed.keyBinding.addKeyboardHandler(this.$keyboardHandler);
|
435
|
+
this.$originalEditorOnPaste = ed.onPaste; ed.onPaste = this.onPaste.bind(this);
|
436
|
+
this.$mousedownHandler = ed.addEventListener('mousedown', this.onMouseDown.bind(this));
|
437
|
+
this.selectionFix(ed);
|
438
|
+
this.statusMessage(true);
|
439
|
+
}
|
440
|
+
|
441
|
+
this.deactivate = function(reset) {
|
442
|
+
this.cancelSearch(reset);
|
443
|
+
var ed = this.$editor;
|
444
|
+
ed.keyBinding.removeKeyboardHandler(this.$keyboardHandler);
|
445
|
+
if (this.$mousedownHandler) {
|
446
|
+
ed.removeEventListener('mousedown', this.$mousedownHandler);
|
447
|
+
delete this.$mousedownHandler;
|
448
|
+
}
|
449
|
+
ed.onPaste = this.$originalEditorOnPaste;
|
450
|
+
this.message('');
|
451
|
+
}
|
452
|
+
|
453
|
+
this.selectionFix = function(editor) {
|
454
|
+
if (editor.selection.isEmpty() && !editor.session.$emacsMark) {
|
455
|
+
editor.clearSelection();
|
456
|
+
}
|
457
|
+
}
|
458
|
+
|
459
|
+
this.highlight = function(regexp) {
|
460
|
+
var sess = this.$editor.session,
|
461
|
+
hl = sess.$isearchHighlight = sess.$isearchHighlight || sess.addDynamicMarker(
|
462
|
+
new SearchHighlight(null, "ace_isearch-result", "text"));
|
463
|
+
hl.setRegexp(regexp);
|
464
|
+
sess._emit("changeBackMarker"); // force highlight layer redraw
|
465
|
+
}
|
466
|
+
|
467
|
+
this.cancelSearch = function(reset) {
|
468
|
+
var e = this.$editor;
|
469
|
+
this.$prevNeedle = this.$options.needle;
|
470
|
+
this.$options.needle = '';
|
471
|
+
if (reset) {
|
472
|
+
e.moveCursorToPosition(this.$startPos);
|
473
|
+
this.$currentPos = this.$startPos;
|
474
|
+
} else {
|
475
|
+
e.pushEmacsMark && e.pushEmacsMark(this.$startPos, false);
|
476
|
+
}
|
477
|
+
this.highlight(null);
|
478
|
+
return Range.fromPoints(this.$currentPos, this.$currentPos);
|
479
|
+
}
|
480
|
+
|
481
|
+
this.highlightAndFindWithNeedle = function(moveToNext, needleUpdateFunc) {
|
482
|
+
if (!this.$editor) return null;
|
483
|
+
var options = this.$options;
|
484
|
+
if (needleUpdateFunc) {
|
485
|
+
options.needle = needleUpdateFunc.call(this, options.needle || '') || '';
|
486
|
+
}
|
487
|
+
if (options.needle.length === 0) {
|
488
|
+
this.statusMessage(true);
|
489
|
+
return this.cancelSearch(true);
|
490
|
+
};
|
491
|
+
options.start = this.$currentPos;
|
492
|
+
var session = this.$editor.session,
|
493
|
+
found = this.find(session),
|
494
|
+
shouldSelect = this.$editor.emacsMark ?
|
495
|
+
!!this.$editor.emacsMark() : !this.$editor.selection.isEmpty();
|
496
|
+
if (found) {
|
497
|
+
if (options.backwards) found = Range.fromPoints(found.end, found.start);
|
498
|
+
this.$editor.selection.setRange(Range.fromPoints(shouldSelect ? this.$startPos : found.end, found.end));
|
499
|
+
if (moveToNext) this.$currentPos = found.end;
|
500
|
+
this.highlight(options.re)
|
501
|
+
}
|
502
|
+
|
503
|
+
this.statusMessage(found);
|
504
|
+
|
505
|
+
return found;
|
506
|
+
}
|
507
|
+
|
508
|
+
this.addString = function(s) {
|
509
|
+
return this.highlightAndFindWithNeedle(false, function(needle) {
|
510
|
+
if (!isRegExp(needle))
|
511
|
+
return needle + s;
|
512
|
+
var reObj = regExpToObject(needle);
|
513
|
+
reObj.expression += s;
|
514
|
+
return objectToRegExp(reObj);
|
515
|
+
});
|
516
|
+
}
|
517
|
+
|
518
|
+
this.removeChar = function(c) {
|
519
|
+
return this.highlightAndFindWithNeedle(false, function(needle) {
|
520
|
+
if (!isRegExp(needle))
|
521
|
+
return needle.substring(0, needle.length-1);
|
522
|
+
var reObj = regExpToObject(needle);
|
523
|
+
reObj.expression = reObj.expression.substring(0, reObj.expression.length-1);
|
524
|
+
return objectToRegExp(reObj);
|
525
|
+
});
|
526
|
+
}
|
527
|
+
|
528
|
+
this.next = function(options) {
|
529
|
+
options = options || {};
|
530
|
+
this.$options.backwards = !!options.backwards;
|
531
|
+
this.$currentPos = this.$editor.getCursorPosition();
|
532
|
+
return this.highlightAndFindWithNeedle(true, function(needle) {
|
533
|
+
return options.useCurrentOrPrevSearch && needle.length === 0 ?
|
534
|
+
this.$prevNeedle || '' : needle;
|
535
|
+
});
|
536
|
+
}
|
537
|
+
|
538
|
+
this.onMouseDown = function(evt) {
|
539
|
+
this.deactivate();
|
540
|
+
return true;
|
541
|
+
}
|
542
|
+
|
543
|
+
this.onPaste = function(text) {
|
544
|
+
this.addString(text);
|
545
|
+
}
|
546
|
+
|
547
|
+
this.convertNeedleToRegExp = function() {
|
548
|
+
return this.highlightAndFindWithNeedle(false, function(needle) {
|
549
|
+
return isRegExp(needle) ? needle : stringToRegExp(needle, 'ig');
|
550
|
+
});
|
551
|
+
}
|
552
|
+
|
553
|
+
this.convertNeedleToString = function() {
|
554
|
+
return this.highlightAndFindWithNeedle(false, function(needle) {
|
555
|
+
return isRegExp(needle) ? regExpToObject(needle).expression : needle;
|
556
|
+
});
|
557
|
+
}
|
558
|
+
|
559
|
+
this.statusMessage = function(found) {
|
560
|
+
var options = this.$options, msg = '';
|
561
|
+
msg += options.backwards ? 'reverse-' : '';
|
562
|
+
msg += 'isearch: ' + options.needle;
|
563
|
+
msg += found ? '' : ' (not found)';
|
564
|
+
this.message(msg);
|
565
|
+
}
|
566
|
+
|
567
|
+
this.message = function(msg) {
|
568
|
+
if (this.$editor.showCommandLine) {
|
569
|
+
this.$editor.showCommandLine(msg);
|
570
|
+
this.$editor.focus();
|
571
|
+
} else {
|
572
|
+
console.log(msg);
|
573
|
+
}
|
574
|
+
}
|
575
|
+
|
576
|
+
}).call(IncrementalSearch.prototype);
|
577
|
+
|
578
|
+
|
579
|
+
exports.IncrementalSearch = IncrementalSearch;
|
580
|
+
|
581
|
+
var dom = require('./lib/dom');
|
582
|
+
dom.importCssString && dom.importCssString("\
|
583
|
+
.ace_marker-layer .ace_isearch-result {\
|
584
|
+
position: absolute;\
|
585
|
+
z-index: 6;\
|
586
|
+
-moz-box-sizing: border-box;\
|
587
|
+
-webkit-box-sizing: border-box;\
|
588
|
+
box-sizing: border-box;\
|
589
|
+
}\
|
590
|
+
div.ace_isearch-result {\
|
591
|
+
border-radius: 4px;\
|
592
|
+
background-color: rgba(255, 200, 0, 0.5);\
|
593
|
+
box-shadow: 0 0 4px rgb(255, 200, 0);\
|
594
|
+
}\
|
595
|
+
.ace_dark div.ace_isearch-result {\
|
596
|
+
background-color: rgb(100, 110, 160);\
|
597
|
+
box-shadow: 0 0 4px rgb(80, 90, 140);\
|
598
|
+
}", "incremental-search-highlighting");
|
599
|
+
var commands = require("./commands/command_manager");
|
600
|
+
(function() {
|
601
|
+
this.setupIncrementalSearch = function(editor, val) {
|
602
|
+
if (this.usesIncrementalSearch == val) return;
|
603
|
+
this.usesIncrementalSearch = val;
|
604
|
+
var iSearchCommands = iSearchCommandModule.iSearchStartCommands;
|
605
|
+
var method = val ? 'addCommands' : 'removeCommands';
|
606
|
+
this[method](iSearchCommands);
|
607
|
+
};
|
608
|
+
}).call(commands.CommandManager.prototype);
|
609
|
+
var Editor = require("./editor").Editor;
|
610
|
+
require("./config").defineOptions(Editor.prototype, "editor", {
|
611
|
+
useIncrementalSearch: {
|
612
|
+
set: function(val) {
|
613
|
+
this.keyBinding.$handlers.forEach(function(handler) {
|
614
|
+
if (handler.setupIncrementalSearch) {
|
615
|
+
handler.setupIncrementalSearch(this, val);
|
616
|
+
}
|
617
|
+
});
|
618
|
+
this._emit('incrementalSearchSettingChanged', {isEnabled: val});
|
619
|
+
}
|
620
|
+
}
|
621
|
+
});
|
622
|
+
|
623
|
+
});
|
624
|
+
|
625
|
+
ace.define("ace/keyboard/emacs",["require","exports","module","ace/lib/dom","ace/incremental_search","ace/commands/incremental_search_commands","ace/keyboard/hash_handler","ace/lib/keys"], function(require, exports, module) {
|
626
|
+
"use strict";
|
627
|
+
|
628
|
+
var dom = require("../lib/dom");
|
629
|
+
require("../incremental_search");
|
630
|
+
var iSearchCommandModule = require("../commands/incremental_search_commands");
|
631
|
+
|
632
|
+
|
633
|
+
var screenToTextBlockCoordinates = function(x, y) {
|
634
|
+
var canvasPos = this.scroller.getBoundingClientRect();
|
635
|
+
|
636
|
+
var col = Math.floor(
|
637
|
+
(x + this.scrollLeft - canvasPos.left - this.$padding) / this.characterWidth
|
638
|
+
);
|
639
|
+
var row = Math.floor(
|
640
|
+
(y + this.scrollTop - canvasPos.top) / this.lineHeight
|
641
|
+
);
|
642
|
+
|
643
|
+
return this.session.screenToDocumentPosition(row, col);
|
644
|
+
};
|
645
|
+
|
646
|
+
var HashHandler = require("./hash_handler").HashHandler;
|
647
|
+
exports.handler = new HashHandler();
|
648
|
+
|
649
|
+
exports.handler.isEmacs = true;
|
650
|
+
exports.handler.$id = "ace/keyboard/emacs";
|
651
|
+
|
652
|
+
var initialized = false;
|
653
|
+
var $formerLongWords;
|
654
|
+
var $formerLineStart;
|
655
|
+
|
656
|
+
exports.handler.attach = function(editor) {
|
657
|
+
if (!initialized) {
|
658
|
+
initialized = true;
|
659
|
+
dom.importCssString('\
|
660
|
+
.emacs-mode .ace_cursor{\
|
661
|
+
border: 1px rgba(50,250,50,0.8) solid!important;\
|
662
|
+
-moz-box-sizing: border-box!important;\
|
663
|
+
-webkit-box-sizing: border-box!important;\
|
664
|
+
box-sizing: border-box!important;\
|
665
|
+
background-color: rgba(0,250,0,0.9);\
|
666
|
+
opacity: 0.5;\
|
667
|
+
}\
|
668
|
+
.emacs-mode .ace_hidden-cursors .ace_cursor{\
|
669
|
+
opacity: 1;\
|
670
|
+
background-color: transparent;\
|
671
|
+
}\
|
672
|
+
.emacs-mode .ace_overwrite-cursors .ace_cursor {\
|
673
|
+
opacity: 1;\
|
674
|
+
background-color: transparent;\
|
675
|
+
border-width: 0 0 2px 2px !important;\
|
676
|
+
}\
|
677
|
+
.emacs-mode .ace_text-layer {\
|
678
|
+
z-index: 4\
|
679
|
+
}\
|
680
|
+
.emacs-mode .ace_cursor-layer {\
|
681
|
+
z-index: 2\
|
682
|
+
}', 'emacsMode'
|
683
|
+
);
|
684
|
+
}
|
685
|
+
$formerLongWords = editor.session.$selectLongWords;
|
686
|
+
editor.session.$selectLongWords = true;
|
687
|
+
$formerLineStart = editor.session.$useEmacsStyleLineStart;
|
688
|
+
editor.session.$useEmacsStyleLineStart = true;
|
689
|
+
|
690
|
+
editor.session.$emacsMark = null; // the active mark
|
691
|
+
editor.session.$emacsMarkRing = editor.session.$emacsMarkRing || [];
|
692
|
+
|
693
|
+
editor.emacsMark = function() {
|
694
|
+
return this.session.$emacsMark;
|
695
|
+
};
|
696
|
+
|
697
|
+
editor.setEmacsMark = function(p) {
|
698
|
+
this.session.$emacsMark = p;
|
699
|
+
};
|
700
|
+
|
701
|
+
editor.pushEmacsMark = function(p, activate) {
|
702
|
+
var prevMark = this.session.$emacsMark;
|
703
|
+
if (prevMark)
|
704
|
+
this.session.$emacsMarkRing.push(prevMark);
|
705
|
+
if (!p || activate) this.setEmacsMark(p);
|
706
|
+
else this.session.$emacsMarkRing.push(p);
|
707
|
+
};
|
708
|
+
|
709
|
+
editor.popEmacsMark = function() {
|
710
|
+
var mark = this.emacsMark();
|
711
|
+
if (mark) { this.setEmacsMark(null); return mark; }
|
712
|
+
return this.session.$emacsMarkRing.pop();
|
713
|
+
};
|
714
|
+
|
715
|
+
editor.getLastEmacsMark = function(p) {
|
716
|
+
return this.session.$emacsMark || this.session.$emacsMarkRing.slice(-1)[0];
|
717
|
+
};
|
718
|
+
|
719
|
+
editor.emacsMarkForSelection = function(replacement) {
|
720
|
+
var sel = this.selection,
|
721
|
+
multiRangeLength = this.multiSelect ?
|
722
|
+
this.multiSelect.getAllRanges().length : 1,
|
723
|
+
selIndex = sel.index || 0,
|
724
|
+
markRing = this.session.$emacsMarkRing,
|
725
|
+
markIndex = markRing.length - (multiRangeLength - selIndex),
|
726
|
+
lastMark = markRing[markIndex] || sel.anchor;
|
727
|
+
if (replacement) {
|
728
|
+
markRing.splice(markIndex, 1,
|
729
|
+
"row" in replacement && "column" in replacement ?
|
730
|
+
replacement : undefined);
|
731
|
+
}
|
732
|
+
return lastMark;
|
733
|
+
}
|
734
|
+
|
735
|
+
editor.on("click", $resetMarkMode);
|
736
|
+
editor.on("changeSession", $kbSessionChange);
|
737
|
+
editor.renderer.screenToTextCoordinates = screenToTextBlockCoordinates;
|
738
|
+
editor.setStyle("emacs-mode");
|
739
|
+
editor.commands.addCommands(commands);
|
740
|
+
exports.handler.platform = editor.commands.platform;
|
741
|
+
editor.$emacsModeHandler = this;
|
742
|
+
editor.addEventListener('copy', this.onCopy);
|
743
|
+
editor.addEventListener('paste', this.onPaste);
|
744
|
+
};
|
745
|
+
|
746
|
+
exports.handler.detach = function(editor) {
|
747
|
+
delete editor.renderer.screenToTextCoordinates;
|
748
|
+
editor.session.$selectLongWords = $formerLongWords;
|
749
|
+
editor.session.$useEmacsStyleLineStart = $formerLineStart;
|
750
|
+
editor.removeEventListener("click", $resetMarkMode);
|
751
|
+
editor.removeEventListener("changeSession", $kbSessionChange);
|
752
|
+
editor.unsetStyle("emacs-mode");
|
753
|
+
editor.commands.removeCommands(commands);
|
754
|
+
editor.removeEventListener('copy', this.onCopy);
|
755
|
+
editor.removeEventListener('paste', this.onPaste);
|
756
|
+
editor.$emacsModeHandler = null;
|
757
|
+
};
|
758
|
+
|
759
|
+
var $kbSessionChange = function(e) {
|
760
|
+
if (e.oldSession) {
|
761
|
+
e.oldSession.$selectLongWords = $formerLongWords;
|
762
|
+
e.oldSession.$useEmacsStyleLineStart = $formerLineStart;
|
763
|
+
}
|
764
|
+
|
765
|
+
$formerLongWords = e.session.$selectLongWords;
|
766
|
+
e.session.$selectLongWords = true;
|
767
|
+
$formerLineStart = e.session.$useEmacsStyleLineStart;
|
768
|
+
e.session.$useEmacsStyleLineStart = true;
|
769
|
+
|
770
|
+
if (!e.session.hasOwnProperty('$emacsMark'))
|
771
|
+
e.session.$emacsMark = null;
|
772
|
+
if (!e.session.hasOwnProperty('$emacsMarkRing'))
|
773
|
+
e.session.$emacsMarkRing = [];
|
774
|
+
};
|
775
|
+
|
776
|
+
var $resetMarkMode = function(e) {
|
777
|
+
e.editor.session.$emacsMark = null;
|
778
|
+
};
|
779
|
+
|
780
|
+
var keys = require("../lib/keys").KEY_MODS;
|
781
|
+
var eMods = {C: "ctrl", S: "shift", M: "alt", CMD: "command"};
|
782
|
+
var combinations = ["C-S-M-CMD",
|
783
|
+
"S-M-CMD", "C-M-CMD", "C-S-CMD", "C-S-M",
|
784
|
+
"M-CMD", "S-CMD", "S-M", "C-CMD", "C-M", "C-S",
|
785
|
+
"CMD", "M", "S", "C"];
|
786
|
+
combinations.forEach(function(c) {
|
787
|
+
var hashId = 0;
|
788
|
+
c.split("-").forEach(function(c) {
|
789
|
+
hashId = hashId | keys[eMods[c]];
|
790
|
+
});
|
791
|
+
eMods[hashId] = c.toLowerCase() + "-";
|
792
|
+
});
|
793
|
+
|
794
|
+
exports.handler.onCopy = function(e, editor) {
|
795
|
+
if (editor.$handlesEmacsOnCopy) return;
|
796
|
+
editor.$handlesEmacsOnCopy = true;
|
797
|
+
exports.handler.commands.killRingSave.exec(editor);
|
798
|
+
editor.$handlesEmacsOnCopy = false;
|
799
|
+
};
|
800
|
+
|
801
|
+
exports.handler.onPaste = function(e, editor) {
|
802
|
+
editor.pushEmacsMark(editor.getCursorPosition());
|
803
|
+
};
|
804
|
+
|
805
|
+
exports.handler.bindKey = function(key, command) {
|
806
|
+
if (typeof key == "object")
|
807
|
+
key = key[this.platform];
|
808
|
+
if (!key)
|
809
|
+
return;
|
810
|
+
|
811
|
+
var ckb = this.commandKeyBinding;
|
812
|
+
key.split("|").forEach(function(keyPart) {
|
813
|
+
keyPart = keyPart.toLowerCase();
|
814
|
+
ckb[keyPart] = command;
|
815
|
+
var keyParts = keyPart.split(" ").slice(0,-1);
|
816
|
+
keyParts.reduce(function(keyMapKeys, keyPart, i) {
|
817
|
+
var prefix = keyMapKeys[i-1] ? keyMapKeys[i-1] + ' ' : '';
|
818
|
+
return keyMapKeys.concat([prefix + keyPart]);
|
819
|
+
}, []).forEach(function(keyPart) {
|
820
|
+
if (!ckb[keyPart]) ckb[keyPart] = "null";
|
821
|
+
});
|
822
|
+
}, this);
|
823
|
+
};
|
824
|
+
|
825
|
+
exports.handler.getStatusText = function(editor, data) {
|
826
|
+
var str = "";
|
827
|
+
if (data.count)
|
828
|
+
str += data.count;
|
829
|
+
if (data.keyChain)
|
830
|
+
str += " " + data.keyChain
|
831
|
+
return str;
|
832
|
+
};
|
833
|
+
|
834
|
+
exports.handler.handleKeyboard = function(data, hashId, key, keyCode) {
|
835
|
+
if (keyCode === -1) return undefined;
|
836
|
+
|
837
|
+
var editor = data.editor;
|
838
|
+
editor._signal("changeStatus");
|
839
|
+
if (hashId == -1) {
|
840
|
+
editor.pushEmacsMark();
|
841
|
+
if (data.count) {
|
842
|
+
var str = new Array(data.count + 1).join(key);
|
843
|
+
data.count = null;
|
844
|
+
return {command: "insertstring", args: str};
|
845
|
+
}
|
846
|
+
}
|
847
|
+
|
848
|
+
var modifier = eMods[hashId];
|
849
|
+
if (modifier == "c-" || data.count) {
|
850
|
+
var count = parseInt(key[key.length - 1]);
|
851
|
+
if (typeof count === 'number' && !isNaN(count)) {
|
852
|
+
data.count = Math.max(data.count, 0) || 0;
|
853
|
+
data.count = 10 * data.count + count;
|
854
|
+
return {command: "null"};
|
855
|
+
}
|
856
|
+
}
|
857
|
+
if (modifier) key = modifier + key;
|
858
|
+
if (data.keyChain) key = data.keyChain += " " + key;
|
859
|
+
var command = this.commandKeyBinding[key];
|
860
|
+
data.keyChain = command == "null" ? key : "";
|
861
|
+
if (!command) return undefined;
|
862
|
+
if (command === "null") return {command: "null"};
|
863
|
+
|
864
|
+
if (command === "universalArgument") {
|
865
|
+
data.count = -4;
|
866
|
+
return {command: "null"};
|
867
|
+
}
|
868
|
+
var args;
|
869
|
+
if (typeof command !== "string") {
|
870
|
+
args = command.args;
|
871
|
+
if (command.command) command = command.command;
|
872
|
+
if (command === "goorselect") {
|
873
|
+
command = editor.emacsMark() ? args[1] : args[0];
|
874
|
+
args = null;
|
875
|
+
}
|
876
|
+
}
|
877
|
+
|
878
|
+
if (typeof command === "string") {
|
879
|
+
if (command === "insertstring" ||
|
880
|
+
command === "splitline" ||
|
881
|
+
command === "togglecomment") {
|
882
|
+
editor.pushEmacsMark();
|
883
|
+
}
|
884
|
+
command = this.commands[command] || editor.commands.commands[command];
|
885
|
+
if (!command) return undefined;
|
886
|
+
}
|
887
|
+
|
888
|
+
if (!command.readOnly && !command.isYank)
|
889
|
+
data.lastCommand = null;
|
890
|
+
|
891
|
+
if (!command.readOnly && editor.emacsMark())
|
892
|
+
editor.setEmacsMark(null)
|
893
|
+
|
894
|
+
if (data.count) {
|
895
|
+
var count = data.count;
|
896
|
+
data.count = 0;
|
897
|
+
if (!command || !command.handlesCount) {
|
898
|
+
return {
|
899
|
+
args: args,
|
900
|
+
command: {
|
901
|
+
exec: function(editor, args) {
|
902
|
+
for (var i = 0; i < count; i++)
|
903
|
+
command.exec(editor, args);
|
904
|
+
},
|
905
|
+
multiSelectAction: command.multiSelectAction
|
906
|
+
}
|
907
|
+
};
|
908
|
+
} else {
|
909
|
+
if (!args) args = {};
|
910
|
+
if (typeof args === 'object') args.count = count;
|
911
|
+
}
|
912
|
+
}
|
913
|
+
|
914
|
+
return {command: command, args: args};
|
915
|
+
};
|
916
|
+
|
917
|
+
exports.emacsKeys = {
|
918
|
+
"Up|C-p" : {command: "goorselect", args: ["golineup","selectup"]},
|
919
|
+
"Down|C-n" : {command: "goorselect", args: ["golinedown","selectdown"]},
|
920
|
+
"Left|C-b" : {command: "goorselect", args: ["gotoleft","selectleft"]},
|
921
|
+
"Right|C-f" : {command: "goorselect", args: ["gotoright","selectright"]},
|
922
|
+
"C-Left|M-b" : {command: "goorselect", args: ["gotowordleft","selectwordleft"]},
|
923
|
+
"C-Right|M-f" : {command: "goorselect", args: ["gotowordright","selectwordright"]},
|
924
|
+
"Home|C-a" : {command: "goorselect", args: ["gotolinestart","selecttolinestart"]},
|
925
|
+
"End|C-e" : {command: "goorselect", args: ["gotolineend","selecttolineend"]},
|
926
|
+
"C-Home|S-M-,": {command: "goorselect", args: ["gotostart","selecttostart"]},
|
927
|
+
"C-End|S-M-." : {command: "goorselect", args: ["gotoend","selecttoend"]},
|
928
|
+
"S-Up|S-C-p" : "selectup",
|
929
|
+
"S-Down|S-C-n" : "selectdown",
|
930
|
+
"S-Left|S-C-b" : "selectleft",
|
931
|
+
"S-Right|S-C-f" : "selectright",
|
932
|
+
"S-C-Left|S-M-b" : "selectwordleft",
|
933
|
+
"S-C-Right|S-M-f" : "selectwordright",
|
934
|
+
"S-Home|S-C-a" : "selecttolinestart",
|
935
|
+
"S-End|S-C-e" : "selecttolineend",
|
936
|
+
"S-C-Home" : "selecttostart",
|
937
|
+
"S-C-End" : "selecttoend",
|
938
|
+
|
939
|
+
"C-l" : "recenterTopBottom",
|
940
|
+
"M-s" : "centerselection",
|
941
|
+
"M-g": "gotoline",
|
942
|
+
"C-x C-p": "selectall",
|
943
|
+
"C-Down": {command: "goorselect", args: ["gotopagedown","selectpagedown"]},
|
944
|
+
"C-Up": {command: "goorselect", args: ["gotopageup","selectpageup"]},
|
945
|
+
"PageDown|C-v": {command: "goorselect", args: ["gotopagedown","selectpagedown"]},
|
946
|
+
"PageUp|M-v": {command: "goorselect", args: ["gotopageup","selectpageup"]},
|
947
|
+
"S-C-Down": "selectpagedown",
|
948
|
+
"S-C-Up": "selectpageup",
|
949
|
+
|
950
|
+
"C-s": "iSearch",
|
951
|
+
"C-r": "iSearchBackwards",
|
952
|
+
|
953
|
+
"M-C-s": "findnext",
|
954
|
+
"M-C-r": "findprevious",
|
955
|
+
"S-M-5": "replace",
|
956
|
+
"Backspace": "backspace",
|
957
|
+
"Delete|C-d": "del",
|
958
|
+
"Return|C-m": {command: "insertstring", args: "\n"}, // "newline"
|
959
|
+
"C-o": "splitline",
|
960
|
+
|
961
|
+
"M-d|C-Delete": {command: "killWord", args: "right"},
|
962
|
+
"C-Backspace|M-Backspace|M-Delete": {command: "killWord", args: "left"},
|
963
|
+
"C-k": "killLine",
|
964
|
+
|
965
|
+
"C-y|S-Delete": "yank",
|
966
|
+
"M-y": "yankRotate",
|
967
|
+
"C-g": "keyboardQuit",
|
968
|
+
|
969
|
+
"C-w|C-S-W": "killRegion",
|
970
|
+
"M-w": "killRingSave",
|
971
|
+
"C-Space": "setMark",
|
972
|
+
"C-x C-x": "exchangePointAndMark",
|
973
|
+
|
974
|
+
"C-t": "transposeletters",
|
975
|
+
"M-u": "touppercase", // Doesn't work
|
976
|
+
"M-l": "tolowercase",
|
977
|
+
"M-/": "autocomplete", // Doesn't work
|
978
|
+
"C-u": "universalArgument",
|
979
|
+
|
980
|
+
"M-;": "togglecomment",
|
981
|
+
|
982
|
+
"C-/|C-x u|S-C--|C-z": "undo",
|
983
|
+
"S-C-/|S-C-x u|C--|S-C-z": "redo", //infinite undo?
|
984
|
+
"C-x r": "selectRectangularRegion",
|
985
|
+
"M-x": {command: "focusCommandLine", args: "M-x "}
|
986
|
+
};
|
987
|
+
|
988
|
+
|
989
|
+
exports.handler.bindKeys(exports.emacsKeys);
|
990
|
+
|
991
|
+
exports.handler.addCommands({
|
992
|
+
recenterTopBottom: function(editor) {
|
993
|
+
var renderer = editor.renderer;
|
994
|
+
var pos = renderer.$cursorLayer.getPixelPosition();
|
995
|
+
var h = renderer.$size.scrollerHeight - renderer.lineHeight;
|
996
|
+
var scrollTop = renderer.scrollTop;
|
997
|
+
if (Math.abs(pos.top - scrollTop) < 2) {
|
998
|
+
scrollTop = pos.top - h;
|
999
|
+
} else if (Math.abs(pos.top - scrollTop - h * 0.5) < 2) {
|
1000
|
+
scrollTop = pos.top;
|
1001
|
+
} else {
|
1002
|
+
scrollTop = pos.top - h * 0.5;
|
1003
|
+
}
|
1004
|
+
editor.session.setScrollTop(scrollTop);
|
1005
|
+
},
|
1006
|
+
selectRectangularRegion: function(editor) {
|
1007
|
+
editor.multiSelect.toggleBlockSelection();
|
1008
|
+
},
|
1009
|
+
setMark: {
|
1010
|
+
exec: function(editor, args) {
|
1011
|
+
|
1012
|
+
if (args && args.count) {
|
1013
|
+
if (editor.inMultiSelectMode) editor.forEachSelection(moveToMark);
|
1014
|
+
else moveToMark();
|
1015
|
+
moveToMark();
|
1016
|
+
return;
|
1017
|
+
}
|
1018
|
+
|
1019
|
+
var mark = editor.emacsMark(),
|
1020
|
+
ranges = editor.selection.getAllRanges(),
|
1021
|
+
rangePositions = ranges.map(function(r) { return {row: r.start.row, column: r.start.column}; }),
|
1022
|
+
transientMarkModeActive = true,
|
1023
|
+
hasNoSelection = ranges.every(function(range) { return range.isEmpty(); });
|
1024
|
+
if (transientMarkModeActive && (mark || !hasNoSelection)) {
|
1025
|
+
if (editor.inMultiSelectMode) editor.forEachSelection({exec: editor.clearSelection.bind(editor)})
|
1026
|
+
else editor.clearSelection();
|
1027
|
+
if (mark) editor.pushEmacsMark(null);
|
1028
|
+
return;
|
1029
|
+
}
|
1030
|
+
|
1031
|
+
if (!mark) {
|
1032
|
+
rangePositions.forEach(function(pos) { editor.pushEmacsMark(pos); });
|
1033
|
+
editor.setEmacsMark(rangePositions[rangePositions.length-1]);
|
1034
|
+
return;
|
1035
|
+
}
|
1036
|
+
|
1037
|
+
function moveToMark() {
|
1038
|
+
var mark = editor.popEmacsMark();
|
1039
|
+
mark && editor.moveCursorToPosition(mark);
|
1040
|
+
}
|
1041
|
+
|
1042
|
+
},
|
1043
|
+
readOnly: true,
|
1044
|
+
handlesCount: true
|
1045
|
+
},
|
1046
|
+
exchangePointAndMark: {
|
1047
|
+
exec: function exchangePointAndMark$exec(editor, args) {
|
1048
|
+
var sel = editor.selection;
|
1049
|
+
if (!args.count && !sel.isEmpty()) { // just invert selection
|
1050
|
+
sel.setSelectionRange(sel.getRange(), !sel.isBackwards());
|
1051
|
+
return;
|
1052
|
+
}
|
1053
|
+
|
1054
|
+
if (args.count) { // replace mark and point
|
1055
|
+
var pos = {row: sel.lead.row, column: sel.lead.column};
|
1056
|
+
sel.clearSelection();
|
1057
|
+
sel.moveCursorToPosition(editor.emacsMarkForSelection(pos));
|
1058
|
+
} else { // create selection to last mark
|
1059
|
+
sel.selectToPosition(editor.emacsMarkForSelection());
|
1060
|
+
}
|
1061
|
+
},
|
1062
|
+
readOnly: true,
|
1063
|
+
handlesCount: true,
|
1064
|
+
multiSelectAction: "forEach"
|
1065
|
+
},
|
1066
|
+
killWord: {
|
1067
|
+
exec: function(editor, dir) {
|
1068
|
+
editor.clearSelection();
|
1069
|
+
if (dir == "left")
|
1070
|
+
editor.selection.selectWordLeft();
|
1071
|
+
else
|
1072
|
+
editor.selection.selectWordRight();
|
1073
|
+
|
1074
|
+
var range = editor.getSelectionRange();
|
1075
|
+
var text = editor.session.getTextRange(range);
|
1076
|
+
exports.killRing.add(text);
|
1077
|
+
|
1078
|
+
editor.session.remove(range);
|
1079
|
+
editor.clearSelection();
|
1080
|
+
},
|
1081
|
+
multiSelectAction: "forEach"
|
1082
|
+
},
|
1083
|
+
killLine: function(editor) {
|
1084
|
+
editor.pushEmacsMark(null);
|
1085
|
+
var pos = editor.getCursorPosition();
|
1086
|
+
if (pos.column === 0 &&
|
1087
|
+
editor.session.doc.getLine(pos.row).length === 0) {
|
1088
|
+
editor.selection.selectLine();
|
1089
|
+
} else {
|
1090
|
+
editor.clearSelection();
|
1091
|
+
editor.selection.selectLineEnd();
|
1092
|
+
}
|
1093
|
+
var range = editor.getSelectionRange();
|
1094
|
+
var text = editor.session.getTextRange(range);
|
1095
|
+
exports.killRing.add(text);
|
1096
|
+
|
1097
|
+
editor.session.remove(range);
|
1098
|
+
editor.clearSelection();
|
1099
|
+
},
|
1100
|
+
yank: function(editor) {
|
1101
|
+
editor.onPaste(exports.killRing.get() || '');
|
1102
|
+
editor.keyBinding.$data.lastCommand = "yank";
|
1103
|
+
},
|
1104
|
+
yankRotate: function(editor) {
|
1105
|
+
if (editor.keyBinding.$data.lastCommand != "yank")
|
1106
|
+
return;
|
1107
|
+
editor.undo();
|
1108
|
+
editor.session.$emacsMarkRing.pop(); // also undo recording mark
|
1109
|
+
editor.onPaste(exports.killRing.rotate());
|
1110
|
+
editor.keyBinding.$data.lastCommand = "yank";
|
1111
|
+
},
|
1112
|
+
killRegion: {
|
1113
|
+
exec: function(editor) {
|
1114
|
+
exports.killRing.add(editor.getCopyText());
|
1115
|
+
editor.commands.byName.cut.exec(editor);
|
1116
|
+
},
|
1117
|
+
readOnly: true,
|
1118
|
+
multiSelectAction: "forEach"
|
1119
|
+
},
|
1120
|
+
killRingSave: {
|
1121
|
+
exec: function(editor) {
|
1122
|
+
|
1123
|
+
editor.$handlesEmacsOnCopy = true;
|
1124
|
+
var marks = editor.session.$emacsMarkRing.slice(),
|
1125
|
+
deselectedMarks = [];
|
1126
|
+
exports.killRing.add(editor.getCopyText());
|
1127
|
+
|
1128
|
+
setTimeout(function() {
|
1129
|
+
function deselect() {
|
1130
|
+
var sel = editor.selection, range = sel.getRange(),
|
1131
|
+
pos = sel.isBackwards() ? range.end : range.start;
|
1132
|
+
deselectedMarks.push({row: pos.row, column: pos.column});
|
1133
|
+
sel.clearSelection();
|
1134
|
+
}
|
1135
|
+
editor.$handlesEmacsOnCopy = false;
|
1136
|
+
if (editor.inMultiSelectMode) editor.forEachSelection({exec: deselect});
|
1137
|
+
else deselect();
|
1138
|
+
editor.session.$emacsMarkRing = marks.concat(deselectedMarks.reverse());
|
1139
|
+
}, 0);
|
1140
|
+
},
|
1141
|
+
readOnly: true
|
1142
|
+
},
|
1143
|
+
keyboardQuit: function(editor) {
|
1144
|
+
editor.selection.clearSelection();
|
1145
|
+
editor.setEmacsMark(null);
|
1146
|
+
editor.keyBinding.$data.count = null;
|
1147
|
+
},
|
1148
|
+
focusCommandLine: function(editor, arg) {
|
1149
|
+
if (editor.showCommandLine)
|
1150
|
+
editor.showCommandLine(arg);
|
1151
|
+
}
|
1152
|
+
});
|
1153
|
+
|
1154
|
+
exports.handler.addCommands(iSearchCommandModule.iSearchStartCommands);
|
1155
|
+
|
1156
|
+
var commands = exports.handler.commands;
|
1157
|
+
commands.yank.isYank = true;
|
1158
|
+
commands.yankRotate.isYank = true;
|
1159
|
+
|
1160
|
+
exports.killRing = {
|
1161
|
+
$data: [],
|
1162
|
+
add: function(str) {
|
1163
|
+
str && this.$data.push(str);
|
1164
|
+
if (this.$data.length > 30)
|
1165
|
+
this.$data.shift();
|
1166
|
+
},
|
1167
|
+
get: function(n) {
|
1168
|
+
n = n || 1;
|
1169
|
+
return this.$data.slice(this.$data.length-n, this.$data.length).reverse().join('\n');
|
1170
|
+
},
|
1171
|
+
pop: function() {
|
1172
|
+
if (this.$data.length > 1)
|
1173
|
+
this.$data.pop();
|
1174
|
+
return this.get();
|
1175
|
+
},
|
1176
|
+
rotate: function() {
|
1177
|
+
this.$data.unshift(this.$data.pop());
|
1178
|
+
return this.get();
|
1179
|
+
}
|
1180
|
+
};
|
1181
|
+
|
1182
|
+
});
|