codemirror-rails 3.24 → 4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/codemirror/rails/version.rb +2 -2
- data/vendor/assets/javascripts/codemirror.js +3001 -1798
- data/vendor/assets/javascripts/codemirror/addons/comment/comment.js +24 -4
- data/vendor/assets/javascripts/codemirror/addons/comment/continuecomment.js +47 -32
- data/vendor/assets/javascripts/codemirror/addons/dialog/dialog.js +9 -2
- data/vendor/assets/javascripts/codemirror/addons/display/fullscreen.js +9 -2
- data/vendor/assets/javascripts/codemirror/addons/display/placeholder.js +9 -2
- data/vendor/assets/javascripts/codemirror/addons/display/rulers.js +9 -2
- data/vendor/assets/javascripts/codemirror/addons/edit/closebrackets.js +76 -37
- data/vendor/assets/javascripts/codemirror/addons/edit/closetag.js +59 -37
- data/vendor/assets/javascripts/codemirror/addons/edit/continuelist.js +25 -17
- data/vendor/assets/javascripts/codemirror/addons/edit/matchbrackets.js +67 -46
- data/vendor/assets/javascripts/codemirror/addons/edit/matchtags.js +10 -3
- data/vendor/assets/javascripts/codemirror/addons/edit/trailingspace.js +23 -14
- data/vendor/assets/javascripts/codemirror/addons/fold/brace-fold.js +12 -3
- data/vendor/assets/javascripts/codemirror/addons/fold/comment-fold.js +12 -0
- data/vendor/assets/javascripts/codemirror/addons/fold/foldcode.js +28 -3
- data/vendor/assets/javascripts/codemirror/addons/fold/foldgutter.js +9 -2
- data/vendor/assets/javascripts/codemirror/addons/fold/indent-fold.js +12 -1
- data/vendor/assets/javascripts/codemirror/addons/fold/markdown-fold.js +12 -0
- data/vendor/assets/javascripts/codemirror/addons/fold/xml-fold.js +9 -4
- data/vendor/assets/javascripts/codemirror/addons/hint/anyword-hint.js +9 -2
- data/vendor/assets/javascripts/codemirror/addons/hint/css-hint.js +10 -3
- data/vendor/assets/javascripts/codemirror/addons/hint/html-hint.js +11 -3
- data/vendor/assets/javascripts/codemirror/addons/hint/javascript-hint.js +9 -4
- data/vendor/assets/javascripts/codemirror/addons/hint/python-hint.js +11 -3
- data/vendor/assets/javascripts/codemirror/addons/hint/show-hint.js +10 -4
- data/vendor/assets/javascripts/codemirror/addons/hint/sql-hint.js +9 -2
- data/vendor/assets/javascripts/codemirror/addons/hint/xml-hint.js +22 -34
- data/vendor/assets/javascripts/codemirror/addons/lint/coffeescript-lint.js +12 -1
- data/vendor/assets/javascripts/codemirror/addons/lint/css-lint.js +12 -1
- data/vendor/assets/javascripts/codemirror/addons/lint/javascript-lint.js +9 -4
- data/vendor/assets/javascripts/codemirror/addons/lint/json-lint.js +12 -1
- data/vendor/assets/javascripts/codemirror/addons/lint/lint.js +12 -8
- data/vendor/assets/javascripts/codemirror/addons/lint/yaml-lint.js +12 -1
- data/vendor/assets/javascripts/codemirror/addons/merge/merge.js +18 -16
- data/vendor/assets/javascripts/codemirror/addons/mode/loadmode.js +9 -2
- data/vendor/assets/javascripts/codemirror/addons/mode/multiplex.js +12 -0
- data/vendor/assets/javascripts/codemirror/addons/mode/overlay.js +15 -10
- data/vendor/assets/javascripts/codemirror/addons/runmode/colorize.js +11 -3
- data/vendor/assets/javascripts/codemirror/addons/runmode/runmode-standalone.js +0 -2
- data/vendor/assets/javascripts/codemirror/addons/runmode/runmode.js +12 -0
- data/vendor/assets/javascripts/codemirror/addons/runmode/runmode.node.js +4 -0
- data/vendor/assets/javascripts/codemirror/addons/scroll/scrollpastend.js +9 -2
- data/vendor/assets/javascripts/codemirror/addons/search/match-highlighter.js +12 -3
- data/vendor/assets/javascripts/codemirror/addons/search/search.js +24 -16
- data/vendor/assets/javascripts/codemirror/addons/search/searchcursor.js +21 -2
- data/vendor/assets/javascripts/codemirror/addons/selection/active-line.js +38 -17
- data/vendor/assets/javascripts/codemirror/addons/selection/mark-selection.js +16 -9
- data/vendor/assets/javascripts/codemirror/addons/tern/tern.js +33 -5
- data/vendor/assets/javascripts/codemirror/addons/wrap/hardwrap.js +27 -2
- data/vendor/assets/javascripts/codemirror/keymaps/emacs.js +12 -5
- data/vendor/assets/javascripts/codemirror/keymaps/sublime.js +505 -0
- data/vendor/assets/javascripts/codemirror/keymaps/vim.js +138 -179
- data/vendor/assets/javascripts/codemirror/modes/apl.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/asterisk.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/clike.js +15 -4
- data/vendor/assets/javascripts/codemirror/modes/clojure.js +13 -0
- data/vendor/assets/javascripts/codemirror/modes/cobol.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/coffeescript.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/commonlisp.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/css.js +18 -27
- data/vendor/assets/javascripts/codemirror/modes/d.js +12 -2
- data/vendor/assets/javascripts/codemirror/modes/diff.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/dtd.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/ecl.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/eiffel.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/erlang.js +13 -1
- data/vendor/assets/javascripts/codemirror/modes/fortran.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/gas.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/gfm.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/gherkin.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/go.js +12 -1
- data/vendor/assets/javascripts/codemirror/modes/groovy.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/haml.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/haskell.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/haxe.js +18 -9
- data/vendor/assets/javascripts/codemirror/modes/htmlembedded.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/htmlmixed.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/http.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/jade.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/javascript.js +23 -16
- data/vendor/assets/javascripts/codemirror/modes/jinja2.js +53 -118
- data/vendor/assets/javascripts/codemirror/modes/julia.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/livescript.js +17 -4
- data/vendor/assets/javascripts/codemirror/modes/lua.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/markdown.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/mirc.js +13 -0
- data/vendor/assets/javascripts/codemirror/modes/mllike.js +12 -1
- data/vendor/assets/javascripts/codemirror/modes/nginx.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/ntriples.js +13 -0
- data/vendor/assets/javascripts/codemirror/modes/octave.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/pascal.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/pegjs.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/perl.js +84 -73
- data/vendor/assets/javascripts/codemirror/modes/php.js +20 -101
- data/vendor/assets/javascripts/codemirror/modes/pig.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/properties.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/puppet.js +13 -0
- data/vendor/assets/javascripts/codemirror/modes/python.js +21 -11
- data/vendor/assets/javascripts/codemirror/modes/q.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/r.js +13 -3
- data/vendor/assets/javascripts/codemirror/modes/{rpm-spec.js → rpm.js} +34 -2
- data/vendor/assets/javascripts/codemirror/modes/rst.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/ruby.js +11 -0
- data/vendor/assets/javascripts/codemirror/modes/rust.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/sass.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/scheme.js +13 -0
- data/vendor/assets/javascripts/codemirror/modes/shell.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/sieve.js +11 -4
- data/vendor/assets/javascripts/codemirror/modes/smalltalk.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/smarty.js +13 -0
- data/vendor/assets/javascripts/codemirror/modes/smartymixed.js +14 -2
- data/vendor/assets/javascripts/codemirror/modes/solr.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/sparql.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/sql.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/stex.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/tcl.js +13 -0
- data/vendor/assets/javascripts/codemirror/modes/tiddlywiki.js +13 -0
- data/vendor/assets/javascripts/codemirror/modes/tiki.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/toml.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/turtle.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/vb.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/vbscript.js +13 -0
- data/vendor/assets/javascripts/codemirror/modes/velocity.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/verilog.js +89 -236
- data/vendor/assets/javascripts/codemirror/modes/xml.js +41 -60
- data/vendor/assets/javascripts/codemirror/modes/xquery.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/yaml.js +12 -0
- data/vendor/assets/javascripts/codemirror/modes/z80.js +12 -0
- data/vendor/assets/stylesheets/codemirror.css +15 -10
- data/vendor/assets/stylesheets/codemirror/themes/ambiance.css +1 -0
- data/vendor/assets/stylesheets/codemirror/themes/lesser-dark.css +4 -0
- data/vendor/assets/stylesheets/codemirror/themes/mdn-like.css +1 -1
- data/vendor/assets/stylesheets/codemirror/themes/pastel-on-dark.css +1 -0
- data/vendor/assets/stylesheets/codemirror/themes/rubyblue.css +2 -0
- data/vendor/assets/stylesheets/codemirror/themes/solarized.css +17 -3
- metadata +20 -25
- data/vendor/assets/javascripts/codemirror/keymaps/extra.js +0 -43
- data/vendor/assets/javascripts/codemirror/modes/django.js +0 -55
- data/vendor/assets/javascripts/codemirror/modes/dylan.js +0 -284
- data/vendor/assets/javascripts/codemirror/modes/less.js +0 -347
- data/vendor/assets/javascripts/codemirror/modes/rpm-changes.js +0 -19
- data/vendor/assets/stylesheets/codemirror/modes/rpm-spec.css +0 -5
@@ -4,7 +4,14 @@
|
|
4
4
|
// selected text the CSS class given as option value, or
|
5
5
|
// "CodeMirror-selectedtext" when the value is not a string.
|
6
6
|
|
7
|
-
(function() {
|
7
|
+
(function(mod) {
|
8
|
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
9
|
+
mod(require("../../lib/codemirror"));
|
10
|
+
else if (typeof define == "function" && define.amd) // AMD
|
11
|
+
define(["../../lib/codemirror"], mod);
|
12
|
+
else // Plain browser env
|
13
|
+
mod(CodeMirror);
|
14
|
+
})(function(CodeMirror) {
|
8
15
|
"use strict";
|
9
16
|
|
10
17
|
CodeMirror.defineOption("styleSelectedText", false, function(cm, val, old) {
|
@@ -34,10 +41,7 @@
|
|
34
41
|
|
35
42
|
var CHUNK_SIZE = 8;
|
36
43
|
var Pos = CodeMirror.Pos;
|
37
|
-
|
38
|
-
function cmp(pos1, pos2) {
|
39
|
-
return pos1.line - pos2.line || pos1.ch - pos2.ch;
|
40
|
-
}
|
44
|
+
var cmp = CodeMirror.cmpPos;
|
41
45
|
|
42
46
|
function coverRange(cm, from, to, addAt) {
|
43
47
|
if (cmp(from, to) == 0) return;
|
@@ -63,13 +67,16 @@
|
|
63
67
|
|
64
68
|
function reset(cm) {
|
65
69
|
clear(cm);
|
66
|
-
var
|
67
|
-
|
70
|
+
var ranges = cm.listSelections();
|
71
|
+
for (var i = 0; i < ranges.length; i++)
|
72
|
+
coverRange(cm, ranges[i].from(), ranges[i].to());
|
68
73
|
}
|
69
74
|
|
70
75
|
function update(cm) {
|
76
|
+
if (!cm.somethingSelected()) return clear(cm);
|
77
|
+
if (cm.listSelections().length > 1) return reset(cm);
|
78
|
+
|
71
79
|
var from = cm.getCursor("start"), to = cm.getCursor("end");
|
72
|
-
if (cmp(from, to) == 0) return clear(cm);
|
73
80
|
|
74
81
|
var array = cm.state.markedSelection;
|
75
82
|
if (!array.length) return coverRange(cm, from, to);
|
@@ -105,4 +112,4 @@
|
|
105
112
|
}
|
106
113
|
}
|
107
114
|
}
|
108
|
-
})
|
115
|
+
});
|
@@ -40,7 +40,14 @@
|
|
40
40
|
// load. Or, if you minified those into a single script and included
|
41
41
|
// them in the workerScript, simply leave this undefined.
|
42
42
|
|
43
|
-
(function() {
|
43
|
+
(function(mod) {
|
44
|
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
45
|
+
mod(require("../../lib/codemirror"));
|
46
|
+
else if (typeof define == "function" && define.amd) // AMD
|
47
|
+
define(["../../lib/codemirror"], mod);
|
48
|
+
else // Plain browser env
|
49
|
+
mod(CodeMirror);
|
50
|
+
})(function(CodeMirror) {
|
44
51
|
"use strict";
|
45
52
|
// declare global: tern
|
46
53
|
|
@@ -106,6 +113,8 @@
|
|
106
113
|
|
107
114
|
rename: function(cm) { rename(this, cm); },
|
108
115
|
|
116
|
+
selectName: function(cm) { selectName(this, cm); },
|
117
|
+
|
109
118
|
request: function (cm, query, c, pos) {
|
110
119
|
var self = this;
|
111
120
|
var doc = findDoc(this, cm.getDoc());
|
@@ -167,7 +176,7 @@
|
|
167
176
|
|
168
177
|
function sendDoc(ts, doc) {
|
169
178
|
ts.server.request({files: [{type: "full", name: doc.name, text: docValue(ts, doc)}]}, function(error) {
|
170
|
-
if (error) console.error(error);
|
179
|
+
if (error) window.console.error(error);
|
171
180
|
else doc.changed = null;
|
172
181
|
});
|
173
182
|
}
|
@@ -429,6 +438,25 @@
|
|
429
438
|
});
|
430
439
|
}
|
431
440
|
|
441
|
+
function selectName(ts, cm) {
|
442
|
+
var cur = cm.getCursor(), token = cm.getTokenAt(cur);
|
443
|
+
if (!/\w/.test(token.string)) showError(ts, cm, "Not at a variable");
|
444
|
+
var name = findDoc(ts, cm.doc).name;
|
445
|
+
ts.request(cm, {type: "refs"}, function(error, data) {
|
446
|
+
if (error) return showError(ts, cm, error);
|
447
|
+
var ranges = [], cur = 0;
|
448
|
+
for (var i = 0; i < data.refs.length; i++) {
|
449
|
+
var ref = data.refs[i];
|
450
|
+
if (ref.file == name) {
|
451
|
+
ranges.push({anchor: ref.start, head: ref.end});
|
452
|
+
if (cmpPos(cur, ref.start) >= 0 && cmpPos(cur, ref.end) <= 0)
|
453
|
+
cur = ranges.length - 1;
|
454
|
+
}
|
455
|
+
}
|
456
|
+
cm.setSelections(ranges, cur);
|
457
|
+
});
|
458
|
+
}
|
459
|
+
|
432
460
|
var nextChangeOrig = 0;
|
433
461
|
function applyChanges(ts, changes) {
|
434
462
|
var perFile = Object.create(null);
|
@@ -521,7 +549,7 @@
|
|
521
549
|
|
522
550
|
// Generic utilities
|
523
551
|
|
524
|
-
|
552
|
+
var cmpPos = CodeMirror.cmpPos;
|
525
553
|
|
526
554
|
function elt(tagname, cls /*, ... elts*/) {
|
527
555
|
var e = document.createElement(tagname);
|
@@ -614,7 +642,7 @@
|
|
614
642
|
send({type: "getFile", err: String(err), text: text, id: data.id});
|
615
643
|
});
|
616
644
|
} else if (data.type == "debug") {
|
617
|
-
console.log(data.message);
|
645
|
+
window.console.log(data.message);
|
618
646
|
} else if (data.id && pending[data.id]) {
|
619
647
|
pending[data.id](data.err, data.body);
|
620
648
|
delete pending[data.id];
|
@@ -629,4 +657,4 @@
|
|
629
657
|
this.delFile = function(name) { send({type: "del", name: name}); };
|
630
658
|
this.request = function(body, c) { send({type: "req", body: body}, c); };
|
631
659
|
}
|
632
|
-
})
|
660
|
+
});
|
@@ -1,4 +1,11 @@
|
|
1
|
-
(function() {
|
1
|
+
(function(mod) {
|
2
|
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
3
|
+
mod(require("../../lib/codemirror"));
|
4
|
+
else if (typeof define == "function" && define.amd) // AMD
|
5
|
+
define(["../../lib/codemirror"], mod);
|
6
|
+
else // Plain browser env
|
7
|
+
mod(CodeMirror);
|
8
|
+
})(function(CodeMirror) {
|
2
9
|
"use strict";
|
3
10
|
|
4
11
|
var Pos = CodeMirror.Pos;
|
@@ -89,6 +96,24 @@
|
|
89
96
|
return wrapRange(this, Pos(para.from, 0), Pos(para.to - 1), options);
|
90
97
|
});
|
91
98
|
|
99
|
+
CodeMirror.commands.wrapLines = function(cm) {
|
100
|
+
cm.operation(function() {
|
101
|
+
var ranges = cm.listSelections(), at = cm.lastLine() + 1;
|
102
|
+
for (var i = ranges.length - 1; i >= 0; i--) {
|
103
|
+
var range = ranges[i], span;
|
104
|
+
if (range.empty()) {
|
105
|
+
var para = findParagraph(cm, range.head, {});
|
106
|
+
span = {from: Pos(para.from, 0), to: Pos(para.to - 1)};
|
107
|
+
} else {
|
108
|
+
span = {from: range.from(), to: range.to()};
|
109
|
+
}
|
110
|
+
if (span.to.line >= at) continue;
|
111
|
+
at = span.from.line;
|
112
|
+
wrapRange(cm, span.from, span.to, {});
|
113
|
+
}
|
114
|
+
});
|
115
|
+
};
|
116
|
+
|
92
117
|
CodeMirror.defineExtension("wrapRange", function(from, to, options) {
|
93
118
|
return wrapRange(this, from, to, options || {});
|
94
119
|
});
|
@@ -108,4 +133,4 @@
|
|
108
133
|
});
|
109
134
|
return madeChange;
|
110
135
|
});
|
111
|
-
})
|
136
|
+
});
|
@@ -1,4 +1,11 @@
|
|
1
|
-
(function() {
|
1
|
+
(function(mod) {
|
2
|
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
3
|
+
mod(require("../lib/codemirror"));
|
4
|
+
else if (typeof define == "function" && define.amd) // AMD
|
5
|
+
define(["../lib/codemirror"], mod);
|
6
|
+
else // Plain browser env
|
7
|
+
mod(CodeMirror);
|
8
|
+
})(function(CodeMirror) {
|
2
9
|
"use strict";
|
3
10
|
|
4
11
|
var Pos = CodeMirror.Pos;
|
@@ -174,7 +181,7 @@
|
|
174
181
|
if (dup > 1 && event.origin == "+input") {
|
175
182
|
var one = event.text.join("\n"), txt = "";
|
176
183
|
for (var i = 1; i < dup; ++i) txt += one;
|
177
|
-
cm.replaceSelection(txt
|
184
|
+
cm.replaceSelection(txt);
|
178
185
|
}
|
179
186
|
}
|
180
187
|
|
@@ -266,7 +273,7 @@
|
|
266
273
|
cm.replaceRange(getFromRing(getPrefix(cm)), start, start, "paste");
|
267
274
|
cm.setSelection(start, cm.getCursor());
|
268
275
|
},
|
269
|
-
"Alt-Y": function(cm) {cm.replaceSelection(popFromRing());},
|
276
|
+
"Alt-Y": function(cm) {cm.replaceSelection(popFromRing(), "around", "paste");},
|
270
277
|
|
271
278
|
"Ctrl-Space": setMark, "Ctrl-Shift-2": setMark,
|
272
279
|
|
@@ -323,7 +330,7 @@
|
|
323
330
|
var range = cm.getRange(from, pos);
|
324
331
|
if (range.length != 2) return;
|
325
332
|
cm.setSelection(from, pos);
|
326
|
-
cm.replaceSelection(range.charAt(1) + range.charAt(0), "
|
333
|
+
cm.replaceSelection(range.charAt(1) + range.charAt(0), null, "+transpose");
|
327
334
|
}),
|
328
335
|
|
329
336
|
"Alt-C": repeated(function(cm) {
|
@@ -395,4 +402,4 @@
|
|
395
402
|
}
|
396
403
|
for (var i = 0; i < 10; ++i) regPrefix(String(i));
|
397
404
|
regPrefix("-");
|
398
|
-
})
|
405
|
+
});
|
@@ -0,0 +1,505 @@
|
|
1
|
+
// A rough approximation of Sublime Text's keybindings
|
2
|
+
// Depends on addon/search/searchcursor.js and optionally addon/dialog/dialogs.js
|
3
|
+
|
4
|
+
(function(mod) {
|
5
|
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
6
|
+
mod(require("../lib/codemirror"), require("../addon/search/searchcursor"), require("../addon/edit/matchbrackets"));
|
7
|
+
else if (typeof define == "function" && define.amd) // AMD
|
8
|
+
define(["../lib/codemirror", "../addon/search/searchcursor", "../addon/edit/matchbrackets"], mod);
|
9
|
+
else // Plain browser env
|
10
|
+
mod(CodeMirror);
|
11
|
+
})(function(CodeMirror) {
|
12
|
+
"use strict";
|
13
|
+
|
14
|
+
var map = CodeMirror.keyMap.sublime = {fallthrough: "default"};
|
15
|
+
var cmds = CodeMirror.commands;
|
16
|
+
var Pos = CodeMirror.Pos;
|
17
|
+
var ctrl = CodeMirror.keyMap["default"] == CodeMirror.keyMap.pcDefault ? "Ctrl-" : "Cmd-";
|
18
|
+
|
19
|
+
// This is not exactly Sublime's algorithm. I couldn't make heads or tails of that.
|
20
|
+
function findPosSubword(doc, start, dir) {
|
21
|
+
if (dir < 0 && start.ch == 0) return doc.clipPos(Pos(start.line - 1));
|
22
|
+
var line = doc.getLine(start.line);
|
23
|
+
if (dir > 0 && start.ch >= line.length) return doc.clipPos(Pos(start.line + 1, 0));
|
24
|
+
var state = "start", type;
|
25
|
+
for (var pos = start.ch, e = dir < 0 ? 0 : line.length, i = 0; pos != e; pos += dir, i++) {
|
26
|
+
var next = line.charAt(dir < 0 ? pos - 1 : pos);
|
27
|
+
var cat = next != "_" && CodeMirror.isWordChar(next) ? "w" : "o";
|
28
|
+
if (cat == "w" && next.toUpperCase() == next) cat = "W";
|
29
|
+
if (state == "start") {
|
30
|
+
if (cat != "o") { state = "in"; type = cat; }
|
31
|
+
} else if (state == "in") {
|
32
|
+
if (type != cat) {
|
33
|
+
if (type == "w" && cat == "W" && dir < 0) pos--;
|
34
|
+
if (type == "W" && cat == "w" && dir > 0) { type = "w"; continue; }
|
35
|
+
break;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
return Pos(start.line, pos);
|
40
|
+
}
|
41
|
+
|
42
|
+
function moveSubword(cm, dir) {
|
43
|
+
cm.extendSelectionsBy(function(range) {
|
44
|
+
if (cm.display.shift || cm.doc.extend || range.empty())
|
45
|
+
return findPosSubword(cm.doc, range.head, dir);
|
46
|
+
else
|
47
|
+
return dir < 0 ? range.from() : range.to();
|
48
|
+
});
|
49
|
+
}
|
50
|
+
|
51
|
+
cmds[map["Alt-Left"] = "goSubwordLeft"] = function(cm) { moveSubword(cm, -1); };
|
52
|
+
cmds[map["Alt-Right"] = "goSubwordRight"] = function(cm) { moveSubword(cm, 1); };
|
53
|
+
|
54
|
+
cmds[map[ctrl + "Up"] = "scrollLineUp"] = function(cm) {
|
55
|
+
cm.scrollTo(null, cm.getScrollInfo().top - cm.defaultTextHeight());
|
56
|
+
};
|
57
|
+
cmds[map[ctrl + "Down"] = "scrollLineDown"] = function(cm) {
|
58
|
+
cm.scrollTo(null, cm.getScrollInfo().top + cm.defaultTextHeight());
|
59
|
+
};
|
60
|
+
|
61
|
+
cmds[map["Shift-" + ctrl + "L"] = "splitSelectionByLine"] = function(cm) {
|
62
|
+
var ranges = cm.listSelections(), lineRanges = [];
|
63
|
+
for (var i = 0; i < ranges.length; i++) {
|
64
|
+
var from = ranges[i].from(), to = ranges[i].to();
|
65
|
+
for (var line = from.line; line <= to.line; ++line)
|
66
|
+
if (!(to.line > from.line && line == to.line && to.ch == 0))
|
67
|
+
lineRanges.push({anchor: line == from.line ? from : Pos(line, 0),
|
68
|
+
head: line == to.line ? to : Pos(line)});
|
69
|
+
}
|
70
|
+
cm.setSelections(lineRanges, 0);
|
71
|
+
};
|
72
|
+
|
73
|
+
map["Shift-Tab"] = "indentLess";
|
74
|
+
|
75
|
+
cmds[map["Esc"] = "singleSelectionTop"] = function(cm) {
|
76
|
+
var range = cm.listSelections()[0];
|
77
|
+
cm.setSelection(range.anchor, range.head, {scroll: false});
|
78
|
+
};
|
79
|
+
|
80
|
+
cmds[map[ctrl + "L"] = "selectLine"] = function(cm) {
|
81
|
+
var ranges = cm.listSelections(), extended = [];
|
82
|
+
for (var i = 0; i < ranges.length; i++) {
|
83
|
+
var range = ranges[i];
|
84
|
+
extended.push({anchor: Pos(range.from().line, 0),
|
85
|
+
head: Pos(range.to().line + 1, 0)});
|
86
|
+
}
|
87
|
+
cm.setSelections(extended);
|
88
|
+
};
|
89
|
+
|
90
|
+
map["Shift-" + ctrl + "K"] = "deleteLine";
|
91
|
+
|
92
|
+
function insertLine(cm, above) {
|
93
|
+
cm.operation(function() {
|
94
|
+
var len = cm.listSelections().length, newSelection = [], last = -1;
|
95
|
+
for (var i = 0; i < len; i++) {
|
96
|
+
var head = cm.listSelections()[i].head;
|
97
|
+
if (head.line <= last) continue;
|
98
|
+
var at = Pos(head.line + (above ? 0 : 1), 0);
|
99
|
+
cm.replaceRange("\n", at, null, "+insertLine");
|
100
|
+
cm.indentLine(at.line, null, true);
|
101
|
+
newSelection.push({head: at, anchor: at});
|
102
|
+
last = head.line + 1;
|
103
|
+
}
|
104
|
+
cm.setSelections(newSelection);
|
105
|
+
});
|
106
|
+
}
|
107
|
+
|
108
|
+
cmds[map[ctrl + "Enter"] = "insertLineAfter"] = function(cm) { insertLine(cm, false); };
|
109
|
+
|
110
|
+
cmds[map["Shift-" + ctrl + "Enter"] = "insertLineBefore"] = function(cm) { insertLine(cm, true); };
|
111
|
+
|
112
|
+
function wordAt(cm, pos) {
|
113
|
+
var start = pos.ch, end = start, line = cm.getLine(pos.line);
|
114
|
+
while (start && CodeMirror.isWordChar(line.charAt(start - 1))) --start;
|
115
|
+
while (end < line.length && CodeMirror.isWordChar(line.charAt(end))) ++end;
|
116
|
+
return {from: Pos(pos.line, start), to: Pos(pos.line, end), word: line.slice(start, end)};
|
117
|
+
}
|
118
|
+
|
119
|
+
cmds[map[ctrl + "D"] = "selectNextOccurrence"] = function(cm) {
|
120
|
+
var from = cm.getCursor("from"), to = cm.getCursor("to");
|
121
|
+
var fullWord = cm.state.sublimeFindFullWord == cm.doc.sel;
|
122
|
+
if (CodeMirror.cmpPos(from, to) == 0) {
|
123
|
+
var word = wordAt(cm, from);
|
124
|
+
if (!word.word) return;
|
125
|
+
cm.setSelection(word.from, word.to);
|
126
|
+
fullWord = true;
|
127
|
+
} else {
|
128
|
+
var text = cm.getRange(from, to);
|
129
|
+
var query = fullWord ? new RegExp("\\b" + text + "\\b") : text;
|
130
|
+
var cur = cm.getSearchCursor(query, to);
|
131
|
+
if (cur.findNext()) {
|
132
|
+
cm.addSelection(cur.from(), cur.to());
|
133
|
+
} else {
|
134
|
+
cur = cm.getSearchCursor(query, Pos(cm.firstLine(), 0));
|
135
|
+
if (cur.findNext())
|
136
|
+
cm.addSelection(cur.from(), cur.to());
|
137
|
+
}
|
138
|
+
}
|
139
|
+
if (fullWord)
|
140
|
+
cm.state.sublimeFindFullWord = cm.doc.sel;
|
141
|
+
};
|
142
|
+
|
143
|
+
var mirror = "(){}[]";
|
144
|
+
function selectBetweenBrackets(cm) {
|
145
|
+
var pos = cm.getCursor(), opening = cm.scanForBracket(pos, -1);
|
146
|
+
if (!opening) return;
|
147
|
+
for (;;) {
|
148
|
+
var closing = cm.scanForBracket(pos, 1);
|
149
|
+
if (!closing) return;
|
150
|
+
if (closing.ch == mirror.charAt(mirror.indexOf(opening.ch) + 1)) {
|
151
|
+
cm.setSelection(Pos(opening.pos.line, opening.pos.ch + 1), closing.pos, false);
|
152
|
+
return true;
|
153
|
+
}
|
154
|
+
pos = Pos(closing.pos.line, closing.pos.ch + 1);
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
158
|
+
cmds[map["Shift-" + ctrl + "Space"] = "selectScope"] = function(cm) {
|
159
|
+
selectBetweenBrackets(cm) || cm.execCommand("selectAll");
|
160
|
+
};
|
161
|
+
cmds[map["Shift-" + ctrl + "M"] = "selectBetweenBrackets"] = function(cm) {
|
162
|
+
if (!selectBetweenBrackets(cm)) return CodeMirror.Pass;
|
163
|
+
};
|
164
|
+
|
165
|
+
cmds[map[ctrl + "M"] = "goToBracket"] = function(cm) {
|
166
|
+
cm.extendSelectionsBy(function(range) {
|
167
|
+
var next = cm.scanForBracket(range.head, 1);
|
168
|
+
if (next && CodeMirror.cmpPos(next.pos, range.head) != 0) return next.pos;
|
169
|
+
var prev = cm.scanForBracket(range.head, -1);
|
170
|
+
return prev && Pos(prev.pos.line, prev.pos.ch + 1) || range.head;
|
171
|
+
});
|
172
|
+
};
|
173
|
+
|
174
|
+
cmds[map["Shift-" + ctrl + "Up"] = "swapLineUp"] = function(cm) {
|
175
|
+
var ranges = cm.listSelections(), linesToMove = [], at = cm.firstLine() - 1;
|
176
|
+
for (var i = 0; i < ranges.length; i++) {
|
177
|
+
var range = ranges[i], from = range.from().line - 1, to = range.to().line;
|
178
|
+
if (from > at) linesToMove.push(from, to);
|
179
|
+
else if (linesToMove.length) linesToMove[linesToMove.length - 1] = to;
|
180
|
+
at = to;
|
181
|
+
}
|
182
|
+
cm.operation(function() {
|
183
|
+
for (var i = 0; i < linesToMove.length; i += 2) {
|
184
|
+
var from = linesToMove[i], to = linesToMove[i + 1];
|
185
|
+
var line = cm.getLine(from);
|
186
|
+
cm.replaceRange("", Pos(from, 0), Pos(from + 1, 0), "+swapLine");
|
187
|
+
if (to > cm.lastLine()) {
|
188
|
+
cm.replaceRange("\n" + line, Pos(cm.lastLine()), null, "+swapLine");
|
189
|
+
var sels = cm.listSelections(), last = sels[sels.length - 1];
|
190
|
+
var head = last.head.line == to ? Pos(to - 1) : last.head;
|
191
|
+
var anchor = last.anchor.line == to ? Pos(to - 1) : last.anchor;
|
192
|
+
cm.setSelections(sels.slice(0, sels.length - 1).concat([{head: head, anchor: anchor}]));
|
193
|
+
} else {
|
194
|
+
cm.replaceRange(line + "\n", Pos(to, 0), null, "+swapLine");
|
195
|
+
}
|
196
|
+
}
|
197
|
+
cm.scrollIntoView();
|
198
|
+
});
|
199
|
+
};
|
200
|
+
|
201
|
+
cmds[map["Shift-" + ctrl + "Down"] = "swapLineDown"] = function(cm) {
|
202
|
+
var ranges = cm.listSelections(), linesToMove = [], at = cm.lastLine() + 1;
|
203
|
+
for (var i = ranges.length - 1; i >= 0; i--) {
|
204
|
+
var range = ranges[i], from = range.to().line + 1, to = range.from().line;
|
205
|
+
if (from < at) linesToMove.push(from, to);
|
206
|
+
else if (linesToMove.length) linesToMove[linesToMove.length - 1] = to;
|
207
|
+
at = to;
|
208
|
+
}
|
209
|
+
cm.operation(function() {
|
210
|
+
for (var i = linesToMove.length - 2; i >= 0; i -= 2) {
|
211
|
+
var from = linesToMove[i], to = linesToMove[i + 1];
|
212
|
+
var line = cm.getLine(from);
|
213
|
+
if (from == cm.lastLine())
|
214
|
+
cm.replaceRange("", Pos(from - 1), Pos(from), "+swapLine");
|
215
|
+
else
|
216
|
+
cm.replaceRange("", Pos(from, 0), Pos(from + 1, 0), "+swapLine");
|
217
|
+
cm.replaceRange(line + "\n", Pos(to, 0), null, "+swapLine");
|
218
|
+
}
|
219
|
+
cm.scrollIntoView();
|
220
|
+
});
|
221
|
+
};
|
222
|
+
|
223
|
+
map[ctrl + "/"] = "toggleComment";
|
224
|
+
|
225
|
+
cmds[map[ctrl + "J"] = "joinLines"] = function(cm) {
|
226
|
+
var ranges = cm.listSelections(), joined = [];
|
227
|
+
for (var i = 0; i < ranges.length; i++) {
|
228
|
+
var range = ranges[i], from = range.from();
|
229
|
+
var start = from.line, end = range.to().line;
|
230
|
+
while (i < ranges.length - 1 && ranges[i + 1].from().line == end)
|
231
|
+
end = ranges[++i].to().line;
|
232
|
+
joined.push({start: start, end: end, anchor: !range.empty() && from});
|
233
|
+
}
|
234
|
+
cm.operation(function() {
|
235
|
+
var offset = 0, ranges = [];
|
236
|
+
for (var i = 0; i < joined.length; i++) {
|
237
|
+
var obj = joined[i];
|
238
|
+
var anchor = obj.anchor && Pos(obj.anchor.line - offset, obj.anchor.ch), head;
|
239
|
+
for (var line = obj.start; line <= obj.end; line++) {
|
240
|
+
var actual = line - offset;
|
241
|
+
if (line == obj.end) head = Pos(actual, cm.getLine(actual).length + 1);
|
242
|
+
if (actual < cm.lastLine()) {
|
243
|
+
cm.replaceRange(" ", Pos(actual), Pos(actual + 1, /^\s*/.exec(cm.getLine(actual + 1))[0].length));
|
244
|
+
++offset;
|
245
|
+
}
|
246
|
+
}
|
247
|
+
ranges.push({anchor: anchor || head, head: head});
|
248
|
+
}
|
249
|
+
cm.setSelections(ranges, 0);
|
250
|
+
});
|
251
|
+
};
|
252
|
+
|
253
|
+
cmds[map["Shift-" + ctrl + "D"] = "duplicateLine"] = function(cm) {
|
254
|
+
cm.operation(function() {
|
255
|
+
var rangeCount = cm.listSelections().length;
|
256
|
+
for (var i = 0; i < rangeCount; i++) {
|
257
|
+
var range = cm.listSelections()[i];
|
258
|
+
if (range.empty())
|
259
|
+
cm.replaceRange(cm.getLine(range.head.line) + "\n", Pos(range.head.line, 0));
|
260
|
+
else
|
261
|
+
cm.replaceRange(cm.getRange(range.from(), range.to()), range.from());
|
262
|
+
}
|
263
|
+
cm.scrollIntoView();
|
264
|
+
});
|
265
|
+
};
|
266
|
+
|
267
|
+
map[ctrl + "T"] = "transposeChars";
|
268
|
+
|
269
|
+
function sortLines(cm, caseSensitive) {
|
270
|
+
var ranges = cm.listSelections(), toSort = [], selected;
|
271
|
+
for (var i = 0; i < ranges.length; i++) {
|
272
|
+
var range = ranges[i];
|
273
|
+
if (range.empty()) continue;
|
274
|
+
var from = range.from().line, to = range.to().line;
|
275
|
+
while (i < ranges.length - 1 && ranges[i + 1].from().line == to)
|
276
|
+
to = range[++i].to().line;
|
277
|
+
toSort.push(from, to);
|
278
|
+
}
|
279
|
+
if (toSort.length) selected = true;
|
280
|
+
else toSort.push(cm.firstLine(), cm.lastLine());
|
281
|
+
|
282
|
+
cm.operation(function() {
|
283
|
+
var ranges = [];
|
284
|
+
for (var i = 0; i < toSort.length; i += 2) {
|
285
|
+
var from = toSort[i], to = toSort[i + 1];
|
286
|
+
var start = Pos(from, 0), end = Pos(to);
|
287
|
+
var lines = cm.getRange(start, end, false);
|
288
|
+
if (caseSensitive)
|
289
|
+
lines.sort();
|
290
|
+
else
|
291
|
+
lines.sort(function(a, b) {
|
292
|
+
var au = a.toUpperCase(), bu = b.toUpperCase();
|
293
|
+
if (au != bu) { a = au; b = bu; }
|
294
|
+
return a < b ? -1 : a == b ? 0 : 1;
|
295
|
+
});
|
296
|
+
cm.replaceRange(lines, start, end);
|
297
|
+
if (selected) ranges.push({anchor: start, head: end});
|
298
|
+
}
|
299
|
+
if (selected) cm.setSelections(ranges, 0);
|
300
|
+
});
|
301
|
+
}
|
302
|
+
|
303
|
+
cmds[map["F9"] = "sortLines"] = function(cm) { sortLines(cm, true); };
|
304
|
+
cmds[map[ctrl + "F9"] = "sortLinesInsensitive"] = function(cm) { sortLines(cm, false); };
|
305
|
+
|
306
|
+
cmds[map["F2"] = "nextBookmark"] = function(cm) {
|
307
|
+
var marks = cm.state.sublimeBookmarks;
|
308
|
+
if (marks) while (marks.length) {
|
309
|
+
var current = marks.shift();
|
310
|
+
var found = current.find();
|
311
|
+
if (found) {
|
312
|
+
marks.push(current);
|
313
|
+
return cm.setSelection(found.from, found.to);
|
314
|
+
}
|
315
|
+
}
|
316
|
+
};
|
317
|
+
|
318
|
+
cmds[map["Shift-F2"] = "prevBookmark"] = function(cm) {
|
319
|
+
var marks = cm.state.sublimeBookmarks;
|
320
|
+
if (marks) while (marks.length) {
|
321
|
+
marks.unshift(marks.pop());
|
322
|
+
var found = marks[marks.length - 1].find();
|
323
|
+
if (!found)
|
324
|
+
marks.pop();
|
325
|
+
else
|
326
|
+
return cm.setSelection(found.from, found.to);
|
327
|
+
}
|
328
|
+
};
|
329
|
+
|
330
|
+
cmds[map[ctrl + "F2"] = "toggleBookmark"] = function(cm) {
|
331
|
+
var ranges = cm.listSelections();
|
332
|
+
var marks = cm.state.sublimeBookmarks || (cm.state.sublimeBookmarks = []);
|
333
|
+
for (var i = 0; i < ranges.length; i++) {
|
334
|
+
var from = ranges[i].from(), to = ranges[i].to();
|
335
|
+
var found = cm.findMarks(from, to);
|
336
|
+
for (var j = 0; j < found.length; j++) {
|
337
|
+
if (found[j].sublimeBookmark) {
|
338
|
+
found[j].clear();
|
339
|
+
for (var k = 0; k < marks.length; k++)
|
340
|
+
if (marks[k] == found[j])
|
341
|
+
marks.splice(k--, 1);
|
342
|
+
break;
|
343
|
+
}
|
344
|
+
}
|
345
|
+
if (j == found.length)
|
346
|
+
marks.push(cm.markText(from, to, {sublimeBookmark: true, clearWhenEmpty: false}));
|
347
|
+
}
|
348
|
+
};
|
349
|
+
|
350
|
+
cmds[map["Shift-" + ctrl + "F2"] = "clearBookmarks"] = function(cm) {
|
351
|
+
var marks = cm.state.sublimeBookmarks;
|
352
|
+
if (marks) for (var i = 0; i < marks.length; i++) marks[i].clear();
|
353
|
+
marks.length = 0;
|
354
|
+
};
|
355
|
+
|
356
|
+
cmds[map["Alt-F2"] = "selectBookmarks"] = function(cm) {
|
357
|
+
var marks = cm.state.sublimeBookmarks, ranges = [];
|
358
|
+
if (marks) for (var i = 0; i < marks.length; i++) {
|
359
|
+
var found = marks[i].find();
|
360
|
+
if (!found)
|
361
|
+
marks.splice(i--, 0);
|
362
|
+
else
|
363
|
+
ranges.push({anchor: found.from, head: found.to});
|
364
|
+
}
|
365
|
+
if (ranges.length)
|
366
|
+
cm.setSelections(ranges, 0);
|
367
|
+
};
|
368
|
+
|
369
|
+
map["Alt-Q"] = "wrapLines";
|
370
|
+
|
371
|
+
var mapK = CodeMirror.keyMap["sublime-Ctrl-K"] = {auto: "sublime", nofallthrough: true};
|
372
|
+
|
373
|
+
map[ctrl + "K"] = function(cm) {cm.setOption("keyMap", "sublime-Ctrl-K");};
|
374
|
+
|
375
|
+
function modifyWordOrSelection(cm, mod) {
|
376
|
+
cm.operation(function() {
|
377
|
+
var ranges = cm.listSelections(), indices = [], replacements = [];
|
378
|
+
for (var i = 0; i < ranges.length; i++) {
|
379
|
+
var range = ranges[i];
|
380
|
+
if (range.empty()) { indices.push(i); replacements.push(""); }
|
381
|
+
else replacements.push(mod(cm.getRange(range.from(), range.to())));
|
382
|
+
}
|
383
|
+
cm.replaceSelections(replacements, "around", "case");
|
384
|
+
for (var i = indices.length - 1, at; i >= 0; i--) {
|
385
|
+
var range = ranges[indices[i]];
|
386
|
+
if (at && CodeMirror.cmpPos(range.head, at) > 0) continue;
|
387
|
+
var word = wordAt(cm, range.head);
|
388
|
+
at = word.from;
|
389
|
+
cm.replaceRange(mod(word.word), word.from, word.to);
|
390
|
+
}
|
391
|
+
});
|
392
|
+
}
|
393
|
+
|
394
|
+
mapK[ctrl + "Backspace"] = "delLineLeft";
|
395
|
+
|
396
|
+
cmds[mapK[ctrl + "K"] = "delLineRight"] = function(cm) {
|
397
|
+
cm.operation(function() {
|
398
|
+
var ranges = cm.listSelections();
|
399
|
+
for (var i = ranges.length - 1; i >= 0; i--)
|
400
|
+
cm.replaceRange("", ranges[i].anchor, Pos(ranges[i].to().line), "+delete");
|
401
|
+
cm.scrollIntoView();
|
402
|
+
});
|
403
|
+
};
|
404
|
+
|
405
|
+
cmds[mapK[ctrl + "U"] = "upcaseAtCursor"] = function(cm) {
|
406
|
+
modifyWordOrSelection(cm, function(str) { return str.toUpperCase(); });
|
407
|
+
};
|
408
|
+
cmds[mapK[ctrl + "L"] = "downcaseAtCursor"] = function(cm) {
|
409
|
+
modifyWordOrSelection(cm, function(str) { return str.toLowerCase(); });
|
410
|
+
};
|
411
|
+
|
412
|
+
cmds[mapK[ctrl + "Space"] = "setSublimeMark"] = function(cm) {
|
413
|
+
if (cm.state.sublimeMark) cm.state.sublimeMark.clear();
|
414
|
+
cm.state.sublimeMark = cm.setBookmark(cm.getCursor());
|
415
|
+
};
|
416
|
+
cmds[mapK[ctrl + "A"] = "selectToSublimeMark"] = function(cm) {
|
417
|
+
var found = cm.state.sublimeMark && cm.state.sublimeMark.find();
|
418
|
+
if (found) cm.setSelection(cm.getCursor(), found);
|
419
|
+
};
|
420
|
+
cmds[mapK[ctrl + "W"] = "deleteToSublimeMark"] = function(cm) {
|
421
|
+
var found = cm.state.sublimeMark && cm.state.sublimeMark.find();
|
422
|
+
if (found) {
|
423
|
+
var from = cm.getCursor(), to = found;
|
424
|
+
if (CodeMirror.cmpPos(from, to) > 0) { var tmp = to; to = from; from = tmp; }
|
425
|
+
cm.state.sublimeKilled = cm.getRange(from, to);
|
426
|
+
cm.replaceRange("", from, to);
|
427
|
+
}
|
428
|
+
};
|
429
|
+
cmds[mapK[ctrl + "X"] = "swapWithSublimeMark"] = function(cm) {
|
430
|
+
var found = cm.state.sublimeMark && cm.state.sublimeMark.find();
|
431
|
+
if (found) {
|
432
|
+
cm.state.sublimeMark.clear();
|
433
|
+
cm.state.sublimeMark = cm.setBookmark(cm.getCursor());
|
434
|
+
cm.setCursor(found);
|
435
|
+
}
|
436
|
+
};
|
437
|
+
cmds[mapK[ctrl + "Y"] = "sublimeYank"] = function(cm) {
|
438
|
+
if (cm.state.sublimeKilled != null)
|
439
|
+
cm.replaceSelection(cm.state.sublimeKilled, null, "paste");
|
440
|
+
};
|
441
|
+
|
442
|
+
mapK[ctrl + "G"] = "clearBookmarks";
|
443
|
+
cmds[mapK[ctrl + "C"] = "showInCenter"] = function(cm) {
|
444
|
+
var pos = cm.cursorCoords(null, "local");
|
445
|
+
cm.scrollTo(null, (pos.top + pos.bottom) / 2 - cm.getScrollInfo().clientHeight / 2);
|
446
|
+
};
|
447
|
+
|
448
|
+
cmds[map["Shift-Alt-Up"] = "selectLinesUpward"] = function(cm) {
|
449
|
+
cm.operation(function() {
|
450
|
+
var ranges = cm.listSelections();
|
451
|
+
for (var i = 0; i < ranges.length; i++) {
|
452
|
+
var range = ranges[i];
|
453
|
+
if (range.head.line > cm.firstLine())
|
454
|
+
cm.addSelection(Pos(range.head.line - 1, range.head.ch));
|
455
|
+
}
|
456
|
+
});
|
457
|
+
};
|
458
|
+
cmds[map["Shift-Alt-Down"] = "selectLinesDownward"] = function(cm) {
|
459
|
+
cm.operation(function() {
|
460
|
+
var ranges = cm.listSelections();
|
461
|
+
for (var i = 0; i < ranges.length; i++) {
|
462
|
+
var range = ranges[i];
|
463
|
+
if (range.head.line < cm.lastLine())
|
464
|
+
cm.addSelection(Pos(range.head.line + 1, range.head.ch));
|
465
|
+
}
|
466
|
+
});
|
467
|
+
};
|
468
|
+
|
469
|
+
function findAndGoTo(cm, forward) {
|
470
|
+
var from = cm.getCursor("from"), to = cm.getCursor("to");
|
471
|
+
if (CodeMirror.cmpPos(from, to) == 0) {
|
472
|
+
var word = wordAt(cm, from);
|
473
|
+
if (!word.word) return;
|
474
|
+
from = word.from;
|
475
|
+
to = word.to;
|
476
|
+
}
|
477
|
+
|
478
|
+
var query = cm.getRange(from, to);
|
479
|
+
var cur = cm.getSearchCursor(query, forward ? to : from);
|
480
|
+
|
481
|
+
if (forward ? cur.findNext() : cur.findPrevious()) {
|
482
|
+
cm.setSelection(cur.from(), cur.to());
|
483
|
+
} else {
|
484
|
+
cur = cm.getSearchCursor(query, forward ? Pos(cm.firstLine(), 0)
|
485
|
+
: cm.clipPos(Pos(cm.lastLine())));
|
486
|
+
if (forward ? cur.findNext() : cur.findPrevious())
|
487
|
+
cm.setSelection(cur.from(), cur.to());
|
488
|
+
else if (word)
|
489
|
+
cm.setSelection(from, to);
|
490
|
+
}
|
491
|
+
};
|
492
|
+
cmds[map[ctrl + "F3"] = "findUnder"] = function(cm) { findAndGoTo(cm, true); };
|
493
|
+
cmds[map["Shift-" + ctrl + "F3"] = "findUnderPrevious"] = function(cm) { findAndGoTo(cm,false); };
|
494
|
+
|
495
|
+
map["Shift-" + ctrl + "["] = "fold";
|
496
|
+
map["Shift-" + ctrl + "]"] = "unfold";
|
497
|
+
mapK[ctrl + "0"] = mapK[ctrl + "j"] = "unfoldAll";
|
498
|
+
|
499
|
+
map[ctrl + "I"] = "findIncremental";
|
500
|
+
map["Shift-" + ctrl + "I"] = "findIncrementalReverse";
|
501
|
+
map[ctrl + "H"] = "replace";
|
502
|
+
map["F3"] = "findNext";
|
503
|
+
map["Shift-F3"] = "findPrev";
|
504
|
+
|
505
|
+
});
|