add autoindent after { and brace pairing for logiql

This commit is contained in:
nightwing 2013-03-27 14:19:42 +04:00
commit 74f38ffd6a

View file

@ -38,11 +38,15 @@ var LogiQLHighlightRules = require("./logiql_highlight_rules").LogiQLHighlightRu
var FoldMode = require("./folding/coffee").FoldMode; var FoldMode = require("./folding/coffee").FoldMode;
var TokenIterator = require("../token_iterator").TokenIterator; var TokenIterator = require("../token_iterator").TokenIterator;
var Range = require("../range").Range; var Range = require("../range").Range;
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
var Mode = function() { var Mode = function() {
var highlighter = new LogiQLHighlightRules(); var highlighter = new LogiQLHighlightRules();
this.foldingRules = new FoldMode(); this.foldingRules = new FoldMode();
this.$tokenizer = new Tokenizer(highlighter.getRules()); this.$tokenizer = new Tokenizer(highlighter.getRules());
this.$outdent = new MatchingBraceOutdent();
this.$behaviour = new CstyleBehaviour();
}; };
oop.inherits(Mode, TextMode); oop.inherits(Mode, TextMode);
@ -62,12 +66,15 @@ oop.inherits(Mode, TextMode);
return indent; return indent;
var match = line.match(); var match = line.match();
if (/(-->|<--|<-|->)\s*$/.test(line)) if (/(-->|<--|<-|->|{)\s*$/.test(line))
indent += tab; indent += tab;
return indent; return indent;
}; };
this.checkOutdent = function(state, line, input) { this.checkOutdent = function(state, line, input) {
if (this.$outdent.checkOutdent(line, input))
return true;
if (input !== "\n" && input !== "\r\n") if (input !== "\n" && input !== "\r\n")
return false; return false;
@ -78,6 +85,8 @@ oop.inherits(Mode, TextMode);
}; };
this.autoOutdent = function(state, doc, row) { this.autoOutdent = function(state, doc, row) {
if (this.$outdent.autoOutdent(doc, row))
return;
var prevLine = doc.getLine(row); var prevLine = doc.getLine(row);
var match = prevLine.match(/^\s+/); var match = prevLine.match(/^\s+/);
var column = prevLine.lastIndexOf(".") + 1; var column = prevLine.lastIndexOf(".") + 1;