rename selection.selectionLead to selection.lead
This commit is contained in:
parent
ad05b3a6c2
commit
c5bc3d96e0
1 changed files with 49 additions and 44 deletions
|
|
@ -64,11 +64,11 @@ var Selection = function(session) {
|
|||
this.doc = session.getDocument();
|
||||
|
||||
this.clearSelection();
|
||||
this.selectionLead = this.doc.createAnchor(0, 0);
|
||||
this.selectionAnchor = this.doc.createAnchor(0, 0);
|
||||
this.lead = this.selectionLead = this.doc.createAnchor(0, 0);
|
||||
this.anchor = this.selectionAnchor = this.doc.createAnchor(0, 0);
|
||||
|
||||
var self = this;
|
||||
this.selectionLead.on("change", function(e) {
|
||||
this.lead.on("change", function(e) {
|
||||
self._emit("changeCursor");
|
||||
if (!self.$isEmpty)
|
||||
self._emit("changeSelection");
|
||||
|
|
@ -93,8 +93,8 @@ var Selection = function(session) {
|
|||
**/
|
||||
this.isEmpty = function() {
|
||||
return (this.$isEmpty || (
|
||||
this.selectionAnchor.row == this.selectionLead.row &&
|
||||
this.selectionAnchor.column == this.selectionLead.column
|
||||
this.anchor.row == this.lead.row &&
|
||||
this.anchor.column == this.lead.column
|
||||
));
|
||||
};
|
||||
|
||||
|
|
@ -117,7 +117,7 @@ var Selection = function(session) {
|
|||
* Gets the current position of the cursor.
|
||||
**/
|
||||
this.getCursor = function() {
|
||||
return this.selectionLead.getPosition();
|
||||
return this.lead.getPosition();
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -128,7 +128,7 @@ var Selection = function(session) {
|
|||
* Sets the row and column position of the anchor. This function also emits the `'changeSelection'` event.
|
||||
**/
|
||||
this.setSelectionAnchor = function(row, column) {
|
||||
this.selectionAnchor.setPosition(row, column);
|
||||
this.anchor.setPosition(row, column);
|
||||
|
||||
if (this.$isEmpty) {
|
||||
this.$isEmpty = false;
|
||||
|
|
@ -146,7 +146,7 @@ var Selection = function(session) {
|
|||
if (this.$isEmpty)
|
||||
return this.getSelectionLead()
|
||||
else
|
||||
return this.selectionAnchor.getPosition();
|
||||
return this.anchor.getPosition();
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -155,7 +155,7 @@ var Selection = function(session) {
|
|||
* Returns an object containing the `row` and `column` of the calling selection lead.
|
||||
**/
|
||||
this.getSelectionLead = function() {
|
||||
return this.selectionLead.getPosition();
|
||||
return this.lead.getPosition();
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -167,7 +167,7 @@ var Selection = function(session) {
|
|||
**/
|
||||
this.shiftSelection = function(columns) {
|
||||
if (this.$isEmpty) {
|
||||
this.moveCursorTo(this.selectionLead.row, this.selectionLead.column + columns);
|
||||
this.moveCursorTo(this.lead.row, this.lead.column + columns);
|
||||
return;
|
||||
};
|
||||
|
||||
|
|
@ -192,8 +192,8 @@ var Selection = function(session) {
|
|||
* Returns `true` if the selection is going backwards in the document.
|
||||
**/
|
||||
this.isBackwards = function() {
|
||||
var anchor = this.selectionAnchor;
|
||||
var lead = this.selectionLead;
|
||||
var anchor = this.anchor;
|
||||
var lead = this.lead;
|
||||
return (anchor.row > lead.row || (anchor.row == lead.row && anchor.column > lead.column));
|
||||
};
|
||||
|
||||
|
|
@ -203,8 +203,8 @@ var Selection = function(session) {
|
|||
* [Returns the [[Range `Range`]] for the selected text.]{: #Selection.getRange}
|
||||
**/
|
||||
this.getRange = function() {
|
||||
var anchor = this.selectionAnchor;
|
||||
var lead = this.selectionLead;
|
||||
var anchor = this.anchor;
|
||||
var lead = this.lead;
|
||||
|
||||
if (this.isEmpty())
|
||||
return Range.fromPoints(lead, lead);
|
||||
|
|
@ -249,18 +249,23 @@ var Selection = function(session) {
|
|||
*
|
||||
**/
|
||||
this.setSelectionRange = function(range, reverse) {
|
||||
if (reverse) {
|
||||
this.setSelectionAnchor(range.end.row, range.end.column);
|
||||
this.selectTo(range.start.row, range.start.column);
|
||||
if (range.isEmpty()) {
|
||||
this.lead.setPosition(range.start.row, range.start.column);
|
||||
this.clearSelection();
|
||||
} else if (reverse) {
|
||||
this.$isEmpty = false;
|
||||
this.anchor.setPosition(range.end.row, range.end.column);
|
||||
this.lead.setPosition(range.start.row, range.start.column);
|
||||
} else {
|
||||
this.setSelectionAnchor(range.start.row, range.start.column);
|
||||
this.selectTo(range.end.row, range.end.column);
|
||||
this.$isEmpty = false;
|
||||
this.anchor.setPosition(range.start.row, range.start.column);
|
||||
this.lead.setPosition(range.end.row, range.end.column);
|
||||
}
|
||||
this.$desiredColumn = null;
|
||||
};
|
||||
|
||||
this.$moveSelection = function(mover) {
|
||||
var lead = this.selectionLead;
|
||||
var lead = this.lead;
|
||||
if (this.$isEmpty)
|
||||
this.setSelectionAnchor(lead.row, lead.column);
|
||||
|
||||
|
|
@ -391,7 +396,7 @@ var Selection = function(session) {
|
|||
**/
|
||||
this.getWordRange = function(row, column) {
|
||||
if (typeof column == "undefined") {
|
||||
var cursor = row || this.selectionLead;
|
||||
var cursor = row || this.lead;
|
||||
row = cursor.row;
|
||||
column = cursor.column;
|
||||
}
|
||||
|
|
@ -414,7 +419,7 @@ var Selection = function(session) {
|
|||
};
|
||||
|
||||
this.getLineRange = function(row, excludeLastChar) {
|
||||
var rowStart = typeof row == "number" ? row : this.selectionLead.row;
|
||||
var rowStart = typeof row == "number" ? row : this.lead.row;
|
||||
var rowEnd;
|
||||
|
||||
var foldLine = this.session.getFoldLine(rowStart);
|
||||
|
|
@ -463,7 +468,7 @@ var Selection = function(session) {
|
|||
* Moves the cursor left one column.
|
||||
**/
|
||||
this.moveCursorLeft = function() {
|
||||
var cursor = this.selectionLead.getPosition(),
|
||||
var cursor = this.lead.getPosition(),
|
||||
fold;
|
||||
|
||||
if (fold = this.session.getFoldAt(cursor.row, cursor.column, -1)) {
|
||||
|
|
@ -489,19 +494,19 @@ var Selection = function(session) {
|
|||
* Moves the cursor right one column.
|
||||
**/
|
||||
this.moveCursorRight = function() {
|
||||
var cursor = this.selectionLead.getPosition(),
|
||||
var cursor = this.lead.getPosition(),
|
||||
fold;
|
||||
if (fold = this.session.getFoldAt(cursor.row, cursor.column, 1)) {
|
||||
this.moveCursorTo(fold.end.row, fold.end.column);
|
||||
}
|
||||
else if (this.selectionLead.column == this.doc.getLine(this.selectionLead.row).length) {
|
||||
if (this.selectionLead.row < this.doc.getLength() - 1) {
|
||||
this.moveCursorTo(this.selectionLead.row + 1, 0);
|
||||
else if (this.lead.column == this.doc.getLine(this.lead.row).length) {
|
||||
if (this.lead.row < this.doc.getLength() - 1) {
|
||||
this.moveCursorTo(this.lead.row + 1, 0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
var tabSize = this.session.getTabSize();
|
||||
var cursor = this.selectionLead;
|
||||
var cursor = this.lead;
|
||||
if (this.session.isTabStop(cursor) && this.doc.getLine(cursor.row).slice(cursor.column, cursor.column+tabSize).split(" ").length-1 == tabSize)
|
||||
this.moveCursorBy(0, tabSize);
|
||||
else
|
||||
|
|
@ -515,8 +520,8 @@ var Selection = function(session) {
|
|||
* Moves the cursor to the start of the line.
|
||||
**/
|
||||
this.moveCursorLineStart = function() {
|
||||
var row = this.selectionLead.row;
|
||||
var column = this.selectionLead.column;
|
||||
var row = this.lead.row;
|
||||
var column = this.lead.column;
|
||||
var screenRow = this.session.documentToScreenRow(row, column);
|
||||
|
||||
// Determ the doc-position of the first character at the screen line.
|
||||
|
|
@ -548,7 +553,7 @@ var Selection = function(session) {
|
|||
* Moves the cursor to the end of the line.
|
||||
**/
|
||||
this.moveCursorLineEnd = function() {
|
||||
var lead = this.selectionLead;
|
||||
var lead = this.lead;
|
||||
var lastRowColumnPosition =
|
||||
this.session.getDocumentLastRowColumnPosition(lead.row, lead.column);
|
||||
this.moveCursorTo(
|
||||
|
|
@ -583,8 +588,8 @@ var Selection = function(session) {
|
|||
* Moves the cursor to the word on the right.
|
||||
**/
|
||||
this.moveCursorLongWordRight = function() {
|
||||
var row = this.selectionLead.row;
|
||||
var column = this.selectionLead.column;
|
||||
var row = this.lead.row;
|
||||
var column = this.lead.column;
|
||||
var line = this.doc.getLine(row);
|
||||
var rightOfCursor = line.substring(column);
|
||||
|
||||
|
|
@ -630,8 +635,8 @@ var Selection = function(session) {
|
|||
* Moves the cursor to the word on the left.
|
||||
**/
|
||||
this.moveCursorLongWordLeft = function() {
|
||||
var row = this.selectionLead.row;
|
||||
var column = this.selectionLead.column;
|
||||
var row = this.lead.row;
|
||||
var column = this.lead.column;
|
||||
|
||||
// skip folds
|
||||
var fold;
|
||||
|
|
@ -712,8 +717,8 @@ var Selection = function(session) {
|
|||
};
|
||||
|
||||
this.moveCursorShortWordRight = function() {
|
||||
var row = this.selectionLead.row;
|
||||
var column = this.selectionLead.column;
|
||||
var row = this.lead.row;
|
||||
var column = this.lead.column;
|
||||
var line = this.doc.getLine(row);
|
||||
var rightOfCursor = line.substring(column);
|
||||
|
||||
|
|
@ -730,8 +735,8 @@ var Selection = function(session) {
|
|||
};
|
||||
|
||||
this.moveCursorShortWordLeft = function() {
|
||||
var row = this.selectionLead.row;
|
||||
var column = this.selectionLead.column;
|
||||
var row = this.lead.row;
|
||||
var column = this.lead.column;
|
||||
|
||||
var fold;
|
||||
if (fold = this.session.getFoldAt(row, column, -1))
|
||||
|
|
@ -770,8 +775,8 @@ var Selection = function(session) {
|
|||
**/
|
||||
this.moveCursorBy = function(rows, chars) {
|
||||
var screenPos = this.session.documentToScreenPosition(
|
||||
this.selectionLead.row,
|
||||
this.selectionLead.column
|
||||
this.lead.row,
|
||||
this.lead.column
|
||||
);
|
||||
|
||||
if (chars === 0) {
|
||||
|
|
@ -814,7 +819,7 @@ var Selection = function(session) {
|
|||
}
|
||||
|
||||
this.$keepDesiredColumnOnChange = true;
|
||||
this.selectionLead.setPosition(row, column);
|
||||
this.lead.setPosition(row, column);
|
||||
this.$keepDesiredColumnOnChange = false;
|
||||
|
||||
if (!keepDesiredColumn)
|
||||
|
|
@ -836,8 +841,8 @@ var Selection = function(session) {
|
|||
|
||||
// remove listeners from document
|
||||
this.detach = function() {
|
||||
this.selectionLead.detach();
|
||||
this.selectionAnchor.detach();
|
||||
this.lead.detach();
|
||||
this.anchor.detach();
|
||||
this.session = this.doc = null;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue