Permalink
Browse files

Merge pull request #819 from ajaxorg/misc

foldmode improvements and autosizing markers
  • Loading branch information...
2 parents 3a19dc5 + 8fbe921 commit cc0508b9228986553ed22229d72134b5678e38ad @nightwing nightwing committed Jul 2, 2012
View
@@ -97,10 +97,9 @@ exports.init = function() {
}
}
- var m = src.match(/^(?:(.*\/)ace\.js)(?:\?|$)/);
- if (m) {
- scriptUrl = m[1] || m[2];
- }
+ var m = src.match(/^(.*)\/ace(\-\w+)?\.js(\?|$)/);
+ if (m)
+ scriptUrl = m[1];
}
if (scriptUrl) {
View
@@ -8,7 +8,6 @@
.ace_scroller {
position: absolute;
overflow: hidden;
- width : 100%;
}
.ace_content {
@@ -94,7 +94,7 @@ function BracketMatch() {
var match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
if (!match) {
chr = line.charAt(pos.column);
- pos.column++;
+ pos = {row: pos.row, column: pos.column + 1};
match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
before = false;
}
@@ -123,9 +123,6 @@ function BracketMatch() {
range.cursor = range.start;
}
- if (!before)
- pos.column--;
-
return range;
};
@@ -194,7 +191,7 @@ function BracketMatch() {
return null;
};
- this.$findClosingBracket = function(bracket, position, typeRe, allowBlankLine) {
+ this.$findClosingBracket = function(bracket, position, typeRe) {
var closingBracket = this.$brackets[bracket];
var depth = 1;
@@ -239,12 +236,6 @@ function BracketMatch() {
// whose type matches typeRe
do {
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));
if (token == null)
View
@@ -73,7 +73,7 @@ var Marker = function(parentEl) {
var html = [];
- for ( var key in this.markers) {
+ for (var key in this.markers) {
var marker = this.markers[key];
if (!marker.range) {
@@ -140,29 +140,25 @@ var Marker = function(parentEl) {
}
};
- // Draws a multi line marker, where lines span the full width
- this.drawMultiLineMarker = function(stringBuilder, range, clazz, layerConfig, type) {
+ // Draws a multi line marker, where lines span the full width
+ this.drawMultiLineMarker = function(stringBuilder, range, clazz, config, type) {
var padding = type === "background" ? 0 : this.$padding;
- var layerWidth = layerConfig.width + 2 * this.$padding - padding;
// from selection start to the end of the line
- var height = layerConfig.lineHeight;
- var width = Math.round(layerWidth - (range.start.column * layerConfig.characterWidth));
- var top = this.$getTop(range.start.row, layerConfig);
- var left = Math.round(
- padding + range.start.column * layerConfig.characterWidth
- );
+ var height = config.lineHeight;
+ var top = this.$getTop(range.start.row, config);
+ var left = Math.round(padding + range.start.column * config.characterWidth);
stringBuilder.push(
"<div class='", clazz, " start' style='",
"height:", height, "px;",
- "width:", width, "px;",
+ "right:0;",
"top:", top, "px;",
"left:", left, "px;'></div>"
);
// from start of the last line to the selection end
- top = this.$getTop(range.end.row, layerConfig);
- width = Math.round(range.end.column * layerConfig.characterWidth);
+ top = this.$getTop(range.end.row, config);
+ var width = Math.round(range.end.column * config.characterWidth);
stringBuilder.push(
"<div class='", clazz, "' style='",
@@ -173,15 +169,15 @@ var Marker = function(parentEl) {
);
// 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)
return;
- top = this.$getTop(range.start.row + 1, layerConfig);
+ top = this.$getTop(range.start.row + 1, config);
stringBuilder.push(
"<div class='", clazz, "' style='",
"height:", height, "px;",
- "width:", layerWidth, "px;",
+ "right:0;",
"top:", top, "px;",
"left:", padding, "px;'></div>"
);
View
@@ -131,7 +131,7 @@ var Text = function(parentEl) {
container.appendChild(measureNode);
}
}
-
+
// Size and width can be null if the editor is not visible or
// detached from the document
if (!this.element.offsetWidth)
@@ -153,7 +153,7 @@ var Text = function(parentEl) {
return null;
return size;
- }
+ }
: function() {
if (!this.$measureNode) {
var measureNode = this.$measureNode = dom.createElement("div");
@@ -178,7 +178,7 @@ var Text = function(parentEl) {
container.appendChild(measureNode);
}
-
+
var rect = this.$measureNode.getBoundingClientRect();
var size = {
@@ -382,7 +382,7 @@ var Text = function(parentEl) {
"lparen": true
};
- this.$renderToken = function(stringBuilder, screenColumn, token, value) {
+ this.$renderToken = function(stringBuilder, screenColumn, token, value) {
var self = this;
var replaceReg = /\t|&|<|( +)|([\u0000-\u0019\u00a0\u1680\u180E\u2000-\u200b\u2028\u2029\u202F\u205F\u3000\uFEFF])|[\u1100-\u115F\u11A3-\u11A7\u11FA-\u11FF\u2329-\u232A\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u2FF0-\u2FFB\u3000-\u303E\u3041-\u3096\u3099-\u30FF\u3105-\u312D\u3131-\u318E\u3190-\u31BA\u31C0-\u31E3\u31F0-\u321E\u3220-\u3247\u3250-\u32FE\u3300-\u4DBF\u4E00-\uA48C\uA490-\uA4C6\uA960-\uA97C\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFAFF\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE66\uFE68-\uFE6B\uFF01-\uFF60\uFFE0-\uFFE6]/g;
var replaceFunc = function(c, a, b, tabIdx, idx4) {
@@ -447,7 +447,7 @@ var Text = function(parentEl) {
"'>"
);
}
-
+
for (var i = 0; i < tokens.length; i++) {
var token = tokens[i];
var value = token.value;
@@ -461,12 +461,12 @@ var Text = function(parentEl) {
else {
while (chars + value.length >= splitChars) {
screenColumn = self.$renderToken(
- stringBuilder, screenColumn,
+ stringBuilder, screenColumn,
token, value.substring(0, splitChars - chars)
);
value = value.substring(splitChars - chars);
chars = splitChars;
-
+
if (!onlyContents) {
stringBuilder.push("</div>",
"<div class='ace_line' style='height:",
@@ -510,26 +510,24 @@ var Text = function(parentEl) {
};
this.$renderFoldLine = function(stringBuilder, row, tokens, onlyContents) {
- var session = this.session,
- foldLine = session.getFoldLine(row),
- renderTokens = [];
+ var session = this.session;
+ var foldLine = session.getFoldLine(row);
+ var renderTokens = [];
function addTokens(tokens, from, to) {
var idx = 0, col = 0;
while ((col + tokens[idx].value.length) < from) {
col += tokens[idx].value.length;
idx++;
- if (idx == tokens.length) {
+ if (idx == tokens.length)
return;
- }
}
if (col != from) {
var value = tokens[idx].value.substring(from - col);
// 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);
- }
renderTokens.push({
type: tokens[idx].type,
@@ -540,43 +538,43 @@ var Text = function(parentEl) {
idx += 1;
}
- while (col < to) {
+ while (col < to && idx < tokens.length) {
var value = tokens[idx].value;
if (value.length + col > to) {
- value = value.substring(0, to - col);
- }
- renderTokens.push({
- type: tokens[idx].type,
- value: value
- });
+ renderTokens.push({
+ type: tokens[idx].type,
+ value: value.substring(0, to - col)
+ });
+ } else
+ renderTokens.push(tokens[idx]);
col += value.length;
idx += 1;
}
}
foldLine.walk(function(placeholder, row, column, lastColumn, isNewRow) {
if (placeholder) {
- renderTokens.push({
+ renderTokens.push({
type: "fold",
value: placeholder
});
} else {
if (isNewRow)
- tokens = this.session.getTokens(row);
+ tokens = session.getTokens(row);
if (tokens.length)
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!
- var splits = this.session.$useWrapMode?this.session.$wrapData[row]:null;
+ // splits for foldline are stored at its' first row
+ var splits = this.session.$useWrapMode ? this.session.$wrapData[row] : null;
this.$renderLineCore(stringBuilder, row, renderTokens, splits, onlyContents);
};
-
+
this.$useLineGroups = function() {
// For the updateLines function to work correctly, it's important that the
- // child nodes of this.element correspond on a 1-to-1 basis to rows in the
+ // child nodes of this.element correspond on a 1-to-1 basis to rows in the
// document (as distinct from lines on the screen). For sessions that are
// wrapped, this means we need to add a layer to the node hierarchy (tagged
// with the class name ace_line_group).
View
@@ -56,18 +56,6 @@ oop.inherits(Mode, TextMode);
this.getNextLineIndent = function(state, line, tab) {
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;
};
View
@@ -41,7 +41,7 @@ define(function(require, exports, module) {
var Tokenizer = require("../tokenizer").Tokenizer;
var Rules = require("./coffee_highlight_rules").CoffeeHighlightRules;
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 TextMode = require("./text").Mode;
var WorkerClient = require("../worker/worker_client").WorkerClient;
@@ -153,7 +153,7 @@ define(function(require, exports, module) {
regex : "\\?|\\:|\\,|\\."
}, {
token : "keyword.operator",
- regex : "(?:[\\-=]>|[-+*/%<>&|^!?=]=|>>>=?|\\-\\-|\\+\\+|::|&&=|\\|\\|=|<<=|>>=|\\?\\.|\\.{2,3}|\\!)"
+ regex : "(?:[\\-=]>|[-+*/%<>&|^!?=]=|>>>=?|\\-\\-|\\+\\+|::|&&=|\\|\\|=|<<=|>>=|\\?\\.|\\.{2,3}|[!*+-=><])"
}, {
token : "paren.lparen",
regex : "[({[]"
@@ -48,46 +48,32 @@ oop.inherits(FoldMode, BaseFoldMode);
(function() {
- this.foldingStartMarker = /[a-zA-Z](:)\s*$/;
- this.foldingStopMarker = /^(\s*)$/;
+ this.foldingStartMarker = /^(\w.*\:|Searching for.*)$/;
+ this.foldingStopMarker = /^(\s+|Found.*)$/;
this.getFoldWidgetRange = function(session, foldStyle, row) {
var line = session.getLine(row);
- var match = line.match(this.foldingStartMarker);
- if (match) {
- var i = match.index;
+ var level1 = /^(Found.*|Searching for.*)$/;
+ var level2 = /^(\w.*\:|\s*)$/;
+ var re = level1.test(line) ? level1 : level2;
- if (match[1])
- return this.openingBracketBlock(session, match[1], row, i, false, true);
+ if (this.foldingStartMarker.test(line)) {
+ for (var i = row + 1, l = session.getLength(); i < l; i++) {
+ if (re.test(session.getLine(i)))
+ break;
+ }
- var range = session.getCommentFoldRange(row, i + match[0].length);
- range.end.column -= 2;
- return range;
+ return new Range(row, line.length, i, 0);
}
- if (foldStyle !== "markbeginend")
- 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;
+ if (this.foldingStopMarker.test(line)) {
+ for (var i = row - 1; i >= 0; i--) {
+ line = session.getLine(i);
+ if (re.test(line))
+ break;
}
- var end = {row: row, column: i};
- var start = session.$findOpeningBracket(match[1], end);
-
- if (!start)
- return;
-
- start.column++;
- end.column--;
-
- return Range.fromPoints(start, end);
+ return new Range(i, line.length, row, 0);
}
};
Oops, something went wrong.

0 comments on commit cc0508b

Please sign in to comment.