add insert right mode for anchors and range_lists

This commit is contained in:
nightwing 2013-09-06 14:39:20 +04:00
commit 06d61cf239
2 changed files with 16 additions and 5 deletions

View file

@ -82,6 +82,10 @@ var Anchor = exports.Anchor = function(doc, row, column) {
return this.document;
};
/**
* experimental: allows anchor to stick to the next on the left
*/
this.$insertRight = false;
/**
* Fires whenever the anchor position changes.
*
@ -115,8 +119,9 @@ var Anchor = exports.Anchor = function(doc, row, column) {
if (delta.action === "insertText") {
if (start.row === row && start.column <= column) {
if (start.row === end.row) {
//if (start.column == column)
if (start.column === column && this.$insertRight) {
// do nothing
} else if (start.row === end.row) {
column += end.column - start.column;
} else {
column -= start.column;

View file

@ -204,11 +204,17 @@ var RangeList = function() {
break;
if (r.start.row == startRow && r.start.column >= start.column ) {
r.start.column += colDiff;
r.start.row += lineDif;
if (r.start.column == start.column && this.$insertRight) {
// do nothing
} else {
r.start.column += colDiff;
r.start.row += lineDif;
}
}
if (r.end.row == startRow && r.end.column >= start.column) {
if (r.end.column == start.column && this.$insertRight) {
continue;
}
// special handling for the case when two ranges share an edge
if (r.end.column == start.column && colDiff > 0 && i < n - 1) {
if (r.end.column > r.start.column && r.end.column == ranges[i+1].start.column)