Permalink
Browse files

Merge pull request #819 from ajaxorg/misc

foldmode improvements and autosizing markers
  • Loading branch information...
nightwing committed Jul 2, 2012
2 parents 3a19dc5 + 8fbe921 commit cc0508b9228986553ed22229d72134b5678e38ad
View
@@ -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) {
View
@@ -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)
View
@@ -73,7 +73,7 @@ var Marker = function(parentEl) {
var html = []; var html = [];
for ( var key in this.markers) { for (var key in this.markers) {
var marker = this.markers[key]; var marker = this.markers[key];
if (!marker.range) { if (!marker.range) {
@@ -140,29 +140,25 @@ 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>"
); );
View
@@ -131,7 +131,7 @@ var Text = function(parentEl) {
container.appendChild(measureNode); container.appendChild(measureNode);
} }
} }
// Size and width can be null if the editor is not visible or // Size and width can be null if the editor is not visible or
// detached from the document // detached from the document
if (!this.element.offsetWidth) if (!this.element.offsetWidth)
@@ -153,7 +153,7 @@ var Text = function(parentEl) {
return null; return null;
return size; return size;
} }
: function() { : function() {
if (!this.$measureNode) { if (!this.$measureNode) {
var measureNode = this.$measureNode = dom.createElement("div"); var measureNode = this.$measureNode = dom.createElement("div");
@@ -178,7 +178,7 @@ var Text = function(parentEl) {
container.appendChild(measureNode); container.appendChild(measureNode);
} }
var rect = this.$measureNode.getBoundingClientRect(); var rect = this.$measureNode.getBoundingClientRect();
var size = { var size = {
@@ -382,7 +382,7 @@ var Text = function(parentEl) {
"lparen": true "lparen": true
}; };
this.$renderToken = function(stringBuilder, screenColumn, token, value) { this.$renderToken = function(stringBuilder, screenColumn, token, value) {
var self = this; 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 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) { var replaceFunc = function(c, a, b, tabIdx, idx4) {
@@ -447,7 +447,7 @@ var Text = function(parentEl) {
"'>" "'>"
); );
} }
for (var i = 0; i < tokens.length; i++) { for (var i = 0; i < tokens.length; i++) {
var token = tokens[i]; var token = tokens[i];
var value = token.value; var value = token.value;
@@ -461,12 +461,12 @@ var Text = function(parentEl) {
else { else {
while (chars + value.length >= splitChars) { while (chars + value.length >= splitChars) {
screenColumn = self.$renderToken( screenColumn = self.$renderToken(
stringBuilder, screenColumn, stringBuilder, screenColumn,
token, value.substring(0, splitChars - chars) token, value.substring(0, splitChars - chars)
); );
value = value.substring(splitChars - chars); value = value.substring(splitChars - chars);
chars = splitChars; chars = splitChars;
if (!onlyContents) { if (!onlyContents) {
stringBuilder.push("</div>", stringBuilder.push("</div>",
"<div class='ace_line' style='height:", "<div class='ace_line' style='height:",
@@ -510,26 +510,24 @@ 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;
while ((col + tokens[idx].value.length) < from) { while ((col + tokens[idx].value.length) < from) {
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,43 +538,43 @@ 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({
} type: tokens[idx].type,
renderTokens.push({ value: value.substring(0, to - col)
type: tokens[idx].type, });
value: value } else
}); renderTokens.push(tokens[idx]);
col += value.length; col += value.length;
idx += 1; idx += 1;
} }
} }
foldLine.walk(function(placeholder, row, column, lastColumn, isNewRow) { foldLine.walk(function(placeholder, row, column, lastColumn, isNewRow) {
if (placeholder) { if (placeholder) {
renderTokens.push({ renderTokens.push({
type: "fold", type: "fold",
value: placeholder value: placeholder
}); });
} 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);
}; };
this.$useLineGroups = function() { this.$useLineGroups = function() {
// For the updateLines function to work correctly, it's important that the // 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 // 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 // wrapped, this means we need to add a layer to the node hierarchy (tagged
// with the class name ace_line_group). // with the class name ace_line_group).
View
@@ -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;
}; };
View
@@ -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)))
break;
}
var range = session.getCommentFoldRange(row, i + match[0].length); return new Range(row, line.length, i, 0);
range.end.column -= 2;
return range;
} }
if (foldStyle !== "markbeginend") if (this.foldingStopMarker.test(line)) {
return; for (var i = row - 1; i >= 0; i--) {
line = session.getLine(i);
var match = line.match(this.foldingStopMarker); if (re.test(line))
if (match) { break;
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}; return new Range(i, line.length, row, 0);
var start = session.$findOpeningBracket(match[1], end);
if (!start)
return;
start.column++;
end.column--;
return Range.fromPoints(start, end);
} }
}; };
Oops, something went wrong.

0 comments on commit cc0508b

Please sign in to comment.