You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2013/10/30 14:43:39 UTC
[45/52] [partial] Remove unneeded ace files and codemirror
http://git-wip-us.apache.org/repos/asf/couchdb/blob/5b8fb9c3/src/fauxton/assets/js/libs/ace/edit_session/bracket_match.js
----------------------------------------------------------------------
diff --git a/src/fauxton/assets/js/libs/ace/edit_session/bracket_match.js b/src/fauxton/assets/js/libs/ace/edit_session/bracket_match.js
deleted file mode 100644
index 825f692..0000000
--- a/src/fauxton/assets/js/libs/ace/edit_session/bracket_match.js
+++ /dev/null
@@ -1,219 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Distributed under the BSD license:
- *
- * Copyright (c) 2010, Ajax.org B.V.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of Ajax.org B.V. nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * ***** END LICENSE BLOCK ***** */
-
-define(function(require, exports, module) {
-"use strict";
-
-var TokenIterator = require("../token_iterator").TokenIterator;
-var Range = require("../range").Range;
-
-
-function BracketMatch() {
-
- this.findMatchingBracket = function(position, chr) {
- if (position.column == 0) return null;
-
- var charBeforeCursor = chr || this.getLine(position.row).charAt(position.column-1);
- if (charBeforeCursor == "") return null;
-
- var match = charBeforeCursor.match(/([\(\[\{])|([\)\]\}])/);
- if (!match)
- return null;
-
- if (match[1])
- return this.$findClosingBracket(match[1], position);
- else
- return this.$findOpeningBracket(match[2], position);
- };
-
- this.getBracketRange = function(pos) {
- var line = this.getLine(pos.row);
- var before = true, range;
-
- var chr = line.charAt(pos.column-1);
- var match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
- if (!match) {
- chr = line.charAt(pos.column);
- pos = {row: pos.row, column: pos.column + 1};
- match = chr && chr.match(/([\(\[\{])|([\)\]\}])/);
- before = false;
- }
- if (!match)
- return null;
-
- if (match[1]) {
- var bracketPos = this.$findClosingBracket(match[1], pos);
- if (!bracketPos)
- return null;
- range = Range.fromPoints(pos, bracketPos);
- if (!before) {
- range.end.column++;
- range.start.column--;
- }
- range.cursor = range.end;
- } else {
- var bracketPos = this.$findOpeningBracket(match[2], pos);
- if (!bracketPos)
- return null;
- range = Range.fromPoints(bracketPos, pos);
- if (!before) {
- range.start.column++;
- range.end.column--;
- }
- range.cursor = range.start;
- }
-
- return range;
- };
-
- this.$brackets = {
- ")": "(",
- "(": ")",
- "]": "[",
- "[": "]",
- "{": "}",
- "}": "{"
- };
-
- this.$findOpeningBracket = function(bracket, position, typeRe) {
- var openBracket = this.$brackets[bracket];
- var depth = 1;
-
- var iterator = new TokenIterator(this, position.row, position.column);
- var token = iterator.getCurrentToken();
- if (!token)
- token = iterator.stepForward();
- if (!token)
- return;
-
- if (!typeRe){
- typeRe = new RegExp(
- "(\\.?" +
- token.type.replace(".", "\\.").replace("rparen", ".paren")
- + ")+"
- );
- }
-
- // Start searching in token, just before the character at position.column
- var valueIndex = position.column - iterator.getCurrentTokenColumn() - 2;
- var value = token.value;
-
- while (true) {
-
- while (valueIndex >= 0) {
- var chr = value.charAt(valueIndex);
- if (chr == openBracket) {
- depth -= 1;
- if (depth == 0) {
- return {row: iterator.getCurrentTokenRow(),
- column: valueIndex + iterator.getCurrentTokenColumn()};
- }
- }
- else if (chr == bracket) {
- depth += 1;
- }
- valueIndex -= 1;
- }
-
- // Scan backward through the document, looking for the next token
- // whose type matches typeRe
- do {
- token = iterator.stepBackward();
- } while (token && !typeRe.test(token.type));
-
- if (token == null)
- break;
-
- value = token.value;
- valueIndex = value.length - 1;
- }
-
- return null;
- };
-
- this.$findClosingBracket = function(bracket, position, typeRe) {
- var closingBracket = this.$brackets[bracket];
- var depth = 1;
-
- var iterator = new TokenIterator(this, position.row, position.column);
- var token = iterator.getCurrentToken();
- if (!token)
- token = iterator.stepForward();
- if (!token)
- return;
-
- if (!typeRe){
- typeRe = new RegExp(
- "(\\.?" +
- token.type.replace(".", "\\.").replace("lparen", ".paren")
- + ")+"
- );
- }
-
- // Start searching in token, after the character at position.column
- var valueIndex = position.column - iterator.getCurrentTokenColumn();
-
- while (true) {
-
- var value = token.value;
- var valueLength = value.length;
- while (valueIndex < valueLength) {
- var chr = value.charAt(valueIndex);
- if (chr == closingBracket) {
- depth -= 1;
- if (depth == 0) {
- return {row: iterator.getCurrentTokenRow(),
- column: valueIndex + iterator.getCurrentTokenColumn()};
- }
- }
- else if (chr == bracket) {
- depth += 1;
- }
- valueIndex += 1;
- }
-
- // Scan forward through the document, looking for the next token
- // whose type matches typeRe
- do {
- token = iterator.stepForward();
- } while (token && !typeRe.test(token.type));
-
- if (token == null)
- break;
-
- valueIndex = 0;
- }
-
- return null;
- };
-}
-exports.BracketMatch = BracketMatch;
-
-});
http://git-wip-us.apache.org/repos/asf/couchdb/blob/5b8fb9c3/src/fauxton/assets/js/libs/ace/edit_session/fold.js
----------------------------------------------------------------------
diff --git a/src/fauxton/assets/js/libs/ace/edit_session/fold.js b/src/fauxton/assets/js/libs/ace/edit_session/fold.js
deleted file mode 100644
index 232101b..0000000
--- a/src/fauxton/assets/js/libs/ace/edit_session/fold.js
+++ /dev/null
@@ -1,140 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Distributed under the BSD license:
- *
- * Copyright (c) 2010, Ajax.org B.V.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of Ajax.org B.V. nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * ***** END LICENSE BLOCK ***** */
-
-define(function(require, exports, module) {
-"use strict";
-
-var Range = require("../range").Range;
-var RangeList = require("../range_list").RangeList;
-var oop = require("../lib/oop")
-/*
- * Simple fold-data struct.
- **/
-var Fold = exports.Fold = function(range, placeholder) {
- this.foldLine = null;
- this.placeholder = placeholder;
- this.range = range;
- this.start = range.start;
- this.end = range.end;
-
- this.sameRow = range.start.row == range.end.row;
- this.subFolds = this.ranges = [];
-};
-
-oop.inherits(Fold, RangeList);
-
-(function() {
-
- this.toString = function() {
- return '"' + this.placeholder + '" ' + this.range.toString();
- };
-
- this.setFoldLine = function(foldLine) {
- this.foldLine = foldLine;
- this.subFolds.forEach(function(fold) {
- fold.setFoldLine(foldLine);
- });
- };
-
- this.clone = function() {
- var range = this.range.clone();
- var fold = new Fold(range, this.placeholder);
- this.subFolds.forEach(function(subFold) {
- fold.subFolds.push(subFold.clone());
- });
- fold.collapseChildren = this.collapseChildren;
- return fold;
- };
-
- this.addSubFold = function(fold) {
- if (this.range.isEqual(fold))
- return;
-
- if (!this.range.containsRange(fold))
- throw new Error("A fold can't intersect already existing fold" + fold.range + this.range);
-
- // transform fold to local coordinates
- consumeRange(fold, this.start);
-
- var row = fold.start.row, column = fold.start.column;
- for (var i = 0, cmp = -1; i < this.subFolds.length; i++) {
- cmp = this.subFolds[i].range.compare(row, column);
- if (cmp != 1)
- break;
- }
- var afterStart = this.subFolds[i];
-
- if (cmp == 0)
- return afterStart.addSubFold(fold);
-
- // cmp == -1
- var row = fold.range.end.row, column = fold.range.end.column;
- for (var j = i, cmp = -1; j < this.subFolds.length; j++) {
- cmp = this.subFolds[j].range.compare(row, column);
- if (cmp != 1)
- break;
- }
- var afterEnd = this.subFolds[j];
-
- if (cmp == 0)
- throw new Error("A fold can't intersect already existing fold" + fold.range + this.range);
-
- var consumedFolds = this.subFolds.splice(i, j - i, fold);
- fold.setFoldLine(this.foldLine);
-
- return fold;
- };
-
- this.restoreRange = function(range) {
- return restoreRange(range, this.start);
- };
-
-}).call(Fold.prototype);
-
-function consumePoint(point, anchor) {
- point.row -= anchor.row;
- if (point.row == 0)
- point.column -= anchor.column;
-}
-function consumeRange(range, anchor) {
- consumePoint(range.start, anchor);
- consumePoint(range.end, anchor);
-}
-function restorePoint(point, anchor) {
- if (point.row == 0)
- point.column += anchor.column;
- point.row += anchor.row;
-}
-function restoreRange(range, anchor) {
- restorePoint(range.start, anchor);
- restorePoint(range.end, anchor);
-}
-
-});
http://git-wip-us.apache.org/repos/asf/couchdb/blob/5b8fb9c3/src/fauxton/assets/js/libs/ace/edit_session/fold_line.js
----------------------------------------------------------------------
diff --git a/src/fauxton/assets/js/libs/ace/edit_session/fold_line.js b/src/fauxton/assets/js/libs/ace/edit_session/fold_line.js
deleted file mode 100644
index 0218195..0000000
--- a/src/fauxton/assets/js/libs/ace/edit_session/fold_line.js
+++ /dev/null
@@ -1,268 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Distributed under the BSD license:
- *
- * Copyright (c) 2010, Ajax.org B.V.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of Ajax.org B.V. nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * ***** END LICENSE BLOCK ***** */
-
-define(function(require, exports, module) {
-"use strict";
-
-var Range = require("../range").Range;
-
-/*
- * If an array is passed in, the folds are expected to be sorted already.
- */
-function FoldLine(foldData, folds) {
- this.foldData = foldData;
- if (Array.isArray(folds)) {
- this.folds = folds;
- } else {
- folds = this.folds = [ folds ];
- }
-
- var last = folds[folds.length - 1]
- this.range = new Range(folds[0].start.row, folds[0].start.column,
- last.end.row, last.end.column);
- this.start = this.range.start;
- this.end = this.range.end;
-
- this.folds.forEach(function(fold) {
- fold.setFoldLine(this);
- }, this);
-}
-
-(function() {
- /*
- * Note: This doesn't update wrapData!
- */
- this.shiftRow = function(shift) {
- this.start.row += shift;
- this.end.row += shift;
- this.folds.forEach(function(fold) {
- fold.start.row += shift;
- fold.end.row += shift;
- });
- }
-
- this.addFold = function(fold) {
- if (fold.sameRow) {
- if (fold.start.row < this.startRow || fold.endRow > this.endRow) {
- throw new Error("Can't add a fold to this FoldLine as it has no connection");
- }
- this.folds.push(fold);
- this.folds.sort(function(a, b) {
- return -a.range.compareEnd(b.start.row, b.start.column);
- });
- if (this.range.compareEnd(fold.start.row, fold.start.column) > 0) {
- this.end.row = fold.end.row;
- this.end.column = fold.end.column;
- } else if (this.range.compareStart(fold.end.row, fold.end.column) < 0) {
- this.start.row = fold.start.row;
- this.start.column = fold.start.column;
- }
- } else if (fold.start.row == this.end.row) {
- this.folds.push(fold);
- this.end.row = fold.end.row;
- this.end.column = fold.end.column;
- } else if (fold.end.row == this.start.row) {
- this.folds.unshift(fold);
- this.start.row = fold.start.row;
- this.start.column = fold.start.column;
- } else {
- throw new Error("Trying to add fold to FoldRow that doesn't have a matching row");
- }
- fold.foldLine = this;
- }
-
- this.containsRow = function(row) {
- return row >= this.start.row && row <= this.end.row;
- }
-
- this.walk = function(callback, endRow, endColumn) {
- var lastEnd = 0,
- folds = this.folds,
- fold,
- comp, stop, isNewRow = true;
-
- if (endRow == null) {
- endRow = this.end.row;
- endColumn = this.end.column;
- }
-
- for (var i = 0; i < folds.length; i++) {
- fold = folds[i];
-
- comp = fold.range.compareStart(endRow, endColumn);
- // This fold is after the endRow/Column.
- if (comp == -1) {
- callback(null, endRow, endColumn, lastEnd, isNewRow);
- return;
- }
-
- stop = callback(null, fold.start.row, fold.start.column, lastEnd, isNewRow);
- stop = !stop && callback(fold.placeholder, fold.start.row, fold.start.column, lastEnd);
-
- // If the user requested to stop the walk or endRow/endColumn is
- // inside of this fold (comp == 0), then end here.
- if (stop || comp == 0) {
- return;
- }
-
- // Note the new lastEnd might not be on the same line. However,
- // it's the callback's job to recognize this.
- isNewRow = !fold.sameRow;
- lastEnd = fold.end.column;
- }
- callback(null, endRow, endColumn, lastEnd, isNewRow);
- }
-
- this.getNextFoldTo = function(row, column) {
- var fold, cmp;
- for (var i = 0; i < this.folds.length; i++) {
- fold = this.folds[i];
- cmp = fold.range.compareEnd(row, column);
- if (cmp == -1) {
- return {
- fold: fold,
- kind: "after"
- };
- } else if (cmp == 0) {
- return {
- fold: fold,
- kind: "inside"
- }
- }
- }
- return null;
- }
-
- this.addRemoveChars = function(row, column, len) {
- var ret = this.getNextFoldTo(row, column),
- fold, folds;
- if (ret) {
- fold = ret.fold;
- if (ret.kind == "inside"
- && fold.start.column != column
- && fold.start.row != row)
- {
- //throwing here breaks whole editor
- //TODO: properly handle this
- window.console && window.console.log(row, column, fold);
- } else if (fold.start.row == row) {
- folds = this.folds;
- var i = folds.indexOf(fold);
- if (i == 0) {
- this.start.column += len;
- }
- for (i; i < folds.length; i++) {
- fold = folds[i];
- fold.start.column += len;
- if (!fold.sameRow) {
- return;
- }
- fold.end.column += len;
- }
- this.end.column += len;
- }
- }
- }
-
- this.split = function(row, column) {
- var fold = this.getNextFoldTo(row, column).fold;
- var folds = this.folds;
- var foldData = this.foldData;
-
- if (!fold)
- return null;
-
- var i = folds.indexOf(fold);
- var foldBefore = folds[i - 1];
- this.end.row = foldBefore.end.row;
- this.end.column = foldBefore.end.column;
-
- // Remove the folds after row/column and create a new FoldLine
- // containing these removed folds.
- folds = folds.splice(i, folds.length - i);
-
- var newFoldLine = new FoldLine(foldData, folds);
- foldData.splice(foldData.indexOf(this) + 1, 0, newFoldLine);
- return newFoldLine;
- }
-
- this.merge = function(foldLineNext) {
- var folds = foldLineNext.folds;
- for (var i = 0; i < folds.length; i++) {
- this.addFold(folds[i]);
- }
- // Remove the foldLineNext - no longer needed, as
- // it's merged now with foldLineNext.
- var foldData = this.foldData;
- foldData.splice(foldData.indexOf(foldLineNext), 1);
- }
-
- this.toString = function() {
- var ret = [this.range.toString() + ": [" ];
-
- this.folds.forEach(function(fold) {
- ret.push(" " + fold.toString());
- });
- ret.push("]")
- return ret.join("\n");
- }
-
- this.idxToPosition = function(idx) {
- var lastFoldEndColumn = 0;
- var fold;
-
- for (var i = 0; i < this.folds.length; i++) {
- var fold = this.folds[i];
-
- idx -= fold.start.column - lastFoldEndColumn;
- if (idx < 0) {
- return {
- row: fold.start.row,
- column: fold.start.column + idx
- };
- }
-
- idx -= fold.placeholder.length;
- if (idx < 0) {
- return fold.start;
- }
-
- lastFoldEndColumn = fold.end.column;
- }
-
- return {
- row: this.end.row,
- column: this.end.column + idx
- };
- }
-}).call(FoldLine.prototype);
-
-exports.FoldLine = FoldLine;
-});
http://git-wip-us.apache.org/repos/asf/couchdb/blob/5b8fb9c3/src/fauxton/assets/js/libs/ace/edit_session/folding.js
----------------------------------------------------------------------
diff --git a/src/fauxton/assets/js/libs/ace/edit_session/folding.js b/src/fauxton/assets/js/libs/ace/edit_session/folding.js
deleted file mode 100644
index a9b2ddd..0000000
--- a/src/fauxton/assets/js/libs/ace/edit_session/folding.js
+++ /dev/null
@@ -1,799 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Distributed under the BSD license:
- *
- * Copyright (c) 2010, Ajax.org B.V.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of Ajax.org B.V. nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * ***** END LICENSE BLOCK ***** */
-
-define(function(require, exports, module) {
-"use strict";
-
-var Range = require("../range").Range;
-var FoldLine = require("./fold_line").FoldLine;
-var Fold = require("./fold").Fold;
-var TokenIterator = require("../token_iterator").TokenIterator;
-
-function Folding() {
- /*
- * Looks up a fold at a given row/column. Possible values for side:
- * -1: ignore a fold if fold.start = row/column
- * +1: ignore a fold if fold.end = row/column
- */
- this.getFoldAt = function(row, column, side) {
- var foldLine = this.getFoldLine(row);
- if (!foldLine)
- return null;
-
- var folds = foldLine.folds;
- for (var i = 0; i < folds.length; i++) {
- var fold = folds[i];
- if (fold.range.contains(row, column)) {
- if (side == 1 && fold.range.isEnd(row, column)) {
- continue;
- } else if (side == -1 && fold.range.isStart(row, column)) {
- continue;
- }
- return fold;
- }
- }
- };
-
- /*
- * Returns all folds in the given range. Note, that this will return folds
- *
- */
- this.getFoldsInRange = function(range) {
- var start = range.start;
- var end = range.end;
- var foldLines = this.$foldData;
- var foundFolds = [];
-
- start.column += 1;
- end.column -= 1;
-
- for (var i = 0; i < foldLines.length; i++) {
- var cmp = foldLines[i].range.compareRange(range);
- if (cmp == 2) {
- // Range is before foldLine. No intersection. This means,
- // there might be other foldLines that intersect.
- continue;
- }
- else if (cmp == -2) {
- // Range is after foldLine. There can't be any other foldLines then,
- // so let's give up.
- break;
- }
-
- var folds = foldLines[i].folds;
- for (var j = 0; j < folds.length; j++) {
- var fold = folds[j];
- cmp = fold.range.compareRange(range);
- if (cmp == -2) {
- break;
- } else if (cmp == 2) {
- continue;
- } else
- // WTF-state: Can happen due to -1/+1 to start/end column.
- if (cmp == 42) {
- break;
- }
- foundFolds.push(fold);
- }
- }
- start.column -= 1;
- end.column += 1;
-
- return foundFolds;
- };
-
- /*
- * Returns all folds in the document
- */
- this.getAllFolds = function() {
- var folds = [];
- var foldLines = this.$foldData;
-
- function addFold(fold) {
- folds.push(fold);
- }
-
- for (var i = 0; i < foldLines.length; i++)
- for (var j = 0; j < foldLines[i].folds.length; j++)
- addFold(foldLines[i].folds[j]);
-
- return folds;
- };
-
- /*
- * Returns the string between folds at the given position.
- * E.g.
- * foo<fold>b|ar<fold>wolrd -> "bar"
- * foo<fold>bar<fold>wol|rd -> "world"
- * foo<fold>bar<fo|ld>wolrd -> <null>
- *
- * where | means the position of row/column
- *
- * The trim option determs if the return string should be trimed according
- * to the "side" passed with the trim value:
- *
- * E.g.
- * foo<fold>b|ar<fold>wolrd -trim=-1> "b"
- * foo<fold>bar<fold>wol|rd -trim=+1> "rld"
- * fo|o<fold>bar<fold>wolrd -trim=00> "foo"
- */
- this.getFoldStringAt = function(row, column, trim, foldLine) {
- foldLine = foldLine || this.getFoldLine(row);
- if (!foldLine)
- return null;
-
- var lastFold = {
- end: { column: 0 }
- };
- // TODO: Refactor to use getNextFoldTo function.
- var str, fold;
- for (var i = 0; i < foldLine.folds.length; i++) {
- fold = foldLine.folds[i];
- var cmp = fold.range.compareEnd(row, column);
- if (cmp == -1) {
- str = this
- .getLine(fold.start.row)
- .substring(lastFold.end.column, fold.start.column);
- break;
- }
- else if (cmp === 0) {
- return null;
- }
- lastFold = fold;
- }
- if (!str)
- str = this.getLine(fold.start.row).substring(lastFold.end.column);
-
- if (trim == -1)
- return str.substring(0, column - lastFold.end.column);
- else if (trim == 1)
- return str.substring(column - lastFold.end.column);
- else
- return str;
- };
-
- this.getFoldLine = function(docRow, startFoldLine) {
- var foldData = this.$foldData;
- var i = 0;
- if (startFoldLine)
- i = foldData.indexOf(startFoldLine);
- if (i == -1)
- i = 0;
- for (i; i < foldData.length; i++) {
- var foldLine = foldData[i];
- if (foldLine.start.row <= docRow && foldLine.end.row >= docRow) {
- return foldLine;
- } else if (foldLine.end.row > docRow) {
- return null;
- }
- }
- return null;
- };
-
- // returns the fold which starts after or contains docRow
- this.getNextFoldLine = function(docRow, startFoldLine) {
- var foldData = this.$foldData;
- var i = 0;
- if (startFoldLine)
- i = foldData.indexOf(startFoldLine);
- if (i == -1)
- i = 0;
- for (i; i < foldData.length; i++) {
- var foldLine = foldData[i];
- if (foldLine.end.row >= docRow) {
- return foldLine;
- }
- }
- return null;
- };
-
- this.getFoldedRowCount = function(first, last) {
- var foldData = this.$foldData, rowCount = last-first+1;
- for (var i = 0; i < foldData.length; i++) {
- var foldLine = foldData[i],
- end = foldLine.end.row,
- start = foldLine.start.row;
- if (end >= last) {
- if(start < last) {
- if(start >= first)
- rowCount -= last-start;
- else
- rowCount = 0;//in one fold
- }
- break;
- } else if(end >= first){
- if (start >= first) //fold inside range
- rowCount -= end-start;
- else
- rowCount -= end-first+1;
- }
- }
- return rowCount;
- };
-
- this.$addFoldLine = function(foldLine) {
- this.$foldData.push(foldLine);
- this.$foldData.sort(function(a, b) {
- return a.start.row - b.start.row;
- });
- return foldLine;
- };
-
- /**
- * Adds a new fold.
- *
- * @returns
- * The new created Fold object or an existing fold object in case the
- * passed in range fits an existing fold exactly.
- */
- this.addFold = function(placeholder, range) {
- var foldData = this.$foldData;
- var added = false;
- var fold;
-
- if (placeholder instanceof Fold)
- fold = placeholder;
- else {
- fold = new Fold(range, placeholder);
- fold.collapseChildren = range.collapseChildren;
- }
- this.$clipRangeToDocument(fold.range);
-
- var startRow = fold.start.row;
- var startColumn = fold.start.column;
- var endRow = fold.end.row;
- var endColumn = fold.end.column;
-
- // --- Some checking ---
- if (!(startRow < endRow ||
- startRow == endRow && startColumn <= endColumn - 2))
- throw new Error("The range has to be at least 2 characters width");
-
- var startFold = this.getFoldAt(startRow, startColumn, 1);
- var endFold = this.getFoldAt(endRow, endColumn, -1);
- if (startFold && endFold == startFold)
- return startFold.addSubFold(fold);
-
- if (
- (startFold && !startFold.range.isStart(startRow, startColumn))
- || (endFold && !endFold.range.isEnd(endRow, endColumn))
- ) {
- throw new Error("A fold can't intersect already existing fold" + fold.range + startFold.range);
- }
-
- // Check if there are folds in the range we create the new fold for.
- var folds = this.getFoldsInRange(fold.range);
- if (folds.length > 0) {
- // Remove the folds from fold data.
- this.removeFolds(folds);
- // Add the removed folds as subfolds on the new fold.
- folds.forEach(function(subFold) {
- fold.addSubFold(subFold);
- });
- }
-
- for (var i = 0; i < foldData.length; i++) {
- var foldLine = foldData[i];
- if (endRow == foldLine.start.row) {
- foldLine.addFold(fold);
- added = true;
- break;
- } else if (startRow == foldLine.end.row) {
- foldLine.addFold(fold);
- added = true;
- if (!fold.sameRow) {
- // Check if we might have to merge two FoldLines.
- var foldLineNext = foldData[i + 1];
- if (foldLineNext && foldLineNext.start.row == endRow) {
- // We need to merge!
- foldLine.merge(foldLineNext);
- break;
- }
- }
- break;
- } else if (endRow <= foldLine.start.row) {
- break;
- }
- }
-
- if (!added)
- foldLine = this.$addFoldLine(new FoldLine(this.$foldData, fold));
-
- if (this.$useWrapMode)
- this.$updateWrapData(foldLine.start.row, foldLine.start.row);
- else
- this.$updateRowLengthCache(foldLine.start.row, foldLine.start.row);
-
- // Notify that fold data has changed.
- this.$modified = true;
- this._emit("changeFold", { data: fold, action: "add" });
-
- return fold;
- };
-
- this.addFolds = function(folds) {
- folds.forEach(function(fold) {
- this.addFold(fold);
- }, this);
- };
-
- this.removeFold = function(fold) {
- var foldLine = fold.foldLine;
- var startRow = foldLine.start.row;
- var endRow = foldLine.end.row;
-
- var foldLines = this.$foldData;
- var folds = foldLine.folds;
- // Simple case where there is only one fold in the FoldLine such that
- // the entire fold line can get removed directly.
- if (folds.length == 1) {
- foldLines.splice(foldLines.indexOf(foldLine), 1);
- } else
- // If the fold is the last fold of the foldLine, just remove it.
- if (foldLine.range.isEnd(fold.end.row, fold.end.column)) {
- folds.pop();
- foldLine.end.row = folds[folds.length - 1].end.row;
- foldLine.end.column = folds[folds.length - 1].end.column;
- } else
- // If the fold is the first fold of the foldLine, just remove it.
- if (foldLine.range.isStart(fold.start.row, fold.start.column)) {
- folds.shift();
- foldLine.start.row = folds[0].start.row;
- foldLine.start.column = folds[0].start.column;
- } else
- // We know there are more then 2 folds and the fold is not at the edge.
- // This means, the fold is somewhere in between.
- //
- // If the fold is in one row, we just can remove it.
- if (fold.sameRow) {
- folds.splice(folds.indexOf(fold), 1);
- } else
- // The fold goes over more then one row. This means remvoing this fold
- // will cause the fold line to get splitted up. newFoldLine is the second part
- {
- var newFoldLine = foldLine.split(fold.start.row, fold.start.column);
- folds = newFoldLine.folds;
- folds.shift();
- newFoldLine.start.row = folds[0].start.row;
- newFoldLine.start.column = folds[0].start.column;
- }
-
- if (!this.$updating) {
- if (this.$useWrapMode)
- this.$updateWrapData(startRow, endRow);
- else
- this.$updateRowLengthCache(startRow, endRow);
- }
-
- // Notify that fold data has changed.
- this.$modified = true;
- this._emit("changeFold", { data: fold, action: "remove" });
- };
-
- this.removeFolds = function(folds) {
- // We need to clone the folds array passed in as it might be the folds
- // array of a fold line and as we call this.removeFold(fold), folds
- // are removed from folds and changes the current index.
- var cloneFolds = [];
- for (var i = 0; i < folds.length; i++) {
- cloneFolds.push(folds[i]);
- }
-
- cloneFolds.forEach(function(fold) {
- this.removeFold(fold);
- }, this);
- this.$modified = true;
- };
-
- this.expandFold = function(fold) {
- this.removeFold(fold);
- fold.subFolds.forEach(function(subFold) {
- fold.restoreRange(subFold);
- this.addFold(subFold);
- }, this);
- if (fold.collapseChildren > 0) {
- this.foldAll(fold.start.row+1, fold.end.row, fold.collapseChildren-1);
- }
- fold.subFolds = [];
- };
-
- this.expandFolds = function(folds) {
- folds.forEach(function(fold) {
- this.expandFold(fold);
- }, this);
- };
-
- this.unfold = function(location, expandInner) {
- var range, folds;
- if (location == null) {
- range = new Range(0, 0, this.getLength(), 0);
- expandInner = true;
- } else if (typeof location == "number")
- range = new Range(location, 0, location, this.getLine(location).length);
- else if ("row" in location)
- range = Range.fromPoints(location, location);
- else
- range = location;
-
- folds = this.getFoldsInRange(range);
- if (expandInner) {
- this.removeFolds(folds);
- } else {
- // TODO: might need to remove and add folds in one go instead of using
- // expandFolds several times.
- while (folds.length) {
- this.expandFolds(folds);
- folds = this.getFoldsInRange(range);
- }
- }
- };
-
- /*
- * Checks if a given documentRow is folded. This is true if there are some
- * folded parts such that some parts of the line is still visible.
- **/
- this.isRowFolded = function(docRow, startFoldRow) {
- return !!this.getFoldLine(docRow, startFoldRow);
- };
-
- this.getRowFoldEnd = function(docRow, startFoldRow) {
- var foldLine = this.getFoldLine(docRow, startFoldRow);
- return foldLine ? foldLine.end.row : docRow;
- };
-
- this.getRowFoldStart = function(docRow, startFoldRow) {
- var foldLine = this.getFoldLine(docRow, startFoldRow);
- return foldLine ? foldLine.start.row : docRow;
- };
-
- this.getFoldDisplayLine = function(foldLine, endRow, endColumn, startRow, startColumn) {
- if (startRow == null) {
- startRow = foldLine.start.row;
- startColumn = 0;
- }
-
- if (endRow == null) {
- endRow = foldLine.end.row;
- endColumn = this.getLine(endRow).length;
- }
-
- // Build the textline using the FoldLine walker.
- var doc = this.doc;
- var textLine = "";
-
- foldLine.walk(function(placeholder, row, column, lastColumn) {
- if (row < startRow)
- return;
- if (row == startRow) {
- if (column < startColumn)
- return;
- lastColumn = Math.max(startColumn, lastColumn);
- }
-
- if (placeholder != null) {
- textLine += placeholder;
- } else {
- textLine += doc.getLine(row).substring(lastColumn, column);
- }
- }, endRow, endColumn);
- return textLine;
- };
-
- this.getDisplayLine = function(row, endColumn, startRow, startColumn) {
- var foldLine = this.getFoldLine(row);
-
- if (!foldLine) {
- var line;
- line = this.doc.getLine(row);
- return line.substring(startColumn || 0, endColumn || line.length);
- } else {
- return this.getFoldDisplayLine(
- foldLine, row, endColumn, startRow, startColumn);
- }
- };
-
- this.$cloneFoldData = function() {
- var fd = [];
- fd = this.$foldData.map(function(foldLine) {
- var folds = foldLine.folds.map(function(fold) {
- return fold.clone();
- });
- return new FoldLine(fd, folds);
- });
-
- return fd;
- };
-
- this.toggleFold = function(tryToUnfold) {
- var selection = this.selection;
- var range = selection.getRange();
- var fold;
- var bracketPos;
-
- if (range.isEmpty()) {
- var cursor = range.start;
- fold = this.getFoldAt(cursor.row, cursor.column);
-
- if (fold) {
- this.expandFold(fold);
- return;
- } else if (bracketPos = this.findMatchingBracket(cursor)) {
- if (range.comparePoint(bracketPos) == 1) {
- range.end = bracketPos;
- } else {
- range.start = bracketPos;
- range.start.column++;
- range.end.column--;
- }
- } else if (bracketPos = this.findMatchingBracket({row: cursor.row, column: cursor.column + 1})) {
- if (range.comparePoint(bracketPos) == 1)
- range.end = bracketPos;
- else
- range.start = bracketPos;
-
- range.start.column++;
- } else {
- range = this.getCommentFoldRange(cursor.row, cursor.column) || range;
- }
- } else {
- var folds = this.getFoldsInRange(range);
- if (tryToUnfold && folds.length) {
- this.expandFolds(folds);
- return;
- } else if (folds.length == 1 ) {
- fold = folds[0];
- }
- }
-
- if (!fold)
- fold = this.getFoldAt(range.start.row, range.start.column);
-
- if (fold && fold.range.toString() == range.toString()) {
- this.expandFold(fold);
- return;
- }
-
- var placeholder = "...";
- if (!range.isMultiLine()) {
- placeholder = this.getTextRange(range);
- if(placeholder.length < 4)
- return;
- placeholder = placeholder.trim().substring(0, 2) + "..";
- }
-
- this.addFold(placeholder, range);
- };
-
- this.getCommentFoldRange = function(row, column, dir) {
- var iterator = new TokenIterator(this, row, column);
- var token = iterator.getCurrentToken();
- if (token && /^comment|string/.test(token.type)) {
- var range = new Range();
- var re = new RegExp(token.type.replace(/\..*/, "\\."));
- if (dir != 1) {
- do {
- token = iterator.stepBackward();
- } while(token && re.test(token.type));
- iterator.stepForward();
- }
-
- range.start.row = iterator.getCurrentTokenRow();
- range.start.column = iterator.getCurrentTokenColumn() + 2;
-
- iterator = new TokenIterator(this, row, column);
-
- if (dir != -1) {
- do {
- token = iterator.stepForward();
- } while(token && re.test(token.type));
- token = iterator.stepBackward();
- } else
- token = iterator.getCurrentToken();
-
- range.end.row = iterator.getCurrentTokenRow();
- range.end.column = iterator.getCurrentTokenColumn() + token.value.length - 2;
- return range;
- }
- };
-
- this.foldAll = function(startRow, endRow, depth) {
- if (depth == undefined)
- depth = 100000; // JSON.stringify doesn't hanle Infinity
- var foldWidgets = this.foldWidgets;
- endRow = endRow || this.getLength();
- startRow = startRow || 0;
- for (var row = startRow; row < endRow; row++) {
- if (foldWidgets[row] == null)
- foldWidgets[row] = this.getFoldWidget(row);
- if (foldWidgets[row] != "start")
- continue;
-
- var range = this.getFoldWidgetRange(row);
- var rangeEndRow = range.end.row;
- // sometimes range can be incompatible with existing fold
- // TODO change addFold to return null istead of throwing
- if (range && range.isMultiLine()
- && rangeEndRow <= endRow
- && range.start.row >= startRow
- ) try {
- var fold = this.addFold("...", range);
- fold.collapseChildren = depth;
- // addFold can change the range
- row = rangeEndRow;
- } catch(e) {}
- }
- };
-
- // structured folding
- this.$foldStyles = {
- "manual": 1,
- "markbegin": 1,
- "markbeginend": 1
- };
- this.$foldStyle = "markbegin";
- this.setFoldStyle = function(style) {
- if (!this.$foldStyles[style])
- throw new Error("invalid fold style: " + style + "[" + Object.keys(this.$foldStyles).join(", ") + "]");
-
- if (this.$foldStyle == style)
- return;
-
- this.$foldStyle = style;
-
- if (style == "manual")
- this.unfold();
-
- // reset folding
- var mode = this.$foldMode;
- this.$setFolding(null);
- this.$setFolding(mode);
- };
-
- this.$setFolding = function(foldMode) {
- if (this.$foldMode == foldMode)
- return;
-
- this.$foldMode = foldMode;
-
- this.removeListener('change', this.$updateFoldWidgets);
- this._emit("changeAnnotation");
-
- if (!foldMode || this.$foldStyle == "manual") {
- this.foldWidgets = null;
- return;
- }
-
- this.foldWidgets = [];
- this.getFoldWidget = foldMode.getFoldWidget.bind(foldMode, this, this.$foldStyle);
- this.getFoldWidgetRange = foldMode.getFoldWidgetRange.bind(foldMode, this, this.$foldStyle);
-
- this.$updateFoldWidgets = this.updateFoldWidgets.bind(this);
- this.on('change', this.$updateFoldWidgets);
-
- };
-
- this.getParentFoldRangeData = function (row, ignoreCurrent) {
- var fw = this.foldWidgets;
- if (!fw || (ignoreCurrent && fw[row]))
- return {};
-
- var i = row - 1, firstRange;
- while (i >= 0) {
- var c = fw[i];
- if (c == null)
- c = fw[i] = this.getFoldWidget(i);
-
- if (c == "start") {
- var range = this.getFoldWidgetRange(i);
- if (!firstRange)
- firstRange = range;
- if (range && range.end.row >= row)
- break;
- }
- i--;
- }
-
- return {
- range: i !== -1 && range,
- firstRange: firstRange
- };
- }
-
- this.onFoldWidgetClick = function(row, e) {
- var type = this.getFoldWidget(row);
- var line = this.getLine(row);
- e = e.domEvent;
- var children = e.shiftKey;
- var all = e.ctrlKey || e.metaKey;
- var siblings = e.altKey;
-
- var dir = type === "end" ? -1 : 1;
- var fold = this.getFoldAt(row, dir === -1 ? 0 : line.length, dir);
-
- if (fold) {
- if (children || all)
- this.removeFold(fold);
- else
- this.expandFold(fold);
- return;
- }
-
- var range = this.getFoldWidgetRange(row);
- // sometimes singleline folds can be missed by the code above
- if (range && !range.isMultiLine()) {
- fold = this.getFoldAt(range.start.row, range.start.column, 1);
- if (fold && range.isEqual(fold.range)) {
- this.removeFold(fold);
- return;
- }
- }
-
- if (siblings) {
- var data = this.getParentFoldRangeData(row);
- if (data.range) {
- var startRow = data.range.start.row + 1;
- var endRow = data.range.end.row;
- }
- this.foldAll(startRow, endRow, all ? 10000 : 0);
- } else if (children) {
- var endRow = range ? range.end.row : this.getLength();
- this.foldAll(row + 1, range.end.row, all ? 10000 : 0);
- } else if (range) {
- if (all)
- range.collapseChildren = 10000;
- this.addFold("...", range);
- }
-
- if (!range)
- (e.target || e.srcElement).className += " ace_invalid"
- };
-
- this.updateFoldWidgets = function(e) {
- var delta = e.data;
- var range = delta.range;
- var firstRow = range.start.row;
- var len = range.end.row - firstRow;
-
- if (len === 0) {
- this.foldWidgets[firstRow] = null;
- } else if (delta.action == "removeText" || delta.action == "removeLines") {
- this.foldWidgets.splice(firstRow, len + 1, null);
- } else {
- var args = Array(len + 1);
- args.unshift(firstRow, 1);
- this.foldWidgets.splice.apply(this.foldWidgets, args);
- }
- };
-
-}
-
-exports.Folding = Folding;
-
-});