add mixed mode folding rules

This commit is contained in:
Fabian Jakobs 2011-12-02 13:19:36 +01:00
commit a37f9562e3
6 changed files with 213 additions and 8 deletions

View file

@ -4,9 +4,9 @@ import string, sys
# If no arguments were given, print a helpful message
if len(sys.argv)==1:
print '''Usage:
celsius temp1 temp2 ...'''
sys.exit(0)
print '''Usage:
celsius temp1 temp2 ...'''
sys.exit(0)
# Loop over the arguments
for i in sys.argv[1:]:

View file

@ -0,0 +1,87 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Ajax.org Code Editor (ACE).
*
* The Initial Developer of the Original Code is
* Ajax.org B.V.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Fabian Jakobs <fabian AT ajax DOT org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
var oop = require("../../lib/oop");
var BaseFoldMode = require("./fold_mode").FoldMode;
var FoldMode = exports.FoldMode = function(defaultMode, subModes) {
this.defaultMode = defaultMode;
this.subModes = subModes;
};
oop.inherits(FoldMode, BaseFoldMode);
(function() {
this.$getMode = function(state) {
for (var key in this.subModes) {
if (state.indexOf(key) === 0)
return this.subModes[key];
}
return null;
};
this.$tryMode = function(state, session, row) {
var mode = this.$getMode(state);
return (mode ? mode.getFoldWidget(session, row) : "");
};
this.getFoldWidget = function(session, row) {
return (
this.$tryMode(session.getState(row-1), session, row) ||
this.$tryMode(session.getState(row), session, row) ||
this.defaultMode.getFoldWidget(session, row)
);
};
this.getFoldWidgetRange = function(session, row) {
var mode = this.$getMode(session.getState(row-1));
if (!mode || !mode.getFoldWidget(session, row))
mode = this.$getMode(session.getState(row));
if (!mode || !mode.getFoldWidget(session, row))
mode = this.defaultMode;
return mode.getFoldWidgetRange(session, row);
};
}).call(FoldMode.prototype);
});

View file

@ -0,0 +1,106 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Ajax.org Code Editor (ACE).
*
* The Initial Developer of the Original Code is
* Ajax.org B.V.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Fabian Jakobs <fabian AT ajax DOT org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
if (typeof process !== "undefined")
require("amd-loader");
define(function(require, exports, module) {
var FoldMode = require("./mixed").FoldMode;
var XmlFoldMode = require("./xml").FoldMode;
var HtmlMode = require("../html").Mode;
var EditSession = require("../../edit_session").EditSession;
var assert = require("../../test/assertions");
module.exports = {
"test: fold mixed html and javascript": function() {
var session = new EditSession([
'<script type="text/javascript"> ',
'function() foo {',
' var bar = 1;',
'}',
'</script>'
]);
var mode = new HtmlMode();
session.setMode(mode);
assert.equal(session.getFoldWidget(0), "start");
assert.equal(session.getFoldWidget(1), "start");
assert.equal(session.getFoldWidget(2), "");
assert.equal(session.getFoldWidget(3), "end");
assert.equal(session.getFoldWidget(4), "end");
assert.range(session.getFoldWidgetRange(0), 0, 8, 4, 0);
assert.range(session.getFoldWidgetRange(4), 0, 8, 4, 0);
assert.range(session.getFoldWidgetRange(1), 1, 16, 3, 0);
assert.range(session.getFoldWidgetRange(3), 1, 16, 3, 0);
},
"test: fold mixed html and css": function() {
var session = new EditSession([
'<style type="text/css">',
' .text-layer {',
' font-family: Monaco, "Courier New", monospace;',
' }',
'</style>'
]);
var mode = new HtmlMode();
session.setMode(mode);
assert.equal(session.getFoldWidget(0), "start");
assert.equal(session.getFoldWidget(1), "start");
assert.equal(session.getFoldWidget(2), "");
assert.equal(session.getFoldWidget(3), "end");
assert.equal(session.getFoldWidget(4), "end");
assert.range(session.getFoldWidgetRange(0), 0, 7, 4, 0);
assert.range(session.getFoldWidgetRange(4), 0, 7, 4, 0);
assert.range(session.getFoldWidgetRange(1), 1, 17, 3, 4);
assert.range(session.getFoldWidgetRange(3), 1, 17, 3, 4);
}
};
});
if (typeof process !== "undefined")
require("asyncjs").test.testcase(module.exports).exec();

View file

@ -149,7 +149,7 @@ oop.inherits(FoldMode, BaseFoldMode);
if (stack.length === 0) {
end = {
row: iterator.getCurrentTokenRow(),
column: iterator.getCurrentTokenColumn() + (isBack ? value.length : 0)
column: iterator.getCurrentTokenColumn() + (isBack ? value.length + 1 : 0)
};
if (isBack)
return Range.fromPoints(end, start);

View file

@ -44,7 +44,9 @@ var CssMode = require("./css").Mode;
var Tokenizer = require("../tokenizer").Tokenizer;
var HtmlHighlightRules = require("./html_highlight_rules").HtmlHighlightRules;
var XmlBehaviour = require("./behaviour/xml").XmlBehaviour;
var MixedFoldMode = require("./folding/mixed").FoldMode;
var XmlFoldMode = require("./folding/xml").FoldMode;
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
var Mode = function() {
var highlighter = new HtmlHighlightRules();
@ -53,11 +55,11 @@ var Mode = function() {
this.$embeds = highlighter.getEmbeds();
this.createModeDelegates({
"js-": JavaScriptMode,
"css-": CssMode
"js-": JavaScriptMode,
"css-": CssMode
});
this.foldingRules = new XmlFoldMode({
this.foldingRules = new MixedFoldMode(new XmlFoldMode({
"area": 1,
"base": 1,
"br": 1,
@ -74,6 +76,9 @@ var Mode = function() {
"source": 1,
"track": 1,
"wbr": 1
}), {
"js-": new CStyleFoldMode(),
"css-": new CStyleFoldMode()
});
};
oop.inherits(Mode, TextMode);

View file

@ -42,6 +42,9 @@ var XmlMode = require("./xml").Mode;
var JavaScriptMode = require("./javascript").Mode;
var Tokenizer = require("../tokenizer").Tokenizer;
var SvgHighlightRules = require("./svg_highlight_rules").SvgHighlightRules;
var MixedFoldMode = require("./folding/mixed").FoldMode;
var XmlFoldMode = require("./folding/xml").FoldMode;
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
var Mode = function() {
XmlMode.call(this);
@ -51,7 +54,11 @@ var Mode = function() {
this.$embeds = this.highlighter.getEmbeds();
this.createModeDelegates({
"js-": JavaScriptMode
"js-": JavaScriptMode
});
this.foldingRules = new MixedFoldMode(new XmlFoldMode({}), {
"js-": new CStyleFoldMode()
});
};