fix weird pairing of quotes in cstyle behavior

This commit is contained in:
nightwing 2015-01-19 00:33:14 +04:00
commit c356c14940
2 changed files with 18 additions and 4 deletions

View file

@ -30,6 +30,7 @@
if (typeof process !== "undefined") { if (typeof process !== "undefined") {
require("amd-loader"); require("amd-loader");
require("../../test/mockdom");
} }
define(function(require, exports, module) { define(function(require, exports, module) {
@ -117,9 +118,9 @@ module.exports = {
editor.setValue(""); editor.setValue("");
exec("insertstring", 1, "{"); exec("insertstring", 1, "{");
assert.equal(editor.getValue(), "{") assert.equal(editor.getValue(), "{");
exec("insertstring", 1, "\n"); exec("insertstring", 1, "\n");
assert.equal(editor.getValue(), "{\n \n}") assert.equal(editor.getValue(), "{\n \n}");
editor.setValue(""); editor.setValue("");
exec("insertstring", 1, "("); exec("insertstring", 1, "(");
@ -129,6 +130,19 @@ module.exports = {
exec("backspace", 1); exec("backspace", 1);
exec("insertstring", 1, '"'); exec("insertstring", 1, '"');
assert.equal(editor.getValue(), '("")'); assert.equal(editor.getValue(), '("")');
editor.setValue("('foo')", 1);
exec("gotoleft", 1);
exec("selectleft", 1);
exec("selectMoreBefore", 1);
exec("insertstring", 1, "'");
assert.equal(editor.getValue(), "('foo')");
exec("selectleft", 1);
exec("insertstring", 1, '"');
assert.equal(editor.getValue(), '("foo")');
exec("selectleft", 1);
exec("insertstring", 1, '"');
assert.equal(editor.getValue(), '("foo")');
} }
}; };

View file

@ -256,7 +256,7 @@ var CstyleBehaviour = function() {
text: quote + selected + quote, text: quote + selected + quote,
selection: false selection: false
}; };
} else { } else if (!selected) {
var cursor = editor.getCursorPosition(); var cursor = editor.getCursorPosition();
var line = session.doc.getLine(cursor.row); var line = session.doc.getLine(cursor.row);
var leftChar = line.substring(cursor.column-1, cursor.column); var leftChar = line.substring(cursor.column-1, cursor.column);
@ -278,7 +278,7 @@ var CstyleBehaviour = function() {
if (stringBefore && !stringAfter) if (stringBefore && !stringAfter)
return null; // wrap string with different quote return null; // wrap string with different quote
if (stringBefore && stringAfter) if (stringBefore && stringAfter)
return null; // do not pair quotes inside strings return null; // do not pair quotes inside strings
var wordRe = session.$mode.tokenRe; var wordRe = session.$mode.tokenRe;
wordRe.lastIndex = 0; wordRe.lastIndex = 0;
var isWordBefore = wordRe.test(leftChar); var isWordBefore = wordRe.test(leftChar);