Allow insertion before/in punctuation.operator; move rules to constants

This commit is contained in:
Lennart Kats 2012-11-02 13:33:27 +01:00 committed by nightwing
commit ad28e3719e

View file

@ -35,6 +35,11 @@ var oop = require("../../lib/oop");
var Behaviour = require("../behaviour").Behaviour;
var TokenIterator = require("../../token_iterator").TokenIterator;
var SAFE_INSERT_IN_TOKENS =
["text", "paren.rparen", "punctuation.operator"];
var SAFE_INSERT_BEFORE_TOKENS =
["text", "paren.rparen", "punctuation.operator", "comment"];
var autoInsertedBrackets = 0;
var autoInsertedRow = -1;
var autoInsertedLineEnd = "";
@ -46,18 +51,17 @@ var CstyleBehaviour = function () {
var iterator = new TokenIterator(session, cursor.row, cursor.column);
// Don't insert in the middle of a keyword/identifier/lexical
if (!this.$matchTokenType(iterator.getCurrentToken() || "text", ["text", "paren.rparen"])) {
if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
// Look ahead in case we're at the end of a token
var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", ["text", "paren.rparen"]))
if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
return false;
}
// Only insert in front of whitespace/comments
iterator.stepForward();
return iterator.getCurrentTokenRow() !== cursor.row ||
(iterator.getCurrentToken() && iterator.getCurrentToken().value === ";") ||
this.$matchTokenType(iterator.getCurrentToken() || "text", ["text", "comment", "paren.rparen"]);
this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
};
CstyleBehaviour.$matchTokenType = function(token, types) {