Merge pull request #1592 from ajaxorg/anchor_align_left
Add insert right mode for anchors and range_lists
This commit is contained in:
commit
0f83322450
2 changed files with 16 additions and 5 deletions
|
|
@ -82,6 +82,10 @@ var Anchor = exports.Anchor = function(doc, row, column) {
|
||||||
return this.document;
|
return this.document;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* experimental: allows anchor to stick to the next on the left
|
||||||
|
*/
|
||||||
|
this.$insertRight = false;
|
||||||
/**
|
/**
|
||||||
* Fires whenever the anchor position changes.
|
* Fires whenever the anchor position changes.
|
||||||
*
|
*
|
||||||
|
|
@ -115,8 +119,9 @@ var Anchor = exports.Anchor = function(doc, row, column) {
|
||||||
|
|
||||||
if (delta.action === "insertText") {
|
if (delta.action === "insertText") {
|
||||||
if (start.row === row && start.column <= column) {
|
if (start.row === row && start.column <= column) {
|
||||||
if (start.row === end.row) {
|
if (start.column === column && this.$insertRight) {
|
||||||
//if (start.column == column)
|
// do nothing
|
||||||
|
} else if (start.row === end.row) {
|
||||||
column += end.column - start.column;
|
column += end.column - start.column;
|
||||||
} else {
|
} else {
|
||||||
column -= start.column;
|
column -= start.column;
|
||||||
|
|
|
||||||
|
|
@ -204,11 +204,17 @@ var RangeList = function() {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (r.start.row == startRow && r.start.column >= start.column ) {
|
if (r.start.row == startRow && r.start.column >= start.column ) {
|
||||||
|
if (r.start.column == start.column && this.$insertRight) {
|
||||||
r.start.column += colDiff;
|
// do nothing
|
||||||
r.start.row += lineDif;
|
} else {
|
||||||
|
r.start.column += colDiff;
|
||||||
|
r.start.row += lineDif;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (r.end.row == startRow && r.end.column >= start.column) {
|
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
|
// 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 == start.column && colDiff > 0 && i < n - 1) {
|
||||||
if (r.end.column > r.start.column && r.end.column == ranges[i+1].start.column)
|
if (r.end.column > r.start.column && r.end.column == ranges[i+1].start.column)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue