This commit is contained in:
Fabian Jakobs 2011-07-25 14:19:54 +02:00
commit 16dc74d766
22 changed files with 692 additions and 474 deletions

View file

@ -5751,6 +5751,10 @@ var Editor =function(renderer, session) {
} }
this.textInput.focus(); this.textInput.focus();
}; };
this.isFocused = function() {
return this.textInput.isFocused();
};
this.blur = function() { this.blur = function() {
this.textInput.blur(); this.textInput.blur();
@ -6995,10 +6999,11 @@ exports.TextInput = TextInput;
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
define('ace/mouse_handler', ['require', 'exports', 'module' , 'pilot/event', 'pilot/dom'], function(require, exports, module) { define('ace/mouse_handler', ['require', 'exports', 'module' , 'pilot/event', 'pilot/dom', 'pilot/browser_focus'], function(require, exports, module) {
var event = require("pilot/event"); var event = require("pilot/event");
var dom = require("pilot/dom"); var dom = require("pilot/dom");
var BrowserFocus = require("pilot/browser_focus").BrowserFocus;
var STATE_UNKNOWN = 0; var STATE_UNKNOWN = 0;
var STATE_SELECT = 1; var STATE_SELECT = 1;
@ -7009,6 +7014,8 @@ var DRAG_OFFSET = 5; // pixels
var MouseHandler = function(editor) { var MouseHandler = function(editor) {
this.editor = editor; this.editor = editor;
this.browserFocus = new BrowserFocus();
event.addListener(editor.container, "mousedown", function(e) { event.addListener(editor.container, "mousedown", function(e) {
editor.focus(); editor.focus();
return event.preventDefault(e); return event.preventDefault(e);
@ -7049,6 +7056,15 @@ var MouseHandler = function(editor) {
}; };
this.onMouseDown = function(e) { this.onMouseDown = function(e) {
// if this click caused the editor to be focused ignore the click
// for selection and cursor placement
if (
!this.browserFocus.isFocused()
|| new Date().getTime() - this.browserFocus.lastFocus < 20
|| !this.editor.isFocused()
)
return;
var pageX = event.getDocumentX(e); var pageX = event.getDocumentX(e);
var pageY = event.getDocumentY(e); var pageY = event.getDocumentY(e);
var pos = this.$getEventPosition(e); var pos = this.$getEventPosition(e);
@ -7258,6 +7274,97 @@ var MouseHandler = function(editor) {
exports.MouseHandler = MouseHandler; exports.MouseHandler = MouseHandler;
}); });
/* vim:ts=4:sts=4:sw=4:
* ***** 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>
* Irakli Gozalishvili <rfobic@gmail.com> (http://jeditoolkit.com)
* Julian Viereck <julian.viereck@gmail.com>
*
* 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('pilot/browser_focus', ['require', 'exports', 'module' , 'pilot/oop', 'pilot/event', 'pilot/event_emitter'], function(require, exports, module) {
var oop = require("pilot/oop");
var event = require("pilot/event");
var EventEmitter = require("pilot/event_emitter").EventEmitter;
/**
* This class keeps track of the focus state of the given window.
* Focus changes for example when the user switches a browser tab,
* goes to the location bar or switches to another application.
*/
var BrowserFocus = function(win) {
win = win || window;
this.lastFocus = new Date().getTime();
this._isFocused = true;
var _self = this;
event.addListener(win, "blur", function(e) {
_self._setFocused(false);
});
event.addListener(win, "focus", function(e) {
_self._setFocused(true);
});
};
(function(){
oop.implement(this, EventEmitter);
this.isFocused = function() {
return this._isFocused;
};
this._setFocused = function(isFocused) {
if (this._isFocused == isFocused)
return;
if (isFocused)
this.lastFocus = new Date().getTime();
this._isFocused = isFocused;
this._emit("changeFocus");
};
}).call(BrowserFocus.prototype);
exports.BrowserFocus = BrowserFocus;
});
/* ***** BEGIN LICENSE BLOCK ***** /* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
* *
@ -7809,7 +7916,6 @@ var EditSession = function(text, mode) {
}); });
return str; return str;
} }
this.$docChangeCounter = 0;
if (text instanceof Document) { if (text instanceof Document) {
this.setDocument(text); this.setDocument(text);
@ -7835,8 +7941,6 @@ var EditSession = function(text, mode) {
this.doc = doc; this.doc = doc;
doc.on("change", this.onChange.bind(this)); doc.on("change", this.onChange.bind(this));
doc.on("changeStart", this.onChangeStart.bind(this));
doc.on("changeEnd", this.onChangeEnd.bind(this));
this.on("changeFold", this.onChangeFold.bind(this)); this.on("changeFold", this.onChangeFold.bind(this));
}; };
@ -7844,10 +7948,6 @@ var EditSession = function(text, mode) {
return this.doc; return this.doc;
}; };
this.onChangeStart = function() {
this.$docChangeCounter ++;
};
this.$resetRowCache = function(row) { this.$resetRowCache = function(row) {
if (row == 0) { if (row == 0) {
this.$rowCache = []; this.$rowCache = [];
@ -7860,29 +7960,6 @@ var EditSession = function(text, mode) {
return; return;
} }
} }
}
this.onChangeEnd = function() {
this.$docChangeCounter --;
if (this.$docChangeCounter == 0
&& !this.$fromUndo && this.$undoManager)
{
if (this.$deltasFold.length) {
this.$deltas.push({
group: "fold",
deltas: this.$deltasFold
});
this.$deltasFold = [];
}
if (this.$deltasDoc) {
this.$deltas.push({
group: "doc",
deltas: this.$deltasDoc
});
this.$deltasDoc = [];
}
this.$informUndoManager.schedule();
}
}; };
this.onChangeFold = function(e) { this.onChangeFold = function(e) {
@ -7905,6 +7982,8 @@ var EditSession = function(text, mode) {
folds: removedFolds folds: removedFolds
}); });
} }
this.$informUndoManager.schedule();
} }
this.bgTokenizer.start(delta.range.start.row); this.bgTokenizer.start(delta.range.start.row);
@ -7913,6 +7992,9 @@ var EditSession = function(text, mode) {
this.setValue = function(text) { this.setValue = function(text) {
this.doc.setValue(text); this.doc.setValue(text);
this.selection.moveCursorTo(0, 0);
this.selection.clearSelection();
this.$resetRowCache(0); this.$resetRowCache(0);
this.$deltas = []; this.$deltas = [];
this.$deltasDoc = []; this.$deltasDoc = [];
@ -7944,19 +8026,37 @@ var EditSession = function(text, mode) {
this.$deltasDoc = []; this.$deltasDoc = [];
this.$deltasFold = []; this.$deltasFold = [];
if (this.$informUndoManager) { if (this.$informUndoManager)
this.$informUndoManager.cancel(); this.$informUndoManager.cancel();
}
if (undoManager) { if (undoManager) {
var self = this; var self = this;
this.$syncInformUndoManager = function() { this.$syncInformUndoManager = function() {
self.$informUndoManager.cancel(); self.$informUndoManager.cancel();
if (self.$deltas.length > 0)
undoManager.execute({ if (self.$deltasFold.length) {
action : "aceupdate", self.$deltas.push({
args : [self.$deltas, self] group: "fold",
deltas: self.$deltasFold
}); });
self.$deltasFold = [];
}
if (self.$deltasDoc.length) {
self.$deltas.push({
group: "doc",
deltas: self.$deltasDoc
});
self.$deltasDoc = [];
}
if (self.$deltas.length > 0) {
undoManager.execute({
action: "aceupdate",
args: [self.$deltas, self]
});
}
self.$deltas = []; self.$deltas = [];
} }
this.$informUndoManager = this.$informUndoManager =
@ -9168,14 +9268,17 @@ var EditSession = function(text, mode) {
var rowLength = 0; var rowLength = 0;
var rowCache = this.$rowCache; var rowCache = this.$rowCache;
var doCache = !rowCache.length;
for (var i = 0; i < rowCache.length; i++) { for (var i = 0; i < rowCache.length; i++) {
if (rowCache[i].screenRow < screenRow) { if (rowCache[i].screenRow < screenRow) {
row = rowCache[i].screenRow; row = rowCache[i].screenRow;
docRow = rowCache[i].docRow; docRow = rowCache[i].docRow;
doCache = i == rowCache.length - 1; }
else {
break;
} }
} }
var doCache = !rowCache.length || i == rowCache.length;
// clamp row before clamping column, for selection on last line // clamp row before clamping column, for selection on last line
var maxRow = this.getLength() - 1; var maxRow = this.getLength() - 1;
@ -9183,12 +9286,6 @@ var EditSession = function(text, mode) {
var foldStart = foldLine ? foldLine.start.row : Infinity; var foldStart = foldLine ? foldLine.start.row : Infinity;
while (row <= screenRow) { while (row <= screenRow) {
if (doCache) {
rowCache.push({
docRow: docRow,
screenRow: row
});
}
rowLength = this.getRowLength(docRow); rowLength = this.getRowLength(docRow);
if (row + rowLength - 1 >= screenRow || docRow >= maxRow) { if (row + rowLength - 1 >= screenRow || docRow >= maxRow) {
break; break;
@ -9201,6 +9298,12 @@ var EditSession = function(text, mode) {
foldStart = foldLine ? foldLine.start.row : Infinity; foldStart = foldLine ? foldLine.start.row : Infinity;
} }
} }
if (doCache) {
rowCache.push({
docRow: docRow,
screenRow: row
});
}
} }
if (foldLine && foldLine.start.row <= docRow) if (foldLine && foldLine.start.row <= docRow)
@ -9285,15 +9388,16 @@ var EditSession = function(text, mode) {
var rowEnd, row = 0; var rowEnd, row = 0;
var rowCache = this.$rowCache; var rowCache = this.$rowCache;
//
var doCache = !rowCache.length;
for (var i = 0; i < rowCache.length; i++) { for (var i = 0; i < rowCache.length; i++) {
if (rowCache[i].docRow < docRow) { if (rowCache[i].docRow < docRow) {
screenRow = rowCache[i].screenRow; screenRow = rowCache[i].screenRow;
row = rowCache[i].docRow; row = rowCache[i].docRow;
doCache = i == rowCache.length - 1; } else {
break;
} }
} }
var doCache = !rowCache.length || i == rowCache.length;
var foldLine = this.getNextFold(row); var foldLine = this.getNextFold(row);
var foldStart = foldLine ?foldLine.start.row :Infinity; var foldStart = foldLine ?foldLine.start.row :Infinity;
@ -9305,18 +9409,20 @@ var EditSession = function(text, mode) {
break; break;
foldLine = this.getNextFold(rowEnd); foldLine = this.getNextFold(rowEnd);
foldStart = foldLine ?foldLine.start.row :Infinity; foldStart = foldLine ?foldLine.start.row :Infinity;
} else { }
else {
rowEnd = row + 1; rowEnd = row + 1;
} }
screenRow += this.getRowLength(row);
row = rowEnd;
if (doCache) { if (doCache) {
rowCache.push({ rowCache.push({
docRow: row, docRow: row,
screenRow: screenRow screenRow: screenRow
}); });
} }
screenRow += this.getRowLength(row);
row = rowEnd;
} }
// Calculate the text line that is displayed in docRow on the screen. // Calculate the text line that is displayed in docRow on the screen.
@ -9473,6 +9579,13 @@ var lang = require("pilot/lang");
var EventEmitter = require("pilot/event_emitter").EventEmitter; var EventEmitter = require("pilot/event_emitter").EventEmitter;
var Range = require("ace/range").Range; var Range = require("ace/range").Range;
/**
* Keeps cursor position and the text selection of an edit session.
*
* The row/columns used in the selection are in document coordinates
* representing ths coordinates as thez appear in the document
* before applying soft wrap and folding.
*/
var Selection = function(session) { var Selection = function(session) {
this.session = session; this.session = session;
this.doc = session.getDocument(); this.doc = session.getDocument();
@ -10968,14 +11081,12 @@ var Document = function(text) {
var firstLine = lines.splice(0, 1)[0]; var firstLine = lines.splice(0, 1)[0];
var lastLine = lines.length == 0 ? null : lines.splice(lines.length - 1, 1)[0]; var lastLine = lines.length == 0 ? null : lines.splice(lines.length - 1, 1)[0];
this._dispatchEvent("changeStart");
position = this.insertInLine(position, firstLine); position = this.insertInLine(position, firstLine);
if (lastLine !== null) { if (lastLine !== null) {
position = this.insertNewLine(position); // terminate first line position = this.insertNewLine(position); // terminate first line
position = this.insertLines(position.row, lines); position = this.insertLines(position.row, lines);
position = this.insertInLine(position, lastLine || ""); position = this.insertInLine(position, lastLine || "");
} }
this._dispatchEvent("changeEnd");
return position; return position;
}; };
@ -10987,7 +11098,6 @@ var Document = function(text) {
args.push.apply(args, lines); args.push.apply(args, lines);
this.$lines.splice.apply(this.$lines, args); this.$lines.splice.apply(this.$lines, args);
this._dispatchEvent("changeStart");
var range = new Range(row, 0, row + lines.length, 0); var range = new Range(row, 0, row + lines.length, 0);
var delta = { var delta = {
action: "insertLines", action: "insertLines",
@ -10995,7 +11105,6 @@ var Document = function(text) {
lines: lines lines: lines
}; };
this._dispatchEvent("change", { data: delta }); this._dispatchEvent("change", { data: delta });
this._dispatchEvent("changeEnd");
return range.end; return range.end;
}, },
@ -11003,7 +11112,6 @@ var Document = function(text) {
position = this.$clipPosition(position); position = this.$clipPosition(position);
var line = this.$lines[position.row] || ""; var line = this.$lines[position.row] || "";
this._dispatchEvent("changeStart");
this.$lines[position.row] = line.substring(0, position.column); this.$lines[position.row] = line.substring(0, position.column);
this.$lines.splice(position.row + 1, 0, line.substring(position.column, line.length)); this.$lines.splice(position.row + 1, 0, line.substring(position.column, line.length));
@ -11018,7 +11126,6 @@ var Document = function(text) {
text: this.getNewLineCharacter() text: this.getNewLineCharacter()
}; };
this._dispatchEvent("change", { data: delta }); this._dispatchEvent("change", { data: delta });
this._dispatchEvent("changeEnd");
return end; return end;
}; };
@ -11029,7 +11136,6 @@ var Document = function(text) {
var line = this.$lines[position.row] || ""; var line = this.$lines[position.row] || "";
this._dispatchEvent("changeStart");
this.$lines[position.row] = line.substring(0, position.column) + text this.$lines[position.row] = line.substring(0, position.column) + text
+ line.substring(position.column); + line.substring(position.column);
@ -11044,7 +11150,6 @@ var Document = function(text) {
text: text text: text
}; };
this._dispatchEvent("change", { data: delta }); this._dispatchEvent("change", { data: delta });
this._dispatchEvent("changeEnd");
return end; return end;
}; };
@ -11060,7 +11165,6 @@ var Document = function(text) {
var firstRow = range.start.row; var firstRow = range.start.row;
var lastRow = range.end.row; var lastRow = range.end.row;
this._dispatchEvent("changeStart");
if (range.isMultiLine()) { if (range.isMultiLine()) {
var firstFullRow = range.start.column == 0 ? firstRow : firstRow + 1; var firstFullRow = range.start.column == 0 ? firstRow : firstRow + 1;
var lastFullRow = lastRow - 1; var lastFullRow = lastRow - 1;
@ -11079,7 +11183,6 @@ var Document = function(text) {
else { else {
this.removeInLine(firstRow, range.start.column, range.end.column); this.removeInLine(firstRow, range.start.column, range.end.column);
} }
this._dispatchEvent("changeEnd");
return range.start; return range.start;
}; };
@ -11091,7 +11194,6 @@ var Document = function(text) {
var line = this.getLine(row); var line = this.getLine(row);
var removed = line.substring(startColumn, endColumn); var removed = line.substring(startColumn, endColumn);
var newLine = line.substring(0, startColumn) + line.substring(endColumn, line.length); var newLine = line.substring(0, startColumn) + line.substring(endColumn, line.length);
this._dispatchEvent("changeStart");
this.$lines.splice(row, 1, newLine); this.$lines.splice(row, 1, newLine);
var delta = { var delta = {
@ -11100,7 +11202,6 @@ var Document = function(text) {
text: removed text: removed
}; };
this._dispatchEvent("change", { data: delta }); this._dispatchEvent("change", { data: delta });
this._dispatchEvent("changeEnd");
return range.start; return range.start;
}; };
@ -11112,7 +11213,6 @@ var Document = function(text) {
* @return {String[]} The removed lines * @return {String[]} The removed lines
*/ */
this.removeLines = function(firstRow, lastRow) { this.removeLines = function(firstRow, lastRow) {
this._dispatchEvent("changeStart");
var range = new Range(firstRow, 0, lastRow + 1, 0); var range = new Range(firstRow, 0, lastRow + 1, 0);
var removed = this.$lines.splice(firstRow, lastRow - firstRow + 1); var removed = this.$lines.splice(firstRow, lastRow - firstRow + 1);
@ -11123,7 +11223,6 @@ var Document = function(text) {
lines: removed lines: removed
}; };
this._dispatchEvent("change", { data: delta }); this._dispatchEvent("change", { data: delta });
this._dispatchEvent("changeEnd");
return removed; return removed;
}; };
@ -11134,7 +11233,6 @@ var Document = function(text) {
var range = new Range(row, firstLine.length, row+1, 0); var range = new Range(row, firstLine.length, row+1, 0);
var line = firstLine + secondLine; var line = firstLine + secondLine;
this._dispatchEvent("changeStart");
this.$lines.splice(row, 2, line); this.$lines.splice(row, 2, line);
var delta = { var delta = {
@ -11143,7 +11241,6 @@ var Document = function(text) {
text: this.getNewLineCharacter() text: this.getNewLineCharacter()
}; };
this._dispatchEvent("change", { data: delta }); this._dispatchEvent("change", { data: delta });
this._dispatchEvent("changeEnd");
}; };
this.replace = function(range, text) { this.replace = function(range, text) {
@ -11155,7 +11252,6 @@ var Document = function(text) {
if (text == this.getTextRange(range)) if (text == this.getTextRange(range))
return range.end; return range.end;
this._dispatchEvent("changeStart");
this.remove(range); this.remove(range);
if (text) { if (text) {
var end = this.insert(range.start, text); var end = this.insert(range.start, text);
@ -11163,7 +11259,6 @@ var Document = function(text) {
else { else {
end = range.start; end = range.start;
} }
this._dispatchEvent("changeEnd");
return end; return end;
}; };
@ -11609,44 +11704,11 @@ exports.BackgroundTokenizer = BackgroundTokenizer;
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
define('ace/edit_session/folding', ['require', 'exports', 'module' , 'ace/range', 'ace/edit_session/fold_line'], function(require, exports, module) { define('ace/edit_session/folding', ['require', 'exports', 'module' , 'ace/range', 'ace/edit_session/fold_line', 'ace/edit_session/fold'], function(require, exports, module) {
var Range = require("ace/range").Range; var Range = require("ace/range").Range;
var FoldLine = require("ace/edit_session/fold_line").FoldLine; var FoldLine = require("ace/edit_session/fold_line").FoldLine;
var Fold = require("ace/edit_session/fold").Fold;
/**
* Simple fold-data struct.
**/
function Fold(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 = [];
}
Fold.prototype.toString = function() {
return '"' + this.placeholder + '" ' + this.range.toString();
}
Fold.prototype.setFoldLine = function(foldLine) {
this.foldLine = foldLine;
this.subFolds.forEach(function(fold) {
fold.setFoldLine(foldLine);
});
}
Fold.prototype.clone = function() {
var range = this.range.clone();
var fold = new Fold(range, this.placeholder);
this.subFolds.forEach(function(subFold) {
fold.subFolds.push(subFold.clone());
});
return fold;
}
function Folding() { function Folding() {
/** /**
@ -11656,25 +11718,22 @@ function Folding() {
*/ */
this.getFoldAt = function(row, column, side) { this.getFoldAt = function(row, column, side) {
var foldLine = this.getFoldLine(row); var foldLine = this.getFoldLine(row);
if (foldLine) { if (!foldLine)
var folds = foldLine.folds,
fold;
for (var i = 0; i < folds.length; i++) {
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;
}
}
} else {
return null; 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 * Returns all folds in the given range. Note, that this will return folds
@ -11682,33 +11741,30 @@ function Folding() {
*/ */
this.getFoldsInRange = function(range) { this.getFoldsInRange = function(range) {
range = range.clone(); range = range.clone();
var start = range.start, var start = range.start;
end = range.end; var end = range.end;
var foldLines = this.$foldData, var foldLines = this.$foldData;
folds, var foundFolds = [];
fold;
var cmp,
foundFolds = [];
start.column += 1; start.column += 1;
end.column -= 1; end.column -= 1;
for (var i = 0; i < foldLines.length; i++) { for (var i = 0; i < foldLines.length; i++) {
cmp = foldLines[i].range.compareRange(range); var cmp = foldLines[i].range.compareRange(range);
// Range is before foldLine. No intersection. This means,
// there might be other foldLines that intersect.
if (cmp == 2) { if (cmp == 2) {
// Range is before foldLine. No intersection. This means,
// there might be other foldLines that intersect.
continue; continue;
} else }
// Range is after foldLine. There can't be any other foldLines then, else if (cmp == -2) {
// so let's give up. // Range is after foldLine. There can't be any other foldLines then,
if (cmp == -2) { // so let's give up.
break; break;
} }
folds = foldLines[i].folds; var folds = foldLines[i].folds;
for (var j = 0; j < folds.length; j++) { for (var j = 0; j < folds.length; j++) {
fold = folds[j]; var fold = folds[j];
cmp = fold.range.compareRange(range); cmp = fold.range.compareRange(range);
if (cmp == -2) { if (cmp == -2) {
break; break;
@ -11744,46 +11800,44 @@ function Folding() {
*/ */
this.getFoldStringAt = function(row, column, trim, foldLine) { this.getFoldStringAt = function(row, column, trim, foldLine) {
var foldLine = foldLine || this.getFoldLine(row); var foldLine = foldLine || this.getFoldLine(row);
if (!foldLine) { if (!foldLine)
return null; return null;
} else {
var fold, lastFold, cmp, str; var lastFold = {
lastFold = { end: { column: 0 }
end: { column: 0 } };
}; // TODO: Refactor to use getNextFoldTo function.
// TODO: Refactor to use getNextFoldTo function. for (var i = 0; i < foldLine.folds.length; i++) {
for (var i = 0; i < foldLine.folds.length; i++) { var fold = foldLine.folds[i];
fold = foldLine.folds[i]; var cmp = fold.range.compareEnd(row, column);
cmp = fold.range.compareEnd(row, column); if (cmp == -1) {
if (cmp == -1) { var str = this
str = this.getLine(fold.start.row). .getLine(fold.start.row)
substring(lastFold.end.column, fold.start.column); .substring(lastFold.end.column, fold.start.column);
break; break;
} else if (cmp == 0) {
return null;
}
lastFold = fold;
} }
if (!str) { else if (cmp == 0) {
str = this.getLine(fold.start.row). return null;
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;
} }
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) { this.getFoldLine = function(docRow, startFoldLine) {
var foldData = this.$foldData; var foldData = this.$foldData;
var i = 0; var i = 0;
if(startFoldLine) if (startFoldLine)
i = foldData.indexOf(startFoldLine); i = foldData.indexOf(startFoldLine);
if(i == -1) if (i == -1)
i = 0; i = 0;
for (i; i < foldData.length; i++) { for (i; i < foldData.length; i++) {
var foldLine = foldData[i]; var foldLine = foldData[i];
@ -11800,9 +11854,9 @@ function Folding() {
this.getNextFold = function(docRow, startFoldLine) { this.getNextFold = function(docRow, startFoldLine) {
var foldData = this.$foldData, ans; var foldData = this.$foldData, ans;
var i = 0; var i = 0;
if(startFoldLine) if (startFoldLine)
i = foldData.indexOf(startFoldLine); i = foldData.indexOf(startFoldLine);
if(i == -1) if (i == -1)
i = 0; i = 0;
for (i; i < foldData.length; i++) { for (i; i < foldData.length; i++) {
var foldLine = foldData[i]; var foldLine = foldData[i];
@ -11819,7 +11873,7 @@ function Folding() {
var foldLine = foldData[i], var foldLine = foldData[i],
end = foldLine.end.row, end = foldLine.end.row,
start = foldLine.start.row; start = foldLine.start.row;
if(end >= last) { if (end >= last) {
if(start < last) { if(start < last) {
if(start >= first) if(start >= first)
rowCount -= last-start; rowCount -= last-start;
@ -11852,76 +11906,52 @@ function Folding() {
* The new created Fold object or an existing fold object in case the * The new created Fold object or an existing fold object in case the
* passed in range fits an existing fold exactly. * passed in range fits an existing fold exactly.
*/ */
this.addFold = function(placeholder, startRow, startColumn, endRow, endColumn) { this.addFold = function(placeholder, range) {
var range;
var foldData = this.$foldData; var foldData = this.$foldData;
var foldRow = null;
var foldLine;
var fold;
var argsFold;
var folds;
var added = false; var added = false;
if (placeholder instanceof Fold) { if (placeholder instanceof Fold)
argsFold = placeholder; var fold = placeholder;
startRow = argsFold.range; else
placeholder = argsFold.placeholder; fold = new Fold(range, placeholder);
}
// Normalize parameters.
if (!(startRow instanceof Range)) {
range = new Range(startRow, startColumn, endRow, endColumn);
} else {
range = startRow;
startRow = range.start.row;
startColumn = range.start.column;
endRow = range.end.row;
endColumn = range.end.column;
}
var startRow = fold.start.row;
var startColumn = fold.start.column;
var endRow = fold.end.row;
var endColumn = fold.end.column;
// --- Some checking --- // --- Some checking ---
if (placeholder.length < 2) { if (fold.placeholder.length < 2)
throw "Placeholder has to be at least 2 characters"; throw "Placeholder has to be at least 2 characters";
}
if (startRow == endRow && endColumn - startColumn < 2) { if (startRow == endRow && endColumn - startColumn < 2)
throw "The range has to be at least 2 characters width"; throw "The range has to be at least 2 characters width";
}
fold = this.getFoldAt(startRow, startColumn, 1); var existingFold = this.getFoldAt(startRow, startColumn, 1);
if (fold if (
&& fold.range.isEnd(endRow, endColumn) existingFold
&& fold.range.isStart(startRow, startColumn)) && existingFold.range.isEnd(endRow, endColumn)
{ && existingFold.range.isStart(startRow, startColumn)
) {
return fold; return fold;
} }
fold = this.getFoldAt(startRow, startColumn, 1); existingFold = this.getFoldAt(startRow, startColumn, 1);
if (fold && !fold.range.isStart(startRow, startColumn)) { if (existingFold && !existingFold.range.isStart(startRow, startColumn))
throw "A fold can't start inside of an already existing fold"; throw "A fold can't start inside of an already existing fold";
}
fold = this.getFoldAt(endRow, endColumn, -1); existingFold = this.getFoldAt(endRow, endColumn, -1);
if (fold && !fold.range.isEnd(endRow, endColumn)) { if (existingFold && !existingFold.range.isEnd(endRow, endColumn))
throw "A fold can't end inside of an already existing fold"; throw "A fold can't end inside of an already existing fold";
}
if (endRow >= this.doc.getLength()) { if (endRow >= this.doc.getLength())
throw "End of fold is outside of the document."; throw "End of fold is outside of the document.";
}
if (endColumn > this.getLine(endRow).length if (endColumn > this.getLine(endRow).length || startColumn > this.getLine(startRow).length)
|| startColumn > this.getLine(startRow).length)
{
throw "End of fold is outside of the document."; throw "End of fold is outside of the document.";
}
// --- Start adding the fold ---
// Use the passed in fold or create a new one.
fold = argsFold || new Fold(range, placeholder);
// Check if there are folds in the range we create the new fold for. // Check if there are folds in the range we create the new fold for.
folds = this.getFoldsInRange(range); var folds = this.getFoldsInRange(fold.range);
if (folds.length > 0) { if (folds.length > 0) {
// Remove the folds from fold data. // Remove the folds from fold data.
this.removeFolds(folds); this.removeFolds(folds);
@ -11930,12 +11960,13 @@ function Folding() {
} }
for (var i = 0; i < foldData.length; i++) { for (var i = 0; i < foldData.length; i++) {
foldLine = foldData[i]; var foldLine = foldData[i];
if (endRow == foldLine.start.row) { if (endRow == foldLine.start.row) {
foldLine.addFold(fold); foldLine.addFold(fold);
added = true; added = true;
break; break;
} else if (startRow == foldLine.end.row) { }
else if (startRow == foldLine.end.row) {
foldLine.addFold(fold); foldLine.addFold(fold);
added = true; added = true;
if (!fold.sameRow) { if (!fold.sameRow) {
@ -11948,18 +11979,17 @@ function Folding() {
} }
} }
break; break;
} else if (endRow <= foldLine.start.row) { }
else if (endRow <= foldLine.start.row) {
break; break;
} }
} }
if (!added) { if (!added)
foldLine = this.$addFoldLine(new FoldLine(this.$foldData, fold)); foldLine = this.$addFoldLine(new FoldLine(this.$foldData, fold));
}
if (this.$useWrapMode) { if (this.$useWrapMode)
this.$updateWrapData(foldLine.start.row, foldLine.start.row); this.$updateWrapData(foldLine.start.row, foldLine.start.row);
}
// Notify that fold data has changed. // Notify that fold data has changed.
this.$modified = true; this.$modified = true;
@ -12403,6 +12433,84 @@ function FoldLine(foldData, folds) {
}).call(FoldLine.prototype); }).call(FoldLine.prototype);
exports.FoldLine = FoldLine; exports.FoldLine = FoldLine;
});/* vim:ts=4:sts=4:sw=4:
* ***** 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):
* Julian Viereck <julian DOT viereck AT gmail DOT com>
*
* 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('ace/edit_session/fold', ['require', 'exports', 'module' ], function(require, exports, module) {
/**
* 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 = [];
};
(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());
});
return fold;
};
}).call(Fold.prototype);
});/* vim:ts=4:sts=4:sw=4: });/* vim:ts=4:sts=4:sw=4:
* ***** BEGIN LICENSE BLOCK ***** * ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
@ -15215,6 +15323,7 @@ define("text/ace/css/editor.css", [], ".ace_editor {" +
" opacity: 0;" + " opacity: 0;" +
" background: transparent;" + " background: transparent;" +
" appearance: none;" + " appearance: none;" +
" -moz-appearance: none;" +
" border: none;" + " border: none;" +
" resize: none;" + " resize: none;" +
" outline: none;" + " outline: none;" +

File diff suppressed because one or more lines are too long

View file

@ -1 +1 @@
define("ace/keyboard/keybinding/vim",["require","exports","module","ace/keyboard/state_handler"],function(a,b,c){var d=a("ace/keyboard/state_handler").StateHandler,e=a("ace/keyboard/state_handler").matchCharacterOnly,f={start:[{key:"i",then:"insertMode"},{key:"a",exec:"gotoright",then:"insertMode"},{key:"shift-i",exec:"gotolinestart",then:"insertMode"},{key:"shift-a",exec:"gotolineend",then:"insertMode"},{key:"shift-c",exec:"removetolineend",then:"insertMode"},{key:"shift-r",exec:"overwrite",then:"replaceMode"},{regex:["([0-9]*)","(k|up)"],exec:"golineup",params:[{name:"times",match:1,type:"number",defaultValue:1}]},{regex:["([0-9]*)","(j|down|enter)"],exec:"golinedown",params:[{name:"times",match:1,type:"number",defaultValue:1}]},{regex:["([0-9]*)","(l|right)"],exec:"gotoright",params:[{name:"times",match:1,type:"number",defaultValue:1}]},{regex:["([0-9]*)","(h|left)"],exec:"gotoleft",params:[{name:"times",match:1,type:"number",defaultValue:1}]},{key:"shift-g",exec:"gotoend"},{key:"b",exec:"gotowordleft"},{key:"e",exec:"gotowordright"},{key:"x",exec:"del"},{key:"shift-x",exec:"backspace"},{key:"shift-d",exec:"removetolineend"},{comment:"Catch some keyboard input to stop it here",match:e}],insertMode:[{key:"esc",then:"start"}],replaceMode:[{key:"esc",exec:"overwrite",then:"start"}]};b.Vim=new d(f)}),define("ace/keyboard/state_handler",["require","exports","module"],function(a,b,c){function e(a){this.keymapping=this.$buildKeymappingRegex(a)}var d=!1;e.prototype={$buildKeymappingRegex:function(a){for(state in a)this.$buildBindingsRegex(a[state]);return a},$buildBindingsRegex:function(a){a.forEach(function(a){a.key?a.key=new RegExp("^"+a.key+"$"):Array.isArray(a.regex)?(a.key=new RegExp("^"+a.regex[1]+"$"),a.regex=new RegExp(a.regex.join("")+"$")):a.regex&&(a.regex=new RegExp(a.regex+"$"))})},$composeBuffer:function(a,b,c){if(a.state==null||a.buffer==null)a.state="start",a.buffer="";var d=[];b&1&&d.push("ctrl"),b&8&&d.push("command"),b&2&&d.push("option"),b&4&&d.push("shift"),c&&d.push(c);var e=d.join("-"),f=a.buffer+e;b!=2&&(a.buffer=f);return{bufferToUse:f,symbolicName:e}},$find:function(a,b,c,e,f){var g={};this.keymapping[a.state].some(function(h){var i;if(h.key&&!h.key.test(c))return!1;if(h.regex&&!(i=h.regex.exec(b)))return!1;if(h.match&&!h.match(b,e,f,c))return!1;if(h.disallowMatches)for(var j=0;j<h.disallowMatches.length;j++)if(!!i[h.disallowMatches[j]])return!1;if(h.exec){g.command=h.exec;if(h.params){var k;g.args={},h.params.forEach(function(a){a.match!=null&&i!=null?k=i[a.match]||a.defaultValue:k=a.defaultValue,a.type==="number"&&(k=parseInt(k)),g.args[a.name]=k})}a.buffer=""}h.then&&(a.state=h.then,a.buffer=""),g.command==null&&(g.command="null"),d&&console.log("KeyboardStateMapper#find",h);return!0});if(g.command)return g;a.buffer="";return!1},handleKeyboard:function(a,b,c){if(b!=0&&(c==""||c==String.fromCharCode(0)))return null;var e=this.$composeBuffer(a,b,c),f=e.bufferToUse,g=e.symbolicName;e=this.$find(a,f,g,b,c),d&&console.log("KeyboardStateMapper#match",f,g,e);return e}},b.matchCharacterOnly=function(a,b,c,d){return b==0?!0:b==4&&c.length==1?!0:!1},b.StateHandler=e}) define("ace/keyboard/keybinding/vim",["require","exports","module","ace/keyboard/state_handler"],function(a,b,c){var d=a("ace/keyboard/state_handler").StateHandler,e=a("ace/keyboard/state_handler").matchCharacterOnly,f={start:[{key:"i",then:"insertMode"},{key:"d",then:"deleteMode"},{key:"a",exec:"gotoright",then:"insertMode"},{key:"shift-i",exec:"gotolinestart",then:"insertMode"},{key:"shift-a",exec:"gotolineend",then:"insertMode"},{key:"shift-c",exec:"removetolineend",then:"insertMode"},{key:"shift-r",exec:"overwrite",then:"replaceMode"},{regex:["([0-9]*)","(k|up)"],exec:"golineup",params:[{name:"times",match:1,type:"number",defaultValue:1}]},{regex:["([0-9]*)","(j|down|enter)"],exec:"golinedown",params:[{name:"times",match:1,type:"number",defaultValue:1}]},{regex:["([0-9]*)","(l|right)"],exec:"gotoright",params:[{name:"times",match:1,type:"number",defaultValue:1}]},{regex:["([0-9]*)","(h|left)"],exec:"gotoleft",params:[{name:"times",match:1,type:"number",defaultValue:1}]},{key:"shift-g",exec:"gotoend"},{key:"b",exec:"gotowordleft"},{key:"e",exec:"gotowordright"},{key:"x",exec:"del"},{key:"shift-x",exec:"backspace"},{key:"shift-d",exec:"removetolineend"},{comment:"Catch some keyboard input to stop it here",match:e}],insertMode:[{key:"esc",then:"start"}],replaceMode:[{key:"esc",exec:"overwrite",then:"start"}],deleteMode:[{key:"d",exec:"removeline",then:"start"}]};b.Vim=new d(f)}),define("ace/keyboard/state_handler",["require","exports","module"],function(a,b,c){function e(a){this.keymapping=this.$buildKeymappingRegex(a)}var d=!1;e.prototype={$buildKeymappingRegex:function(a){for(state in a)this.$buildBindingsRegex(a[state]);return a},$buildBindingsRegex:function(a){a.forEach(function(a){a.key?a.key=new RegExp("^"+a.key+"$"):Array.isArray(a.regex)?(a.key=new RegExp("^"+a.regex[1]+"$"),a.regex=new RegExp(a.regex.join("")+"$")):a.regex&&(a.regex=new RegExp(a.regex+"$"))})},$composeBuffer:function(a,b,c){if(a.state==null||a.buffer==null)a.state="start",a.buffer="";var d=[];b&1&&d.push("ctrl"),b&8&&d.push("command"),b&2&&d.push("option"),b&4&&d.push("shift"),c&&d.push(c);var e=d.join("-"),f=a.buffer+e;b!=2&&(a.buffer=f);return{bufferToUse:f,symbolicName:e}},$find:function(a,b,c,e,f){var g={};this.keymapping[a.state].some(function(h){var i;if(h.key&&!h.key.test(c))return!1;if(h.regex&&!(i=h.regex.exec(b)))return!1;if(h.match&&!h.match(b,e,f,c))return!1;if(h.disallowMatches)for(var j=0;j<h.disallowMatches.length;j++)if(!!i[h.disallowMatches[j]])return!1;if(h.exec){g.command=h.exec;if(h.params){var k;g.args={},h.params.forEach(function(a){a.match!=null&&i!=null?k=i[a.match]||a.defaultValue:k=a.defaultValue,a.type==="number"&&(k=parseInt(k)),g.args[a.name]=k})}a.buffer=""}h.then&&(a.state=h.then,a.buffer=""),g.command==null&&(g.command="null"),d&&console.log("KeyboardStateMapper#find",h);return!0});if(g.command)return g;a.buffer="";return!1},handleKeyboard:function(a,b,c){if(b!=0&&(c==""||c==String.fromCharCode(0)))return null;var e=this.$composeBuffer(a,b,c),f=e.bufferToUse,g=e.symbolicName;e=this.$find(a,f,g,b,c),d&&console.log("KeyboardStateMapper#match",f,g,e);return e}},b.matchCharacterOnly=function(a,b,c,d){return b==0?!0:b==4&&c.length==1?!0:!1},b.StateHandler=e})

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -5740,6 +5740,10 @@ var Editor =function(renderer, session) {
} }
this.textInput.focus(); this.textInput.focus();
}; };
this.isFocused = function() {
return this.textInput.isFocused();
};
this.blur = function() { this.blur = function() {
this.textInput.blur(); this.textInput.blur();
@ -6984,10 +6988,11 @@ exports.TextInput = TextInput;
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
__ace_shadowed__.define('ace/mouse_handler', ['require', 'exports', 'module' , 'pilot/event', 'pilot/dom'], function(require, exports, module) { __ace_shadowed__.define('ace/mouse_handler', ['require', 'exports', 'module' , 'pilot/event', 'pilot/dom', 'pilot/browser_focus'], function(require, exports, module) {
var event = require("pilot/event"); var event = require("pilot/event");
var dom = require("pilot/dom"); var dom = require("pilot/dom");
var BrowserFocus = require("pilot/browser_focus").BrowserFocus;
var STATE_UNKNOWN = 0; var STATE_UNKNOWN = 0;
var STATE_SELECT = 1; var STATE_SELECT = 1;
@ -6998,6 +7003,8 @@ var DRAG_OFFSET = 5; // pixels
var MouseHandler = function(editor) { var MouseHandler = function(editor) {
this.editor = editor; this.editor = editor;
this.browserFocus = new BrowserFocus();
event.addListener(editor.container, "mousedown", function(e) { event.addListener(editor.container, "mousedown", function(e) {
editor.focus(); editor.focus();
return event.preventDefault(e); return event.preventDefault(e);
@ -7038,6 +7045,15 @@ var MouseHandler = function(editor) {
}; };
this.onMouseDown = function(e) { this.onMouseDown = function(e) {
// if this click caused the editor to be focused ignore the click
// for selection and cursor placement
if (
!this.browserFocus.isFocused()
|| new Date().getTime() - this.browserFocus.lastFocus < 20
|| !this.editor.isFocused()
)
return;
var pageX = event.getDocumentX(e); var pageX = event.getDocumentX(e);
var pageY = event.getDocumentY(e); var pageY = event.getDocumentY(e);
var pos = this.$getEventPosition(e); var pos = this.$getEventPosition(e);
@ -7247,6 +7263,97 @@ var MouseHandler = function(editor) {
exports.MouseHandler = MouseHandler; exports.MouseHandler = MouseHandler;
}); });
/* vim:ts=4:sts=4:sw=4:
* ***** 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>
* Irakli Gozalishvili <rfobic@gmail.com> (http://jeditoolkit.com)
* Julian Viereck <julian.viereck@gmail.com>
*
* 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 ***** */
__ace_shadowed__.define('pilot/browser_focus', ['require', 'exports', 'module' , 'pilot/oop', 'pilot/event', 'pilot/event_emitter'], function(require, exports, module) {
var oop = require("pilot/oop");
var event = require("pilot/event");
var EventEmitter = require("pilot/event_emitter").EventEmitter;
/**
* This class keeps track of the focus state of the given window.
* Focus changes for example when the user switches a browser tab,
* goes to the location bar or switches to another application.
*/
var BrowserFocus = function(win) {
win = win || window;
this.lastFocus = new Date().getTime();
this._isFocused = true;
var _self = this;
event.addListener(win, "blur", function(e) {
_self._setFocused(false);
});
event.addListener(win, "focus", function(e) {
_self._setFocused(true);
});
};
(function(){
oop.implement(this, EventEmitter);
this.isFocused = function() {
return this._isFocused;
};
this._setFocused = function(isFocused) {
if (this._isFocused == isFocused)
return;
if (isFocused)
this.lastFocus = new Date().getTime();
this._isFocused = isFocused;
this._emit("changeFocus");
};
}).call(BrowserFocus.prototype);
exports.BrowserFocus = BrowserFocus;
});
/* ***** BEGIN LICENSE BLOCK ***** /* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
* *
@ -7798,7 +7905,6 @@ var EditSession = function(text, mode) {
}); });
return str; return str;
} }
this.$docChangeCounter = 0;
if (text instanceof Document) { if (text instanceof Document) {
this.setDocument(text); this.setDocument(text);
@ -7824,8 +7930,6 @@ var EditSession = function(text, mode) {
this.doc = doc; this.doc = doc;
doc.on("change", this.onChange.bind(this)); doc.on("change", this.onChange.bind(this));
doc.on("changeStart", this.onChangeStart.bind(this));
doc.on("changeEnd", this.onChangeEnd.bind(this));
this.on("changeFold", this.onChangeFold.bind(this)); this.on("changeFold", this.onChangeFold.bind(this));
}; };
@ -7833,10 +7937,6 @@ var EditSession = function(text, mode) {
return this.doc; return this.doc;
}; };
this.onChangeStart = function() {
this.$docChangeCounter ++;
};
this.$resetRowCache = function(row) { this.$resetRowCache = function(row) {
if (row == 0) { if (row == 0) {
this.$rowCache = []; this.$rowCache = [];
@ -7849,29 +7949,6 @@ var EditSession = function(text, mode) {
return; return;
} }
} }
}
this.onChangeEnd = function() {
this.$docChangeCounter --;
if (this.$docChangeCounter == 0
&& !this.$fromUndo && this.$undoManager)
{
if (this.$deltasFold.length) {
this.$deltas.push({
group: "fold",
deltas: this.$deltasFold
});
this.$deltasFold = [];
}
if (this.$deltasDoc) {
this.$deltas.push({
group: "doc",
deltas: this.$deltasDoc
});
this.$deltasDoc = [];
}
this.$informUndoManager.schedule();
}
}; };
this.onChangeFold = function(e) { this.onChangeFold = function(e) {
@ -7894,6 +7971,8 @@ var EditSession = function(text, mode) {
folds: removedFolds folds: removedFolds
}); });
} }
this.$informUndoManager.schedule();
} }
this.bgTokenizer.start(delta.range.start.row); this.bgTokenizer.start(delta.range.start.row);
@ -7902,6 +7981,9 @@ var EditSession = function(text, mode) {
this.setValue = function(text) { this.setValue = function(text) {
this.doc.setValue(text); this.doc.setValue(text);
this.selection.moveCursorTo(0, 0);
this.selection.clearSelection();
this.$resetRowCache(0); this.$resetRowCache(0);
this.$deltas = []; this.$deltas = [];
this.$deltasDoc = []; this.$deltasDoc = [];
@ -7933,19 +8015,37 @@ var EditSession = function(text, mode) {
this.$deltasDoc = []; this.$deltasDoc = [];
this.$deltasFold = []; this.$deltasFold = [];
if (this.$informUndoManager) { if (this.$informUndoManager)
this.$informUndoManager.cancel(); this.$informUndoManager.cancel();
}
if (undoManager) { if (undoManager) {
var self = this; var self = this;
this.$syncInformUndoManager = function() { this.$syncInformUndoManager = function() {
self.$informUndoManager.cancel(); self.$informUndoManager.cancel();
if (self.$deltas.length > 0)
undoManager.execute({ if (self.$deltasFold.length) {
action : "aceupdate", self.$deltas.push({
args : [self.$deltas, self] group: "fold",
deltas: self.$deltasFold
}); });
self.$deltasFold = [];
}
if (self.$deltasDoc.length) {
self.$deltas.push({
group: "doc",
deltas: self.$deltasDoc
});
self.$deltasDoc = [];
}
if (self.$deltas.length > 0) {
undoManager.execute({
action: "aceupdate",
args: [self.$deltas, self]
});
}
self.$deltas = []; self.$deltas = [];
} }
this.$informUndoManager = this.$informUndoManager =
@ -9157,14 +9257,17 @@ var EditSession = function(text, mode) {
var rowLength = 0; var rowLength = 0;
var rowCache = this.$rowCache; var rowCache = this.$rowCache;
var doCache = !rowCache.length;
for (var i = 0; i < rowCache.length; i++) { for (var i = 0; i < rowCache.length; i++) {
if (rowCache[i].screenRow < screenRow) { if (rowCache[i].screenRow < screenRow) {
row = rowCache[i].screenRow; row = rowCache[i].screenRow;
docRow = rowCache[i].docRow; docRow = rowCache[i].docRow;
doCache = i == rowCache.length - 1; }
else {
break;
} }
} }
var doCache = !rowCache.length || i == rowCache.length;
// clamp row before clamping column, for selection on last line // clamp row before clamping column, for selection on last line
var maxRow = this.getLength() - 1; var maxRow = this.getLength() - 1;
@ -9172,12 +9275,6 @@ var EditSession = function(text, mode) {
var foldStart = foldLine ? foldLine.start.row : Infinity; var foldStart = foldLine ? foldLine.start.row : Infinity;
while (row <= screenRow) { while (row <= screenRow) {
if (doCache) {
rowCache.push({
docRow: docRow,
screenRow: row
});
}
rowLength = this.getRowLength(docRow); rowLength = this.getRowLength(docRow);
if (row + rowLength - 1 >= screenRow || docRow >= maxRow) { if (row + rowLength - 1 >= screenRow || docRow >= maxRow) {
break; break;
@ -9190,6 +9287,12 @@ var EditSession = function(text, mode) {
foldStart = foldLine ? foldLine.start.row : Infinity; foldStart = foldLine ? foldLine.start.row : Infinity;
} }
} }
if (doCache) {
rowCache.push({
docRow: docRow,
screenRow: row
});
}
} }
if (foldLine && foldLine.start.row <= docRow) if (foldLine && foldLine.start.row <= docRow)
@ -9274,15 +9377,16 @@ var EditSession = function(text, mode) {
var rowEnd, row = 0; var rowEnd, row = 0;
var rowCache = this.$rowCache; var rowCache = this.$rowCache;
//
var doCache = !rowCache.length;
for (var i = 0; i < rowCache.length; i++) { for (var i = 0; i < rowCache.length; i++) {
if (rowCache[i].docRow < docRow) { if (rowCache[i].docRow < docRow) {
screenRow = rowCache[i].screenRow; screenRow = rowCache[i].screenRow;
row = rowCache[i].docRow; row = rowCache[i].docRow;
doCache = i == rowCache.length - 1; } else {
break;
} }
} }
var doCache = !rowCache.length || i == rowCache.length;
var foldLine = this.getNextFold(row); var foldLine = this.getNextFold(row);
var foldStart = foldLine ?foldLine.start.row :Infinity; var foldStart = foldLine ?foldLine.start.row :Infinity;
@ -9294,18 +9398,20 @@ var EditSession = function(text, mode) {
break; break;
foldLine = this.getNextFold(rowEnd); foldLine = this.getNextFold(rowEnd);
foldStart = foldLine ?foldLine.start.row :Infinity; foldStart = foldLine ?foldLine.start.row :Infinity;
} else { }
else {
rowEnd = row + 1; rowEnd = row + 1;
} }
screenRow += this.getRowLength(row);
row = rowEnd;
if (doCache) { if (doCache) {
rowCache.push({ rowCache.push({
docRow: row, docRow: row,
screenRow: screenRow screenRow: screenRow
}); });
} }
screenRow += this.getRowLength(row);
row = rowEnd;
} }
// Calculate the text line that is displayed in docRow on the screen. // Calculate the text line that is displayed in docRow on the screen.
@ -9462,6 +9568,13 @@ var lang = require("pilot/lang");
var EventEmitter = require("pilot/event_emitter").EventEmitter; var EventEmitter = require("pilot/event_emitter").EventEmitter;
var Range = require("ace/range").Range; var Range = require("ace/range").Range;
/**
* Keeps cursor position and the text selection of an edit session.
*
* The row/columns used in the selection are in document coordinates
* representing ths coordinates as thez appear in the document
* before applying soft wrap and folding.
*/
var Selection = function(session) { var Selection = function(session) {
this.session = session; this.session = session;
this.doc = session.getDocument(); this.doc = session.getDocument();
@ -10957,14 +11070,12 @@ var Document = function(text) {
var firstLine = lines.splice(0, 1)[0]; var firstLine = lines.splice(0, 1)[0];
var lastLine = lines.length == 0 ? null : lines.splice(lines.length - 1, 1)[0]; var lastLine = lines.length == 0 ? null : lines.splice(lines.length - 1, 1)[0];
this._dispatchEvent("changeStart");
position = this.insertInLine(position, firstLine); position = this.insertInLine(position, firstLine);
if (lastLine !== null) { if (lastLine !== null) {
position = this.insertNewLine(position); // terminate first line position = this.insertNewLine(position); // terminate first line
position = this.insertLines(position.row, lines); position = this.insertLines(position.row, lines);
position = this.insertInLine(position, lastLine || ""); position = this.insertInLine(position, lastLine || "");
} }
this._dispatchEvent("changeEnd");
return position; return position;
}; };
@ -10976,7 +11087,6 @@ var Document = function(text) {
args.push.apply(args, lines); args.push.apply(args, lines);
this.$lines.splice.apply(this.$lines, args); this.$lines.splice.apply(this.$lines, args);
this._dispatchEvent("changeStart");
var range = new Range(row, 0, row + lines.length, 0); var range = new Range(row, 0, row + lines.length, 0);
var delta = { var delta = {
action: "insertLines", action: "insertLines",
@ -10984,7 +11094,6 @@ var Document = function(text) {
lines: lines lines: lines
}; };
this._dispatchEvent("change", { data: delta }); this._dispatchEvent("change", { data: delta });
this._dispatchEvent("changeEnd");
return range.end; return range.end;
}, },
@ -10992,7 +11101,6 @@ var Document = function(text) {
position = this.$clipPosition(position); position = this.$clipPosition(position);
var line = this.$lines[position.row] || ""; var line = this.$lines[position.row] || "";
this._dispatchEvent("changeStart");
this.$lines[position.row] = line.substring(0, position.column); this.$lines[position.row] = line.substring(0, position.column);
this.$lines.splice(position.row + 1, 0, line.substring(position.column, line.length)); this.$lines.splice(position.row + 1, 0, line.substring(position.column, line.length));
@ -11007,7 +11115,6 @@ var Document = function(text) {
text: this.getNewLineCharacter() text: this.getNewLineCharacter()
}; };
this._dispatchEvent("change", { data: delta }); this._dispatchEvent("change", { data: delta });
this._dispatchEvent("changeEnd");
return end; return end;
}; };
@ -11018,7 +11125,6 @@ var Document = function(text) {
var line = this.$lines[position.row] || ""; var line = this.$lines[position.row] || "";
this._dispatchEvent("changeStart");
this.$lines[position.row] = line.substring(0, position.column) + text this.$lines[position.row] = line.substring(0, position.column) + text
+ line.substring(position.column); + line.substring(position.column);
@ -11033,7 +11139,6 @@ var Document = function(text) {
text: text text: text
}; };
this._dispatchEvent("change", { data: delta }); this._dispatchEvent("change", { data: delta });
this._dispatchEvent("changeEnd");
return end; return end;
}; };
@ -11049,7 +11154,6 @@ var Document = function(text) {
var firstRow = range.start.row; var firstRow = range.start.row;
var lastRow = range.end.row; var lastRow = range.end.row;
this._dispatchEvent("changeStart");
if (range.isMultiLine()) { if (range.isMultiLine()) {
var firstFullRow = range.start.column == 0 ? firstRow : firstRow + 1; var firstFullRow = range.start.column == 0 ? firstRow : firstRow + 1;
var lastFullRow = lastRow - 1; var lastFullRow = lastRow - 1;
@ -11068,7 +11172,6 @@ var Document = function(text) {
else { else {
this.removeInLine(firstRow, range.start.column, range.end.column); this.removeInLine(firstRow, range.start.column, range.end.column);
} }
this._dispatchEvent("changeEnd");
return range.start; return range.start;
}; };
@ -11080,7 +11183,6 @@ var Document = function(text) {
var line = this.getLine(row); var line = this.getLine(row);
var removed = line.substring(startColumn, endColumn); var removed = line.substring(startColumn, endColumn);
var newLine = line.substring(0, startColumn) + line.substring(endColumn, line.length); var newLine = line.substring(0, startColumn) + line.substring(endColumn, line.length);
this._dispatchEvent("changeStart");
this.$lines.splice(row, 1, newLine); this.$lines.splice(row, 1, newLine);
var delta = { var delta = {
@ -11089,7 +11191,6 @@ var Document = function(text) {
text: removed text: removed
}; };
this._dispatchEvent("change", { data: delta }); this._dispatchEvent("change", { data: delta });
this._dispatchEvent("changeEnd");
return range.start; return range.start;
}; };
@ -11101,7 +11202,6 @@ var Document = function(text) {
* @return {String[]} The removed lines * @return {String[]} The removed lines
*/ */
this.removeLines = function(firstRow, lastRow) { this.removeLines = function(firstRow, lastRow) {
this._dispatchEvent("changeStart");
var range = new Range(firstRow, 0, lastRow + 1, 0); var range = new Range(firstRow, 0, lastRow + 1, 0);
var removed = this.$lines.splice(firstRow, lastRow - firstRow + 1); var removed = this.$lines.splice(firstRow, lastRow - firstRow + 1);
@ -11112,7 +11212,6 @@ var Document = function(text) {
lines: removed lines: removed
}; };
this._dispatchEvent("change", { data: delta }); this._dispatchEvent("change", { data: delta });
this._dispatchEvent("changeEnd");
return removed; return removed;
}; };
@ -11123,7 +11222,6 @@ var Document = function(text) {
var range = new Range(row, firstLine.length, row+1, 0); var range = new Range(row, firstLine.length, row+1, 0);
var line = firstLine + secondLine; var line = firstLine + secondLine;
this._dispatchEvent("changeStart");
this.$lines.splice(row, 2, line); this.$lines.splice(row, 2, line);
var delta = { var delta = {
@ -11132,7 +11230,6 @@ var Document = function(text) {
text: this.getNewLineCharacter() text: this.getNewLineCharacter()
}; };
this._dispatchEvent("change", { data: delta }); this._dispatchEvent("change", { data: delta });
this._dispatchEvent("changeEnd");
}; };
this.replace = function(range, text) { this.replace = function(range, text) {
@ -11144,7 +11241,6 @@ var Document = function(text) {
if (text == this.getTextRange(range)) if (text == this.getTextRange(range))
return range.end; return range.end;
this._dispatchEvent("changeStart");
this.remove(range); this.remove(range);
if (text) { if (text) {
var end = this.insert(range.start, text); var end = this.insert(range.start, text);
@ -11152,7 +11248,6 @@ var Document = function(text) {
else { else {
end = range.start; end = range.start;
} }
this._dispatchEvent("changeEnd");
return end; return end;
}; };
@ -11598,44 +11693,11 @@ exports.BackgroundTokenizer = BackgroundTokenizer;
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
__ace_shadowed__.define('ace/edit_session/folding', ['require', 'exports', 'module' , 'ace/range', 'ace/edit_session/fold_line'], function(require, exports, module) { __ace_shadowed__.define('ace/edit_session/folding', ['require', 'exports', 'module' , 'ace/range', 'ace/edit_session/fold_line', 'ace/edit_session/fold'], function(require, exports, module) {
var Range = require("ace/range").Range; var Range = require("ace/range").Range;
var FoldLine = require("ace/edit_session/fold_line").FoldLine; var FoldLine = require("ace/edit_session/fold_line").FoldLine;
var Fold = require("ace/edit_session/fold").Fold;
/**
* Simple fold-data struct.
**/
function Fold(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 = [];
}
Fold.prototype.toString = function() {
return '"' + this.placeholder + '" ' + this.range.toString();
}
Fold.prototype.setFoldLine = function(foldLine) {
this.foldLine = foldLine;
this.subFolds.forEach(function(fold) {
fold.setFoldLine(foldLine);
});
}
Fold.prototype.clone = function() {
var range = this.range.clone();
var fold = new Fold(range, this.placeholder);
this.subFolds.forEach(function(subFold) {
fold.subFolds.push(subFold.clone());
});
return fold;
}
function Folding() { function Folding() {
/** /**
@ -11645,25 +11707,22 @@ function Folding() {
*/ */
this.getFoldAt = function(row, column, side) { this.getFoldAt = function(row, column, side) {
var foldLine = this.getFoldLine(row); var foldLine = this.getFoldLine(row);
if (foldLine) { if (!foldLine)
var folds = foldLine.folds,
fold;
for (var i = 0; i < folds.length; i++) {
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;
}
}
} else {
return null; 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 * Returns all folds in the given range. Note, that this will return folds
@ -11671,33 +11730,30 @@ function Folding() {
*/ */
this.getFoldsInRange = function(range) { this.getFoldsInRange = function(range) {
range = range.clone(); range = range.clone();
var start = range.start, var start = range.start;
end = range.end; var end = range.end;
var foldLines = this.$foldData, var foldLines = this.$foldData;
folds, var foundFolds = [];
fold;
var cmp,
foundFolds = [];
start.column += 1; start.column += 1;
end.column -= 1; end.column -= 1;
for (var i = 0; i < foldLines.length; i++) { for (var i = 0; i < foldLines.length; i++) {
cmp = foldLines[i].range.compareRange(range); var cmp = foldLines[i].range.compareRange(range);
// Range is before foldLine. No intersection. This means,
// there might be other foldLines that intersect.
if (cmp == 2) { if (cmp == 2) {
// Range is before foldLine. No intersection. This means,
// there might be other foldLines that intersect.
continue; continue;
} else }
// Range is after foldLine. There can't be any other foldLines then, else if (cmp == -2) {
// so let's give up. // Range is after foldLine. There can't be any other foldLines then,
if (cmp == -2) { // so let's give up.
break; break;
} }
folds = foldLines[i].folds; var folds = foldLines[i].folds;
for (var j = 0; j < folds.length; j++) { for (var j = 0; j < folds.length; j++) {
fold = folds[j]; var fold = folds[j];
cmp = fold.range.compareRange(range); cmp = fold.range.compareRange(range);
if (cmp == -2) { if (cmp == -2) {
break; break;
@ -11733,46 +11789,44 @@ function Folding() {
*/ */
this.getFoldStringAt = function(row, column, trim, foldLine) { this.getFoldStringAt = function(row, column, trim, foldLine) {
var foldLine = foldLine || this.getFoldLine(row); var foldLine = foldLine || this.getFoldLine(row);
if (!foldLine) { if (!foldLine)
return null; return null;
} else {
var fold, lastFold, cmp, str; var lastFold = {
lastFold = { end: { column: 0 }
end: { column: 0 } };
}; // TODO: Refactor to use getNextFoldTo function.
// TODO: Refactor to use getNextFoldTo function. for (var i = 0; i < foldLine.folds.length; i++) {
for (var i = 0; i < foldLine.folds.length; i++) { var fold = foldLine.folds[i];
fold = foldLine.folds[i]; var cmp = fold.range.compareEnd(row, column);
cmp = fold.range.compareEnd(row, column); if (cmp == -1) {
if (cmp == -1) { var str = this
str = this.getLine(fold.start.row). .getLine(fold.start.row)
substring(lastFold.end.column, fold.start.column); .substring(lastFold.end.column, fold.start.column);
break; break;
} else if (cmp == 0) {
return null;
}
lastFold = fold;
} }
if (!str) { else if (cmp == 0) {
str = this.getLine(fold.start.row). return null;
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;
} }
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) { this.getFoldLine = function(docRow, startFoldLine) {
var foldData = this.$foldData; var foldData = this.$foldData;
var i = 0; var i = 0;
if(startFoldLine) if (startFoldLine)
i = foldData.indexOf(startFoldLine); i = foldData.indexOf(startFoldLine);
if(i == -1) if (i == -1)
i = 0; i = 0;
for (i; i < foldData.length; i++) { for (i; i < foldData.length; i++) {
var foldLine = foldData[i]; var foldLine = foldData[i];
@ -11789,9 +11843,9 @@ function Folding() {
this.getNextFold = function(docRow, startFoldLine) { this.getNextFold = function(docRow, startFoldLine) {
var foldData = this.$foldData, ans; var foldData = this.$foldData, ans;
var i = 0; var i = 0;
if(startFoldLine) if (startFoldLine)
i = foldData.indexOf(startFoldLine); i = foldData.indexOf(startFoldLine);
if(i == -1) if (i == -1)
i = 0; i = 0;
for (i; i < foldData.length; i++) { for (i; i < foldData.length; i++) {
var foldLine = foldData[i]; var foldLine = foldData[i];
@ -11808,7 +11862,7 @@ function Folding() {
var foldLine = foldData[i], var foldLine = foldData[i],
end = foldLine.end.row, end = foldLine.end.row,
start = foldLine.start.row; start = foldLine.start.row;
if(end >= last) { if (end >= last) {
if(start < last) { if(start < last) {
if(start >= first) if(start >= first)
rowCount -= last-start; rowCount -= last-start;
@ -11841,76 +11895,52 @@ function Folding() {
* The new created Fold object or an existing fold object in case the * The new created Fold object or an existing fold object in case the
* passed in range fits an existing fold exactly. * passed in range fits an existing fold exactly.
*/ */
this.addFold = function(placeholder, startRow, startColumn, endRow, endColumn) { this.addFold = function(placeholder, range) {
var range;
var foldData = this.$foldData; var foldData = this.$foldData;
var foldRow = null;
var foldLine;
var fold;
var argsFold;
var folds;
var added = false; var added = false;
if (placeholder instanceof Fold) { if (placeholder instanceof Fold)
argsFold = placeholder; var fold = placeholder;
startRow = argsFold.range; else
placeholder = argsFold.placeholder; fold = new Fold(range, placeholder);
}
// Normalize parameters.
if (!(startRow instanceof Range)) {
range = new Range(startRow, startColumn, endRow, endColumn);
} else {
range = startRow;
startRow = range.start.row;
startColumn = range.start.column;
endRow = range.end.row;
endColumn = range.end.column;
}
var startRow = fold.start.row;
var startColumn = fold.start.column;
var endRow = fold.end.row;
var endColumn = fold.end.column;
// --- Some checking --- // --- Some checking ---
if (placeholder.length < 2) { if (fold.placeholder.length < 2)
throw "Placeholder has to be at least 2 characters"; throw "Placeholder has to be at least 2 characters";
}
if (startRow == endRow && endColumn - startColumn < 2) { if (startRow == endRow && endColumn - startColumn < 2)
throw "The range has to be at least 2 characters width"; throw "The range has to be at least 2 characters width";
}
fold = this.getFoldAt(startRow, startColumn, 1); var existingFold = this.getFoldAt(startRow, startColumn, 1);
if (fold if (
&& fold.range.isEnd(endRow, endColumn) existingFold
&& fold.range.isStart(startRow, startColumn)) && existingFold.range.isEnd(endRow, endColumn)
{ && existingFold.range.isStart(startRow, startColumn)
) {
return fold; return fold;
} }
fold = this.getFoldAt(startRow, startColumn, 1); existingFold = this.getFoldAt(startRow, startColumn, 1);
if (fold && !fold.range.isStart(startRow, startColumn)) { if (existingFold && !existingFold.range.isStart(startRow, startColumn))
throw "A fold can't start inside of an already existing fold"; throw "A fold can't start inside of an already existing fold";
}
fold = this.getFoldAt(endRow, endColumn, -1); existingFold = this.getFoldAt(endRow, endColumn, -1);
if (fold && !fold.range.isEnd(endRow, endColumn)) { if (existingFold && !existingFold.range.isEnd(endRow, endColumn))
throw "A fold can't end inside of an already existing fold"; throw "A fold can't end inside of an already existing fold";
}
if (endRow >= this.doc.getLength()) { if (endRow >= this.doc.getLength())
throw "End of fold is outside of the document."; throw "End of fold is outside of the document.";
}
if (endColumn > this.getLine(endRow).length if (endColumn > this.getLine(endRow).length || startColumn > this.getLine(startRow).length)
|| startColumn > this.getLine(startRow).length)
{
throw "End of fold is outside of the document."; throw "End of fold is outside of the document.";
}
// --- Start adding the fold ---
// Use the passed in fold or create a new one.
fold = argsFold || new Fold(range, placeholder);
// Check if there are folds in the range we create the new fold for. // Check if there are folds in the range we create the new fold for.
folds = this.getFoldsInRange(range); var folds = this.getFoldsInRange(fold.range);
if (folds.length > 0) { if (folds.length > 0) {
// Remove the folds from fold data. // Remove the folds from fold data.
this.removeFolds(folds); this.removeFolds(folds);
@ -11919,12 +11949,13 @@ function Folding() {
} }
for (var i = 0; i < foldData.length; i++) { for (var i = 0; i < foldData.length; i++) {
foldLine = foldData[i]; var foldLine = foldData[i];
if (endRow == foldLine.start.row) { if (endRow == foldLine.start.row) {
foldLine.addFold(fold); foldLine.addFold(fold);
added = true; added = true;
break; break;
} else if (startRow == foldLine.end.row) { }
else if (startRow == foldLine.end.row) {
foldLine.addFold(fold); foldLine.addFold(fold);
added = true; added = true;
if (!fold.sameRow) { if (!fold.sameRow) {
@ -11937,18 +11968,17 @@ function Folding() {
} }
} }
break; break;
} else if (endRow <= foldLine.start.row) { }
else if (endRow <= foldLine.start.row) {
break; break;
} }
} }
if (!added) { if (!added)
foldLine = this.$addFoldLine(new FoldLine(this.$foldData, fold)); foldLine = this.$addFoldLine(new FoldLine(this.$foldData, fold));
}
if (this.$useWrapMode) { if (this.$useWrapMode)
this.$updateWrapData(foldLine.start.row, foldLine.start.row); this.$updateWrapData(foldLine.start.row, foldLine.start.row);
}
// Notify that fold data has changed. // Notify that fold data has changed.
this.$modified = true; this.$modified = true;
@ -12392,6 +12422,84 @@ function FoldLine(foldData, folds) {
}).call(FoldLine.prototype); }).call(FoldLine.prototype);
exports.FoldLine = FoldLine; exports.FoldLine = FoldLine;
});/* vim:ts=4:sts=4:sw=4:
* ***** 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):
* Julian Viereck <julian DOT viereck AT gmail DOT com>
*
* 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 ***** */
__ace_shadowed__.define('ace/edit_session/fold', ['require', 'exports', 'module' ], function(require, exports, module) {
/**
* 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 = [];
};
(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());
});
return fold;
};
}).call(Fold.prototype);
});/* vim:ts=4:sts=4:sw=4: });/* vim:ts=4:sts=4:sw=4:
* ***** BEGIN LICENSE BLOCK ***** * ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
@ -15204,6 +15312,7 @@ __ace_shadowed__.define("text!ace/css/editor.css", [], ".ace_editor {" +
" opacity: 0;" + " opacity: 0;" +
" background: transparent;" + " background: transparent;" +
" appearance: none;" + " appearance: none;" +
" -moz-appearance: none;" +
" border: none;" + " border: none;" +
" resize: none;" + " resize: none;" +
" outline: none;" + " outline: none;" +

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long