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

View file

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