implement linked tabstops

This commit is contained in:
nightwing 2013-03-18 13:57:20 +04:00
commit 336e30c62d
2 changed files with 33 additions and 15 deletions

View file

@ -557,7 +557,7 @@ var TabstopManager = function(editor) {
lineDif = -lineDif; lineDif = -lineDif;
colDiff = -colDiff; colDiff = -colDiff;
} }
if (!this.$inChange) { if (!this.$inChange && isRemove) {
var ts = this.selectedTabstop; var ts = this.selectedTabstop;
var changedOutside = !ts.some(function(r) { var changedOutside = !ts.some(function(r) {
return comparePoints(r.start, start) <= 0 && comparePoints(r.end, end) >= 0; return comparePoints(r.start, start) <= 0 && comparePoints(r.end, end) >= 0;
@ -594,9 +594,18 @@ var TabstopManager = function(editor) {
}; };
this.updateLinkedFields = function() { this.updateLinkedFields = function() {
var ts = this.selectedTabstop; var ts = this.selectedTabstop;
if (!ts.linkedRanges) if (!ts.hasLinkedRanges)
return; return;
this.$inChange = true;
var session = this.editor.session;
var text = session.getTextRange(ts.firstNonLinked);
for (var i = ts.length; i--;) {
var range = ts[i];
if (!range.linked)
continue;
var fmt = exports.SnippetManager.tmStrFormat(text, range.original)
session.replace(range, fmt);
}
}; };
this.onAfterExec = function(e) { this.onAfterExec = function(e) {
if (e.command && !e.command.readOnly) if (e.command && !e.command.readOnly)
@ -641,9 +650,12 @@ var TabstopManager = function(editor) {
this.selectedTabstop = ts; this.selectedTabstop = ts;
var sel = this.editor.multiSelect; var sel = this.editor.multiSelect;
sel.toSingleRange(ts[0].clone()); sel.toSingleRange(ts.firstNonLinked.clone());
for (var i = ts.length; i--;) for (var i = ts.length; i--;) {
if (ts.hasLinkedRanges && ts[i].linked)
continue;
sel.addRange(ts[i].clone(), true); sel.addRange(ts[i].clone(), true);
}
this.editor.keyBinding.addKeyboardHandler(this.keyboardHandler); this.editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
}; };
this.addTabstops = function(tabstops, start, end) { this.addTabstops = function(tabstops, start, end) {
@ -670,7 +682,14 @@ var TabstopManager = function(editor) {
range.tabstop = ts; range.tabstop = ts;
ranges.push(range); ranges.push(range);
ts[i] = range; ts[i] = range;
if (p.fmt) {
range.linked = true;
ts.hasLinkedRanges = true;
} else if (!ts.firstNonLinked)
ts.firstNonLinked = range;
} }
if (!ts.firstNonLinked)
ts.hasLinkedRanges = false;
arg.push(ts); arg.push(ts);
this.addTabstopMarkers(ts); this.addTabstopMarkers(ts);
}, this); }, this);
@ -713,7 +732,8 @@ var TabstopManager = function(editor) {
ed.tabstopManager.detach(); ed.tabstopManager.detach();
}, },
"Return": function(ed) { "Return": function(ed) {
ed.tabstopManager.tabNext(1); //ed.tabstopManager.tabNext(1);
return false;
}, },
}); });
}).call(TabstopManager.prototype); }).call(TabstopManager.prototype);

View file

@ -24,14 +24,14 @@ snippet f(
# if # if
snippet if snippet if
if (${1:true}) { if (${1:true}) {
${2} ${0}
} }
# if ... else # if ... else
snippet ife snippet ife
if (${1:true}) { if (${1:true}) {
${2} ${2}
} else { } else {
${3} ${0}
} }
# tertiary conditional # tertiary conditional
snippet ter snippet ter
@ -56,15 +56,13 @@ snippet case
# while (...) {...} # while (...) {...}
snippet wh snippet wh
while (${1:/* condition */}) { while (${1:/* condition */}) {
${2:/* code */} ${0:/* code */}
} }
# try # try
snippet try snippet try
try { try {
${1:/* code */} ${0:/* code */}
} catch (${2:e}) { } catch (e) {}
${3:/* handle error */}
}
# do...while # do...while
snippet do snippet do
do { do {
@ -152,7 +150,7 @@ snippet sing
# class # class
regex /^\s*/clas{0,2}/ regex /^\s*/clas{0,2}/
var ${1:class} = function(${20}) { var ${1:class} = function(${20}) {
$40$0\n $40$0
}; };
(function() { (function() {
@ -187,7 +185,7 @@ snippet req
guard ^\s* guard ^\s*
var ${1/.*\///} = require("${1}"); var ${1/.*\///} = require("${1}");
$0 $0
snippet Req snippet requ
guard ^\s* guard ^\s*
var ${1/.*\/(.)/\u$1/} = require("${1}").${1/.*\/(.)/\u$1/}; var ${1/.*\/(.)/\u$1/} = require("${1}").${1/.*\/(.)/\u$1/};
$0 $0