Add getNext and operations on references
This commit is contained in:
parent
4feaf6c6fb
commit
e28a015a46
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -181,6 +181,21 @@ module.exports = function() {
|
|||||||
return this.beginning.next_cl;
|
return this.beginning.next_cl;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ListManager.prototype.getNext = function(start) {
|
||||||
|
var o;
|
||||||
|
o = start.next_cl;
|
||||||
|
while (!(o instanceof ops.Delimiter)) {
|
||||||
|
if (o.is_deleted) {
|
||||||
|
o = o.next_cl;
|
||||||
|
} else if (o instanceof ops.Delimiter) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return o;
|
||||||
|
};
|
||||||
|
|
||||||
ListManager.prototype.toArray = function() {
|
ListManager.prototype.toArray = function() {
|
||||||
var o, result;
|
var o, result;
|
||||||
o = this.beginning.next_cl;
|
o = this.beginning.next_cl;
|
||||||
@ -273,6 +288,16 @@ module.exports = function() {
|
|||||||
return this.insertAfter(this.end.prev_cl, [content]);
|
return this.insertAfter(this.end.prev_cl, [content]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ListManager.prototype.insertAfterHelper = function(root, content) {
|
||||||
|
var right;
|
||||||
|
if (!root.right) {
|
||||||
|
root.bt.right = content;
|
||||||
|
return content.bt.parent = root;
|
||||||
|
} else {
|
||||||
|
return right = root.next_cl;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
ListManager.prototype.insertAfter = function(left, contents) {
|
ListManager.prototype.insertAfter = function(left, contents) {
|
||||||
var c, j, len, right, tmp;
|
var c, j, len, right, tmp;
|
||||||
right = left.next_cl;
|
right = left.next_cl;
|
||||||
@ -301,12 +326,11 @@ module.exports = function() {
|
|||||||
return this.insertAfter(ith, contents);
|
return this.insertAfter(ith, contents);
|
||||||
};
|
};
|
||||||
|
|
||||||
ListManager.prototype["delete"] = function(position, length) {
|
ListManager.prototype.deleteRef = function(o, length) {
|
||||||
var d, delete_ops, i, j, o, ref;
|
var d, delete_ops, i, j, ref;
|
||||||
if (length == null) {
|
if (length == null) {
|
||||||
length = 1;
|
length = 1;
|
||||||
}
|
}
|
||||||
o = this.getOperationByPosition(position + 1);
|
|
||||||
delete_ops = [];
|
delete_ops = [];
|
||||||
for (i = j = 0, ref = length; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
|
for (i = j = 0, ref = length; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
|
||||||
if (o instanceof ops.Delimiter) {
|
if (o instanceof ops.Delimiter) {
|
||||||
@ -322,6 +346,15 @@ module.exports = function() {
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ListManager.prototype["delete"] = function(position, length) {
|
||||||
|
var o;
|
||||||
|
if (length == null) {
|
||||||
|
length = 1;
|
||||||
|
}
|
||||||
|
o = this.getOperationByPosition(position + 1);
|
||||||
|
return this.deleteRef(o, length);
|
||||||
|
};
|
||||||
|
|
||||||
ListManager.prototype.callOperationSpecificInsertEvents = function(op) {
|
ListManager.prototype.callOperationSpecificInsertEvents = function(op) {
|
||||||
var getContentType;
|
var getContentType;
|
||||||
getContentType = function(content) {
|
getContentType = function(content) {
|
||||||
|
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
@ -155,6 +155,19 @@ module.exports = ()->
|
|||||||
getFirstOperation: ()->
|
getFirstOperation: ()->
|
||||||
@beginning.next_cl
|
@beginning.next_cl
|
||||||
|
|
||||||
|
# get the next non-deleted operation
|
||||||
|
getNext: (start)->
|
||||||
|
o = start.next_cl
|
||||||
|
while not ((o instanceof ops.Delimiter))
|
||||||
|
if o.is_deleted
|
||||||
|
o = o.next_cl
|
||||||
|
else if o instanceof ops.Delimiter
|
||||||
|
return false
|
||||||
|
else break
|
||||||
|
|
||||||
|
o
|
||||||
|
|
||||||
|
|
||||||
# Transforms the the list to an array
|
# Transforms the the list to an array
|
||||||
# Doesn't return left-right delimiter.
|
# Doesn't return left-right delimiter.
|
||||||
toArray: ()->
|
toArray: ()->
|
||||||
@ -232,6 +245,14 @@ module.exports = ()->
|
|||||||
push: (content)->
|
push: (content)->
|
||||||
@insertAfter @end.prev_cl, [content]
|
@insertAfter @end.prev_cl, [content]
|
||||||
|
|
||||||
|
insertAfterHelper: (root, content)->
|
||||||
|
if !root.right
|
||||||
|
root.bt.right = content
|
||||||
|
content.bt.parent = root
|
||||||
|
else
|
||||||
|
right = root.next_cl
|
||||||
|
|
||||||
|
|
||||||
insertAfter: (left, contents)->
|
insertAfter: (left, contents)->
|
||||||
right = left.next_cl
|
right = left.next_cl
|
||||||
while right.isDeleted()
|
while right.isDeleted()
|
||||||
@ -266,9 +287,8 @@ module.exports = ()->
|
|||||||
#
|
#
|
||||||
# @return {ListManager Type} This String object
|
# @return {ListManager Type} This String object
|
||||||
#
|
#
|
||||||
delete: (position, length = 1)->
|
|
||||||
o = @getOperationByPosition(position+1) # position 0 in this case is the deletion of the first character
|
|
||||||
|
|
||||||
|
deleteRef: (o, length = 1) ->
|
||||||
delete_ops = []
|
delete_ops = []
|
||||||
for i in [0...length]
|
for i in [0...length]
|
||||||
if o instanceof ops.Delimiter
|
if o instanceof ops.Delimiter
|
||||||
@ -280,6 +300,11 @@ module.exports = ()->
|
|||||||
delete_ops.push d._encode()
|
delete_ops.push d._encode()
|
||||||
@
|
@
|
||||||
|
|
||||||
|
delete: (position, length = 1)->
|
||||||
|
o = @getOperationByPosition(position+1) # position 0 in this case is the deletion of the first character
|
||||||
|
|
||||||
|
@deleteRef o, length
|
||||||
|
|
||||||
|
|
||||||
callOperationSpecificInsertEvents: (op)->
|
callOperationSpecificInsertEvents: (op)->
|
||||||
getContentType = (content)->
|
getContentType = (content)->
|
||||||
|
Loading…
x
Reference in New Issue
Block a user