Single quotes are not auto-paired like double quotes

fixed #663
This commit is contained in:
Fabian Jakobs 2012-04-06 12:20:10 +02:00
commit d09c0bcdbf

View file

@ -52,12 +52,12 @@ var CstyleBehaviour = function () {
return {
text: '{' + selected + '}',
selection: false
}
};
} else {
return {
text: '{}',
selection: [1, 1]
}
};
}
} else if (text == '}') {
var cursor = editor.getCursorPosition();
@ -69,7 +69,7 @@ var CstyleBehaviour = function () {
return {
text: '',
selection: [1, 1]
}
};
}
}
} else if (text == "\n") {
@ -87,7 +87,7 @@ var CstyleBehaviour = function () {
return {
text: '\n' + indent + '\n' + next_indent,
selection: [1, indent.length, 1, indent.length]
}
};
}
}
});
@ -112,12 +112,12 @@ var CstyleBehaviour = function () {
return {
text: '(' + selected + ')',
selection: false
}
};
} else {
return {
text: '()',
selection: [1, 1]
}
};
}
} else if (text == ')') {
var cursor = editor.getCursorPosition();
@ -129,7 +129,7 @@ var CstyleBehaviour = function () {
return {
text: '',
selection: [1, 1]
}
};
}
}
}
@ -148,14 +148,15 @@ var CstyleBehaviour = function () {
});
this.add("string_dquotes", "insertion", function (state, action, editor, session, text) {
if (text == '"') {
if (text == '"' || text == "'") {
var quote = text;
var selection = editor.getSelectionRange();
var selected = session.doc.getTextRange(selection);
if (selected !== "") {
return {
text: '"' + selected + '"',
text: quote + selected + quote,
selection: false
}
};
} else {
var cursor = editor.getCursorPosition();
var line = session.doc.getLine(cursor.row);
@ -176,7 +177,7 @@ var CstyleBehaviour = function () {
if (token.type == "string") {
quotepos = -1;
} else if (quotepos < 0) {
quotepos = token.value.indexOf('"');
quotepos = token.value.indexOf(quote);
}
if ((token.value.length + col) > selection.start.column) {
break;
@ -185,19 +186,19 @@ var CstyleBehaviour = function () {
}
// Try and be smart about when we auto insert.
if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf('"') === token.value.length-1)))) {
if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) {
return {
text: '""',
text: quote + quote,
selection: [1,1]
}
};
} else if (token && token.type === "string") {
// Ignore input and move right one if we're typing over the closing quote.
var rightChar = line.substring(cursor.column, cursor.column + 1);
if (rightChar == '"') {
if (rightChar == quote) {
return {
text: '',
selection: [1, 1]
}
};
}
}
}
@ -206,7 +207,7 @@ var CstyleBehaviour = function () {
this.add("string_dquotes", "deletion", function (state, action, editor, session, range) {
var selected = session.doc.getTextRange(range);
if (!range.isMultiLine() && selected == '"') {
if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
var line = session.doc.getLine(range.start.row);
var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
if (rightChar == '"') {
@ -216,7 +217,8 @@ var CstyleBehaviour = function () {
}
});
}
};
oop.inherits(CstyleBehaviour, Behaviour);
exports.CstyleBehaviour = CstyleBehaviour;