Allow insertion before/in punctuation.operator; move rules to constants
This commit is contained in:
parent
b2ce75f95b
commit
ad28e3719e
1 changed files with 8 additions and 4 deletions
|
|
@ -35,6 +35,11 @@ var oop = require("../../lib/oop");
|
||||||
var Behaviour = require("../behaviour").Behaviour;
|
var Behaviour = require("../behaviour").Behaviour;
|
||||||
var TokenIterator = require("../../token_iterator").TokenIterator;
|
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 autoInsertedBrackets = 0;
|
||||||
var autoInsertedRow = -1;
|
var autoInsertedRow = -1;
|
||||||
var autoInsertedLineEnd = "";
|
var autoInsertedLineEnd = "";
|
||||||
|
|
@ -46,18 +51,17 @@ var CstyleBehaviour = function () {
|
||||||
var iterator = new TokenIterator(session, cursor.row, cursor.column);
|
var iterator = new TokenIterator(session, cursor.row, cursor.column);
|
||||||
|
|
||||||
// Don't insert in the middle of a keyword/identifier/lexical
|
// 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
|
// Look ahead in case we're at the end of a token
|
||||||
var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only insert in front of whitespace/comments
|
// Only insert in front of whitespace/comments
|
||||||
iterator.stepForward();
|
iterator.stepForward();
|
||||||
return iterator.getCurrentTokenRow() !== cursor.row ||
|
return iterator.getCurrentTokenRow() !== cursor.row ||
|
||||||
(iterator.getCurrentToken() && iterator.getCurrentToken().value === ";") ||
|
this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
|
||||||
this.$matchTokenType(iterator.getCurrentToken() || "text", ["text", "comment", "paren.rparen"]);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
CstyleBehaviour.$matchTokenType = function(token, types) {
|
CstyleBehaviour.$matchTokenType = function(token, types) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue