rebased the branch, moved the moveText() from Document to EditSession, and removed the 'move' change event, which is no longer needed given the fixes in UndoManager.

This commit is contained in:
Mihai Sucan 2011-02-18 14:53:44 +02:00
commit 44846b4983
5 changed files with 44 additions and 71 deletions

View file

@ -1,5 +1,4 @@
/* vim:ts=4:sts=4:sw=4:
* ***** BEGIN LICENSE BLOCK *****
/* ***** 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
@ -71,9 +70,6 @@ var Anchor = exports.Anchor = function(doc, row, column) {
this.onChange = function(e) {
var delta = e.data;
if (delta.isMeta)
return;
var range = delta.range;
if (range.start.row == range.end.row && range.start.row != this.row)

View file

@ -1,5 +1,4 @@
/* vim:ts=4:sts=4:sw=4:
* ***** BEGIN LICENSE BLOCK *****
/* ***** 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
@ -21,7 +20,6 @@
*
* Contributor(s):
* Fabian Jakobs <fabian AT ajax DOT org>
* Mihai Sucan <mihai DOT sucan 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
@ -365,59 +363,9 @@ var Document = function(text) {
return end;
};
/**
* Move a range of text from the given range to the given position.
*
* @param fromRange {Range} The range of text you want moved within the
* document.
* @param toPosition {Object} The location (row and column) where you want
* to move the text to.
* @return {Range} The new range where the text was moved to.
*/
this.move = function(fromRange, toPosition) {
var text = this.getTextRange(fromRange);
this.remove(fromRange);
var toRow = toPosition.row;
var toColumn = toPosition.column;
// Make sure to update the insert location, when text is removed in
// front of the chosen point of insertion.
if (!fromRange.isMultiLine() && fromRange.start.row == toRow &&
fromRange.end.column < toColumn)
toColumn -= text.length;
if (fromRange.isMultiLine() && fromRange.end.row < toRow) {
var lines = this.$split(text);
toRow -= lines.length - 1;
}
var endRow = toRow + fromRange.end.row - fromRange.start.row;
var endColumn = fromRange.isMultiLine() ?
fromRange.end.column :
toColumn + fromRange.end.column - fromRange.start.column;
var toRange = new Range(toRow, toColumn, endRow, endColumn);
this.insert(toRange.start, text);
var delta = {
action: "move",
fromRange: fromRange,
toRange: toRange,
isMeta: true,
};
this._dispatchEvent("change", { data: delta });
return toRange;
};
this.applyDeltas = function(deltas) {
for (var i=0; i<deltas.length; i++) {
var delta = deltas[i];
if (delta.isMeta)
continue;
var range = Range.fromPoints(delta.range.start, delta.range.end);
if (delta.action == "insertLines")
@ -434,9 +382,6 @@ var Document = function(text) {
this.revertDeltas = function(deltas) {
for (var i=deltas.length-1; i>=0; i--) {
var delta = deltas[i];
if (delta.isMeta)
continue;
var range = Range.fromPoints(delta.range.start, delta.range.end);
if (delta.action == "insertLines")

View file

@ -602,6 +602,45 @@ var EditSession = function(text, mode) {
return this.doc.replace(range, text);
};
/**
* Move a range of text from the given range to the given position.
*
* @param fromRange {Range} The range of text you want moved within the
* document.
* @param toPosition {Object} The location (row and column) where you want
* to move the text to.
* @return {Range} The new range where the text was moved to.
*/
this.moveText = function(fromRange, toPosition) {
var text = this.getTextRange(fromRange);
this.remove(fromRange);
var toRow = toPosition.row;
var toColumn = toPosition.column;
// Make sure to update the insert location, when text is removed in
// front of the chosen point of insertion.
if (!fromRange.isMultiLine() && fromRange.start.row == toRow &&
fromRange.end.column < toColumn)
toColumn -= text.length;
if (fromRange.isMultiLine() && fromRange.end.row < toRow) {
var lines = this.doc.$split(text);
toRow -= lines.length - 1;
}
var endRow = toRow + fromRange.end.row - fromRange.start.row;
var endColumn = fromRange.isMultiLine() ?
fromRange.end.column :
toColumn + fromRange.end.column - fromRange.start.column;
var toRange = new Range(toRow, toColumn, endRow, endColumn);
this.insert(toRange.start, text);
return toRange;
};
this.indentRows = function(startRow, endRow, indentString) {
indentString = indentString.replace(/\t/g, this.getTabString());
for (var row=startRow; row<=endRow; row++) {
@ -751,7 +790,7 @@ var EditSession = function(text, mode) {
};
this.$updateWrapDataOnChange = function(e) {
if (!this.$useWrapMode || e.data.isMeta) {
if (!this.$useWrapMode) {
return;
}

View file

@ -271,9 +271,6 @@ var Editor =function(renderer, session) {
this.onDocumentChange = function(e) {
var delta = e.data;
if (delta.isMeta)
return;
var range = delta.range;
this.bgTokenizer.start(range.start.row);
@ -769,7 +766,7 @@ var Editor =function(renderer, session) {
if (this.$readOnly)
return null;
return this.session.doc.move(range, toPosition);
return this.session.moveText(range, toPosition);
};
this.copyLinesUp = function() {

View file

@ -1,5 +1,4 @@
/* vim:ts=4:sts=4:sw=4:
* ***** BEGIN LICENSE BLOCK *****
/* ***** 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
@ -129,9 +128,6 @@ oop.inherits(Mode, TextMode);
worker.call("setValue", [doc.getValue()]);
doc.on("change", function(e) {
if (e.data.isMeta)
return;
e.range = {
start: e.data.range.start,
end: e.data.range.end