Merge pull request #819 from ajaxorg/misc
foldmode improvements and autosizing markers
This commit is contained in:
commit
cc0508b922
19 changed files with 338 additions and 144 deletions
|
|
@ -97,10 +97,9 @@ exports.init = function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var m = src.match(/^(?:(.*\/)ace\.js)(?:\?|$)/);
|
var m = src.match(/^(.*)\/ace(\-\w+)?\.js(\?|$)/);
|
||||||
if (m) {
|
if (m)
|
||||||
scriptUrl = m[1] || m[2];
|
scriptUrl = m[1];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scriptUrl) {
|
if (scriptUrl) {
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@
|
||||||
.ace_scroller {
|
.ace_scroller {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
width : 100%;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.ace_content {
|
.ace_content {
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ function BracketMatch() {
|
||||||
var match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
|
var match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
|
||||||
if (!match) {
|
if (!match) {
|
||||||
chr = line.charAt(pos.column);
|
chr = line.charAt(pos.column);
|
||||||
pos.column++;
|
pos = {row: pos.row, column: pos.column + 1};
|
||||||
match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
|
match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
|
||||||
before = false;
|
before = false;
|
||||||
}
|
}
|
||||||
|
|
@ -123,9 +123,6 @@ function BracketMatch() {
|
||||||
range.cursor = range.start;
|
range.cursor = range.start;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!before)
|
|
||||||
pos.column--;
|
|
||||||
|
|
||||||
return range;
|
return range;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -194,7 +191,7 @@ function BracketMatch() {
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$findClosingBracket = function(bracket, position, typeRe, allowBlankLine) {
|
this.$findClosingBracket = function(bracket, position, typeRe) {
|
||||||
var closingBracket = this.$brackets[bracket];
|
var closingBracket = this.$brackets[bracket];
|
||||||
var depth = 1;
|
var depth = 1;
|
||||||
|
|
||||||
|
|
@ -239,12 +236,6 @@ function BracketMatch() {
|
||||||
// whose type matches typeRe
|
// whose type matches typeRe
|
||||||
do {
|
do {
|
||||||
token = iterator.stepForward();
|
token = iterator.stepForward();
|
||||||
if (allowBlankLine) {
|
|
||||||
// if you've reached the doc end, or, you match a new content line
|
|
||||||
if (token === null || token.type == "string") {
|
|
||||||
return {row: iterator.getCurrentTokenRow() + (token === null ? 1 : -1), column: 0};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while (token && !typeRe.test(token.type));
|
} while (token && !typeRe.test(token.type));
|
||||||
|
|
||||||
if (token == null)
|
if (token == null)
|
||||||
|
|
|
||||||
|
|
@ -141,28 +141,24 @@ var Marker = function(parentEl) {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Draws a multi line marker, where lines span the full width
|
// Draws a multi line marker, where lines span the full width
|
||||||
this.drawMultiLineMarker = function(stringBuilder, range, clazz, layerConfig, type) {
|
this.drawMultiLineMarker = function(stringBuilder, range, clazz, config, type) {
|
||||||
var padding = type === "background" ? 0 : this.$padding;
|
var padding = type === "background" ? 0 : this.$padding;
|
||||||
var layerWidth = layerConfig.width + 2 * this.$padding - padding;
|
|
||||||
// from selection start to the end of the line
|
// from selection start to the end of the line
|
||||||
var height = layerConfig.lineHeight;
|
var height = config.lineHeight;
|
||||||
var width = Math.round(layerWidth - (range.start.column * layerConfig.characterWidth));
|
var top = this.$getTop(range.start.row, config);
|
||||||
var top = this.$getTop(range.start.row, layerConfig);
|
var left = Math.round(padding + range.start.column * config.characterWidth);
|
||||||
var left = Math.round(
|
|
||||||
padding + range.start.column * layerConfig.characterWidth
|
|
||||||
);
|
|
||||||
|
|
||||||
stringBuilder.push(
|
stringBuilder.push(
|
||||||
"<div class='", clazz, " start' style='",
|
"<div class='", clazz, " start' style='",
|
||||||
"height:", height, "px;",
|
"height:", height, "px;",
|
||||||
"width:", width, "px;",
|
"right:0;",
|
||||||
"top:", top, "px;",
|
"top:", top, "px;",
|
||||||
"left:", left, "px;'></div>"
|
"left:", left, "px;'></div>"
|
||||||
);
|
);
|
||||||
|
|
||||||
// from start of the last line to the selection end
|
// from start of the last line to the selection end
|
||||||
top = this.$getTop(range.end.row, layerConfig);
|
top = this.$getTop(range.end.row, config);
|
||||||
width = Math.round(range.end.column * layerConfig.characterWidth);
|
var width = Math.round(range.end.column * config.characterWidth);
|
||||||
|
|
||||||
stringBuilder.push(
|
stringBuilder.push(
|
||||||
"<div class='", clazz, "' style='",
|
"<div class='", clazz, "' style='",
|
||||||
|
|
@ -173,15 +169,15 @@ var Marker = function(parentEl) {
|
||||||
);
|
);
|
||||||
|
|
||||||
// all the complete lines
|
// all the complete lines
|
||||||
height = (range.end.row - range.start.row - 1) * layerConfig.lineHeight;
|
height = (range.end.row - range.start.row - 1) * config.lineHeight;
|
||||||
if (height < 0)
|
if (height < 0)
|
||||||
return;
|
return;
|
||||||
top = this.$getTop(range.start.row + 1, layerConfig);
|
top = this.$getTop(range.start.row + 1, config);
|
||||||
|
|
||||||
stringBuilder.push(
|
stringBuilder.push(
|
||||||
"<div class='", clazz, "' style='",
|
"<div class='", clazz, "' style='",
|
||||||
"height:", height, "px;",
|
"height:", height, "px;",
|
||||||
"width:", layerWidth, "px;",
|
"right:0;",
|
||||||
"top:", top, "px;",
|
"top:", top, "px;",
|
||||||
"left:", padding, "px;'></div>"
|
"left:", padding, "px;'></div>"
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -510,9 +510,9 @@ var Text = function(parentEl) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$renderFoldLine = function(stringBuilder, row, tokens, onlyContents) {
|
this.$renderFoldLine = function(stringBuilder, row, tokens, onlyContents) {
|
||||||
var session = this.session,
|
var session = this.session;
|
||||||
foldLine = session.getFoldLine(row),
|
var foldLine = session.getFoldLine(row);
|
||||||
renderTokens = [];
|
var renderTokens = [];
|
||||||
|
|
||||||
function addTokens(tokens, from, to) {
|
function addTokens(tokens, from, to) {
|
||||||
var idx = 0, col = 0;
|
var idx = 0, col = 0;
|
||||||
|
|
@ -520,16 +520,14 @@ var Text = function(parentEl) {
|
||||||
col += tokens[idx].value.length;
|
col += tokens[idx].value.length;
|
||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
if (idx == tokens.length) {
|
if (idx == tokens.length)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (col != from) {
|
if (col != from) {
|
||||||
var value = tokens[idx].value.substring(from - col);
|
var value = tokens[idx].value.substring(from - col);
|
||||||
// Check if the token value is longer then the from...to spacing.
|
// Check if the token value is longer then the from...to spacing.
|
||||||
if (value.length > (to - from)) {
|
if (value.length > (to - from))
|
||||||
value = value.substring(0, to - from);
|
value = value.substring(0, to - from);
|
||||||
}
|
|
||||||
|
|
||||||
renderTokens.push({
|
renderTokens.push({
|
||||||
type: tokens[idx].type,
|
type: tokens[idx].type,
|
||||||
|
|
@ -540,15 +538,15 @@ var Text = function(parentEl) {
|
||||||
idx += 1;
|
idx += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (col < to) {
|
while (col < to && idx < tokens.length) {
|
||||||
var value = tokens[idx].value;
|
var value = tokens[idx].value;
|
||||||
if (value.length + col > to) {
|
if (value.length + col > to) {
|
||||||
value = value.substring(0, to - col);
|
|
||||||
}
|
|
||||||
renderTokens.push({
|
renderTokens.push({
|
||||||
type: tokens[idx].type,
|
type: tokens[idx].type,
|
||||||
value: value
|
value: value.substring(0, to - col)
|
||||||
});
|
});
|
||||||
|
} else
|
||||||
|
renderTokens.push(tokens[idx]);
|
||||||
col += value.length;
|
col += value.length;
|
||||||
idx += 1;
|
idx += 1;
|
||||||
}
|
}
|
||||||
|
|
@ -562,14 +560,14 @@ var Text = function(parentEl) {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (isNewRow)
|
if (isNewRow)
|
||||||
tokens = this.session.getTokens(row);
|
tokens = session.getTokens(row);
|
||||||
|
|
||||||
if (tokens.length)
|
if (tokens.length)
|
||||||
addTokens(tokens, lastColumn, column);
|
addTokens(tokens, lastColumn, column);
|
||||||
}
|
}
|
||||||
}.bind(this), foldLine.end.row, this.session.getLine(foldLine.end.row).length);
|
}, foldLine.end.row, this.session.getLine(foldLine.end.row).length);
|
||||||
|
|
||||||
// TODO: Build a fake splits array!
|
// splits for foldline are stored at its' first row
|
||||||
var splits = this.session.$useWrapMode ? this.session.$wrapData[row] : null;
|
var splits = this.session.$useWrapMode ? this.session.$wrapData[row] : null;
|
||||||
this.$renderLineCore(stringBuilder, row, renderTokens, splits, onlyContents);
|
this.$renderLineCore(stringBuilder, row, renderTokens, splits, onlyContents);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -56,18 +56,6 @@ oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
this.getNextLineIndent = function(state, line, tab) {
|
||||||
var indent = this.$getIndent(line);
|
var indent = this.$getIndent(line);
|
||||||
|
|
||||||
// ignore braces in comments
|
|
||||||
var tokens = this.$tokenizer.getLineTokens(line, state).tokens;
|
|
||||||
if (tokens.length && tokens[tokens.length-1].type == "comment") {
|
|
||||||
return indent;
|
|
||||||
}
|
|
||||||
|
|
||||||
var match = line.match(/^.*\{\s*$/);
|
|
||||||
if (match) {
|
|
||||||
indent += tab;
|
|
||||||
}
|
|
||||||
|
|
||||||
return indent;
|
return indent;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ define(function(require, exports, module) {
|
||||||
var Tokenizer = require("../tokenizer").Tokenizer;
|
var Tokenizer = require("../tokenizer").Tokenizer;
|
||||||
var Rules = require("./coffee_highlight_rules").CoffeeHighlightRules;
|
var Rules = require("./coffee_highlight_rules").CoffeeHighlightRules;
|
||||||
var Outdent = require("./matching_brace_outdent").MatchingBraceOutdent;
|
var Outdent = require("./matching_brace_outdent").MatchingBraceOutdent;
|
||||||
var PythonFoldMode = require("./folding/pythonic").FoldMode;
|
var PythonFoldMode = require("./folding/coffee").FoldMode;
|
||||||
var Range = require("../range").Range;
|
var Range = require("../range").Range;
|
||||||
var TextMode = require("./text").Mode;
|
var TextMode = require("./text").Mode;
|
||||||
var WorkerClient = require("../worker/worker_client").WorkerClient;
|
var WorkerClient = require("../worker/worker_client").WorkerClient;
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,7 @@ define(function(require, exports, module) {
|
||||||
regex : "\\?|\\:|\\,|\\."
|
regex : "\\?|\\:|\\,|\\."
|
||||||
}, {
|
}, {
|
||||||
token : "keyword.operator",
|
token : "keyword.operator",
|
||||||
regex : "(?:[\\-=]>|[-+*/%<>&|^!?=]=|>>>=?|\\-\\-|\\+\\+|::|&&=|\\|\\|=|<<=|>>=|\\?\\.|\\.{2,3}|\\!)"
|
regex : "(?:[\\-=]>|[-+*/%<>&|^!?=]=|>>>=?|\\-\\-|\\+\\+|::|&&=|\\|\\|=|<<=|>>=|\\?\\.|\\.{2,3}|[!*+-=><])"
|
||||||
}, {
|
}, {
|
||||||
token : "paren.lparen",
|
token : "paren.lparen",
|
||||||
regex : "[({[]"
|
regex : "[({[]"
|
||||||
|
|
|
||||||
|
|
@ -48,46 +48,32 @@ oop.inherits(FoldMode, BaseFoldMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
this.foldingStartMarker = /[a-zA-Z](:)\s*$/;
|
this.foldingStartMarker = /^(\w.*\:|Searching for.*)$/;
|
||||||
this.foldingStopMarker = /^(\s*)$/;
|
this.foldingStopMarker = /^(\s+|Found.*)$/;
|
||||||
|
|
||||||
this.getFoldWidgetRange = function(session, foldStyle, row) {
|
this.getFoldWidgetRange = function(session, foldStyle, row) {
|
||||||
var line = session.getLine(row);
|
var line = session.getLine(row);
|
||||||
var match = line.match(this.foldingStartMarker);
|
var level1 = /^(Found.*|Searching for.*)$/;
|
||||||
if (match) {
|
var level2 = /^(\w.*\:|\s*)$/;
|
||||||
var i = match.index;
|
var re = level1.test(line) ? level1 : level2;
|
||||||
|
|
||||||
if (match[1])
|
if (this.foldingStartMarker.test(line)) {
|
||||||
return this.openingBracketBlock(session, match[1], row, i, false, true);
|
for (var i = row + 1, l = session.getLength(); i < l; i++) {
|
||||||
|
if (re.test(session.getLine(i)))
|
||||||
var range = session.getCommentFoldRange(row, i + match[0].length);
|
break;
|
||||||
range.end.column -= 2;
|
|
||||||
return range;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foldStyle !== "markbeginend")
|
return new Range(row, line.length, i, 0);
|
||||||
return;
|
|
||||||
|
|
||||||
var match = line.match(this.foldingStopMarker);
|
|
||||||
if (match) {
|
|
||||||
var i = match.index + match[0].length;
|
|
||||||
|
|
||||||
if (match[2]) {
|
|
||||||
var range = session.getCommentFoldRange(row, i);
|
|
||||||
range.end.column -= 2;
|
|
||||||
return range;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var end = {row: row, column: i};
|
if (this.foldingStopMarker.test(line)) {
|
||||||
var start = session.$findOpeningBracket(match[1], end);
|
for (var i = row - 1; i >= 0; i--) {
|
||||||
|
line = session.getLine(i);
|
||||||
|
if (re.test(line))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (!start)
|
return new Range(i, line.length, row, 0);
|
||||||
return;
|
|
||||||
|
|
||||||
start.column++;
|
|
||||||
end.column--;
|
|
||||||
|
|
||||||
return Range.fromPoints(start, end);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
127
lib/ace/mode/folding/coffee.js
Normal file
127
lib/ace/mode/folding/coffee.js
Normal file
|
|
@ -0,0 +1,127 @@
|
||||||
|
/* ***** 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) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var oop = require("../../lib/oop");
|
||||||
|
var BaseFoldMode = require("./fold_mode").FoldMode;
|
||||||
|
var Range = require("../../range").Range;
|
||||||
|
|
||||||
|
var FoldMode = exports.FoldMode = function() {};
|
||||||
|
oop.inherits(FoldMode, BaseFoldMode);
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
this.getFoldWidgetRange = function(session, foldStyle, row) {
|
||||||
|
var range = this.indentationBlock(session, row);
|
||||||
|
if (range)
|
||||||
|
return range;
|
||||||
|
|
||||||
|
var re = /\S/;
|
||||||
|
var line = session.getLine(row);
|
||||||
|
var startLevel = line.search(re);
|
||||||
|
if (startLevel == -1 || line[startLevel] != "#")
|
||||||
|
return;
|
||||||
|
|
||||||
|
var startColumn = line.length;
|
||||||
|
var maxRow = session.getLength();
|
||||||
|
var startRow = row;
|
||||||
|
var endRow = row;
|
||||||
|
|
||||||
|
while (++row < maxRow) {
|
||||||
|
line = session.getLine(row);
|
||||||
|
var level = line.search(re);
|
||||||
|
|
||||||
|
if (level == -1)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (line[level] != "#")
|
||||||
|
break;
|
||||||
|
|
||||||
|
endRow = row;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (endRow > startRow) {
|
||||||
|
var endColumn = session.getLine(endRow).length;
|
||||||
|
return new Range(startRow, startColumn, endRow, endColumn);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// must return "" if there's no fold, to enable caching
|
||||||
|
this.getFoldWidget = function(session, foldStyle, row) {
|
||||||
|
var line = session.getLine(row);
|
||||||
|
var indent = line.search(/\S/);
|
||||||
|
var next = session.getLine(row + 1);
|
||||||
|
var prev = session.getLine(row - 1);
|
||||||
|
var prevIndent = prev.search(/\S/);
|
||||||
|
var nextIndent = next.search(/\S/);
|
||||||
|
|
||||||
|
if (indent == -1) {
|
||||||
|
session.foldWidgets[row - 1] = prevIndent!= -1 && prevIndent < nextIndent ? "start" : "";
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// documentation comments
|
||||||
|
if (prevIndent == -1) {
|
||||||
|
if (indent == nextIndent && line[indent] == "#" && next[indent] == "#") {
|
||||||
|
session.foldWidgets[row - 1] = "";
|
||||||
|
session.foldWidgets[row + 1] = "";
|
||||||
|
return "start";
|
||||||
|
}
|
||||||
|
} else if (prevIndent == indent && line[indent] == "#" && prev[indent] == "#") {
|
||||||
|
if (session.getLine(row - 2).search(/\S/) == -1) {
|
||||||
|
session.foldWidgets[row - 1] = "start";
|
||||||
|
session.foldWidgets[row + 1] = "";
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prevIndent!= -1 && prevIndent < indent)
|
||||||
|
session.foldWidgets[row - 1] = "start";
|
||||||
|
else
|
||||||
|
session.foldWidgets[row - 1] = "";
|
||||||
|
|
||||||
|
if (indent < nextIndent)
|
||||||
|
return "start";
|
||||||
|
else
|
||||||
|
return "";
|
||||||
|
};
|
||||||
|
|
||||||
|
}).call(FoldMode.prototype);
|
||||||
|
|
||||||
|
});
|
||||||
108
lib/ace/mode/folding/coffee_test.js
Normal file
108
lib/ace/mode/folding/coffee_test.js
Normal file
|
|
@ -0,0 +1,108 @@
|
||||||
|
/* ***** 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) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var CoffeeMode = require("../coffee").Mode;
|
||||||
|
var EditSession = require("../../edit_session").EditSession;
|
||||||
|
var assert = require("../../test/assertions");
|
||||||
|
function testFoldWidgets(array) {
|
||||||
|
var session = array.filter(function(_, i){return i % 2 == 1});
|
||||||
|
session = new EditSession(session);
|
||||||
|
var mode = new CoffeeMode();
|
||||||
|
session.setFoldStyle("markbeginend");
|
||||||
|
session.setMode(mode);
|
||||||
|
|
||||||
|
var widgets = array.filter(function(_, i){return i % 2 == 0});
|
||||||
|
widgets.forEach(function(w, i){
|
||||||
|
session.foldWidgets[i] = session.getFoldWidget(i);
|
||||||
|
})
|
||||||
|
widgets.forEach(function(w, i){
|
||||||
|
w = w.split(",");
|
||||||
|
var type = w[0] == ">" ? "start" : w[0] == "<" ? "end" : "";
|
||||||
|
assert.equal(session.foldWidgets[i], type);
|
||||||
|
if (!type)
|
||||||
|
return;
|
||||||
|
var range = session.getFoldWidgetRange(i);
|
||||||
|
if (!w[1]) {
|
||||||
|
assert.equal(range, null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
assert.equal(range.start.row, i);
|
||||||
|
assert.equal(range.end.row - range.start.row, parseInt(w[1]));
|
||||||
|
testColumn(w[2], range.start);
|
||||||
|
testColumn(w[3], range.end);
|
||||||
|
});
|
||||||
|
|
||||||
|
function testColumn(w, pos) {
|
||||||
|
if (!w)
|
||||||
|
return;
|
||||||
|
if (w == "l")
|
||||||
|
w = session.getLine(pos.row).length;
|
||||||
|
else
|
||||||
|
w = parseInt(w);
|
||||||
|
assert.equal(pos.column, w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
module.exports = {
|
||||||
|
"test: coffee script indentation based folding": function() {
|
||||||
|
testFoldWidgets([
|
||||||
|
'>,1,l,l', ' ## indented comment',
|
||||||
|
'', ' # ',
|
||||||
|
'', '',
|
||||||
|
'>,1,l,l', ' # plain comment',
|
||||||
|
'', ' # ',
|
||||||
|
'>,2', ' function (x)=>',
|
||||||
|
'', ' ',
|
||||||
|
'', ' x++',
|
||||||
|
'', ' ',
|
||||||
|
'', ' ',
|
||||||
|
'>,2', ' bar = ',
|
||||||
|
'', ' foo: 1',
|
||||||
|
'', ' baz: lighter'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
if (typeof module !== "undefined" && module === require.main)
|
||||||
|
require("asyncjs").test.testcase(module.exports).exec();
|
||||||
|
|
@ -64,19 +64,21 @@ var FoldMode = exports.FoldMode = function() {};
|
||||||
};
|
};
|
||||||
|
|
||||||
this.indentationBlock = function(session, row, column) {
|
this.indentationBlock = function(session, row, column) {
|
||||||
var re = /^\s*/;
|
var re = /\S/;
|
||||||
|
var line = session.getLine(row);
|
||||||
|
var startLevel = line.search(re);
|
||||||
|
if (startLevel == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var startColumn = column || line.length;
|
||||||
|
var maxRow = session.getLength();
|
||||||
var startRow = row;
|
var startRow = row;
|
||||||
var endRow = row;
|
var endRow = row;
|
||||||
var line = session.getLine(row);
|
|
||||||
var startColumn = column || line.length;
|
|
||||||
var startLevel = line.match(re)[0].length;
|
|
||||||
var maxRow = session.getLength()
|
|
||||||
|
|
||||||
while (++row < maxRow) {
|
while (++row < maxRow) {
|
||||||
line = session.getLine(row);
|
var level = session.getLine(row).search(re);
|
||||||
var level = line.match(re)[0].length;
|
|
||||||
|
|
||||||
if (level == line.length)
|
if (level == -1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (level <= startLevel)
|
if (level <= startLevel)
|
||||||
|
|
@ -91,9 +93,9 @@ var FoldMode = exports.FoldMode = function() {};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.openingBracketBlock = function(session, bracket, row, column, typeRe, allowBlankLine) {
|
this.openingBracketBlock = function(session, bracket, row, column, typeRe) {
|
||||||
var start = {row: row, column: column + 1};
|
var start = {row: row, column: column + 1};
|
||||||
var end = session.$findClosingBracket(bracket, start, typeRe, allowBlankLine);
|
var end = session.$findClosingBracket(bracket, start, typeRe);
|
||||||
if (!end)
|
if (!end)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -101,7 +103,7 @@ var FoldMode = exports.FoldMode = function() {};
|
||||||
if (fw == null)
|
if (fw == null)
|
||||||
fw = this.getFoldWidget(session, end.row);
|
fw = this.getFoldWidget(session, end.row);
|
||||||
|
|
||||||
if (fw == "start") {
|
if (fw == "start" && end.row > start.row) {
|
||||||
end.row --;
|
end.row --;
|
||||||
end.column = session.getLine(end.row).length;
|
end.column = session.getLine(end.row).length;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ var oop = require("../../lib/oop");
|
||||||
var BaseFoldMode = require("./fold_mode").FoldMode;
|
var BaseFoldMode = require("./fold_mode").FoldMode;
|
||||||
|
|
||||||
var FoldMode = exports.FoldMode = function(markers) {
|
var FoldMode = exports.FoldMode = function(markers) {
|
||||||
this.foldingStartMarker = new RegExp("(?:([\\[{])|(" + markers + "))(?:\\s*)(?:#.*)?$");
|
this.foldingStartMarker = new RegExp("([\\[{])(?:\\s*)$|(" + markers + ")(?:\\s*)(?:#.*)?$");
|
||||||
};
|
};
|
||||||
oop.inherits(FoldMode, BaseFoldMode);
|
oop.inherits(FoldMode, BaseFoldMode);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,11 +49,12 @@ module.exports = {
|
||||||
|
|
||||||
"test: bracket folding": function() {
|
"test: bracket folding": function() {
|
||||||
var session = new EditSession([
|
var session = new EditSession([
|
||||||
'[ #-',
|
'[ ',
|
||||||
'stuff',
|
'stuff',
|
||||||
']',
|
']',
|
||||||
'[ ',
|
'[ ',
|
||||||
'{ '
|
'{ ',
|
||||||
|
'[ #-',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var mode = new PythonMode();
|
var mode = new PythonMode();
|
||||||
|
|
@ -65,9 +66,11 @@ module.exports = {
|
||||||
assert.equal(session.getFoldWidget(2), "");
|
assert.equal(session.getFoldWidget(2), "");
|
||||||
assert.equal(session.getFoldWidget(3), "start");
|
assert.equal(session.getFoldWidget(3), "start");
|
||||||
assert.equal(session.getFoldWidget(4), "start");
|
assert.equal(session.getFoldWidget(4), "start");
|
||||||
|
assert.equal(session.getFoldWidget(5), "");
|
||||||
|
|
||||||
assert.range(session.getFoldWidgetRange(0), 0, 1, 2, 0);
|
assert.range(session.getFoldWidgetRange(0), 0, 1, 2, 0);
|
||||||
assert.equal(session.getFoldWidgetRange(3), null);
|
assert.equal(session.getFoldWidgetRange(3), null);
|
||||||
|
assert.equal(session.getFoldWidgetRange(5), null);
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: indentation folding": function() {
|
"test: indentation folding": function() {
|
||||||
|
|
|
||||||
|
|
@ -58,13 +58,10 @@ function GutterHandler(mouseHandler) {
|
||||||
var row = e.getDocumentPosition().row;
|
var row = e.getDocumentPosition().row;
|
||||||
var selection = editor.session.selection;
|
var selection = editor.session.selection;
|
||||||
|
|
||||||
if (e.getShiftKey()) {
|
if (e.getShiftKey())
|
||||||
selection.selectTo(row, 0);
|
selection.selectTo(row, 0);
|
||||||
} else {
|
else
|
||||||
selection.moveCursorTo(row, 0);
|
mouseHandler.$clickSelection = editor.selection.getLineRange(row);
|
||||||
selection.selectLine();
|
|
||||||
mouseHandler.$clickSelection = selection.getRange();
|
|
||||||
}
|
|
||||||
|
|
||||||
mouseHandler.captureMouse(e, "selectByLines");
|
mouseHandler.captureMouse(e, "selectByLines");
|
||||||
return e.preventDefault();
|
return e.preventDefault();
|
||||||
|
|
|
||||||
|
|
@ -163,9 +163,11 @@ function DefaultHandlers(mouseHandler) {
|
||||||
|
|
||||||
if (cmpStart == -1 && cmpEnd <= 0) {
|
if (cmpStart == -1 && cmpEnd <= 0) {
|
||||||
anchor = this.$clickSelection.end;
|
anchor = this.$clickSelection.end;
|
||||||
|
if (range.end.row != cursor.row || range.end.column != cursor.column)
|
||||||
cursor = range.start;
|
cursor = range.start;
|
||||||
} else if (cmpEnd == 1 && cmpStart >= 0) {
|
} else if (cmpEnd == 1 && cmpStart >= 0) {
|
||||||
anchor = this.$clickSelection.start;
|
anchor = this.$clickSelection.start;
|
||||||
|
if (range.start.row != cursor.row || range.start.column != cursor.column)
|
||||||
cursor = range.end;
|
cursor = range.end;
|
||||||
} else if (cmpStart == -1 && cmpEnd == 1) {
|
} else if (cmpStart == -1 && cmpEnd == 1) {
|
||||||
cursor = range.end;
|
cursor = range.end;
|
||||||
|
|
@ -296,10 +298,7 @@ function DefaultHandlers(mouseHandler) {
|
||||||
var editor = this.editor;
|
var editor = this.editor;
|
||||||
|
|
||||||
this.setState("selectByLines");
|
this.setState("selectByLines");
|
||||||
|
this.$clickSelection = editor.selection.getLineRange(pos.row);
|
||||||
editor.moveCursorToPosition(pos);
|
|
||||||
editor.selection.selectLine();
|
|
||||||
this.$clickSelection = editor.getSelectionRange();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.onQuadClick = function(ev) {
|
this.onQuadClick = function(ev) {
|
||||||
|
|
|
||||||
|
|
@ -41,17 +41,17 @@
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
var globalRequire = require;
|
var globalRequire = typeof require != "undefined" && require;
|
||||||
|
|
||||||
define(function (require, exports, module) {
|
define(function (require, exports, module) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
exports.load = function (name, req, onLoad, config) {
|
exports.load = function (name, req, onLoad, config) {
|
||||||
if (req.isBrowser)
|
|
||||||
require("ace/lib/net").get(req.toUrl(name), onLoad);
|
|
||||||
else
|
|
||||||
//Using special require.nodeRequire, something added by r.js.
|
//Using special require.nodeRequire, something added by r.js.
|
||||||
onLoad(globalRequire.nodeRequire('fs').readFileSync(req.toUrl(name), 'utf8'));
|
if (globalRequire && globalRequire.nodeRequire)
|
||||||
|
onLoad(('fs').readFileSync(req.toUrl(name), 'utf8'));
|
||||||
|
else
|
||||||
|
require("ace/lib/net").get(req.toUrl(name), onLoad);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ var testNames = [
|
||||||
"ace/mode/folding/html_test",
|
"ace/mode/folding/html_test",
|
||||||
"ace/mode/folding/pythonic_test",
|
"ace/mode/folding/pythonic_test",
|
||||||
"ace/mode/folding/xml_test",
|
"ace/mode/folding/xml_test",
|
||||||
|
"ace/mode/folding/coffee_test",
|
||||||
"ace/multi_select_test",
|
"ace/multi_select_test",
|
||||||
"ace/range_test",
|
"ace/range_test",
|
||||||
"ace/range_list_test",
|
"ace/range_list_test",
|
||||||
|
|
|
||||||
|
|
@ -321,7 +321,7 @@ var VirtualRenderer = function(container, theme) {
|
||||||
var gutterWidth = this.showGutter ? this.$gutter.offsetWidth : 0;
|
var gutterWidth = this.showGutter ? this.$gutter.offsetWidth : 0;
|
||||||
this.scroller.style.left = gutterWidth + "px";
|
this.scroller.style.left = gutterWidth + "px";
|
||||||
size.scrollerWidth = Math.max(0, width - gutterWidth - this.scrollBar.getWidth());
|
size.scrollerWidth = Math.max(0, width - gutterWidth - this.scrollBar.getWidth());
|
||||||
//this.scroller.style.width = size.scrollerWidth + "px";
|
this.scroller.style.right = this.scrollBar.getWidth() + "px";
|
||||||
|
|
||||||
if (this.session.getUseWrapMode() && this.adjustWrapLimit() || force)
|
if (this.session.getUseWrapMode() && this.adjustWrapLimit() || force)
|
||||||
changes = changes | this.CHANGE_FULL;
|
changes = changes | this.CHANGE_FULL;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue