reset desiredColumn when needed instead of updating it all the time
This commit is contained in:
parent
ec9ef6c843
commit
fc500bb37a
2 changed files with 26 additions and 26 deletions
|
|
@ -180,7 +180,8 @@ function addCursorV(editor, dir){
|
|||
range.cursor = isBackwards ? range.start : range.end;
|
||||
|
||||
var screenLead = editor.session.documentToScreenPosition(range.cursor);
|
||||
screenLead.column = editor.selection.$desiredColumn;
|
||||
if (editor.selection.$desiredColumn)
|
||||
screenLead.column = editor.selection.$desiredColumn;
|
||||
|
||||
var lead = editor.session.screenToDocumentPosition(screenLead.row + dir, screenLead.column);
|
||||
|
||||
|
|
|
|||
|
|
@ -59,18 +59,18 @@ var Selection = function(session) {
|
|||
this.selectionLead = this.doc.createAnchor(0, 0);
|
||||
this.selectionAnchor = this.doc.createAnchor(0, 0);
|
||||
|
||||
var _self = this;
|
||||
var self = this;
|
||||
this.selectionLead.on("change", function(e) {
|
||||
_self._emit("changeCursor");
|
||||
if (!_self.$isEmpty)
|
||||
_self._emit("changeSelection");
|
||||
if (!_self.$preventUpdateDesiredColumnOnChange && e.old.column != e.value.column)
|
||||
_self.$updateDesiredColumn();
|
||||
self._emit("changeCursor");
|
||||
if (!self.$isEmpty)
|
||||
self._emit("changeSelection");
|
||||
if (!self.$keepDesiredColumnOnChange && e.old.column != e.value.column)
|
||||
self.$desiredColumn = null;
|
||||
});
|
||||
|
||||
this.selectionAnchor.on("change", function() {
|
||||
if (!_self.$isEmpty)
|
||||
_self._emit("changeSelection");
|
||||
if (!self.$isEmpty)
|
||||
self._emit("changeSelection");
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -180,12 +180,7 @@ var Selection = function(session) {
|
|||
this.setSelectionAnchor(range.start.row, range.start.column);
|
||||
this.selectTo(range.end.row, range.end.column);
|
||||
}
|
||||
this.$updateDesiredColumn();
|
||||
};
|
||||
|
||||
this.$updateDesiredColumn = function() {
|
||||
var cursor = this.getCursor();
|
||||
this.$desiredColumn = this.session.documentToScreenColumn(cursor.row, cursor.column);
|
||||
this.$desiredColumn = null;
|
||||
};
|
||||
|
||||
this.$moveSelection = function(mover) {
|
||||
|
|
@ -470,8 +465,14 @@ var Selection = function(session) {
|
|||
this.selectionLead.column
|
||||
);
|
||||
|
||||
var screenCol = (chars === 0 && this.$desiredColumn) || screenPos.column;
|
||||
var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenCol);
|
||||
if (chars === 0) {
|
||||
if (this.$desiredColumn)
|
||||
screenPos.column = this.$desiredColumn;
|
||||
else
|
||||
this.$desiredColumn = screenPos.column;
|
||||
}
|
||||
|
||||
var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenPos.column);
|
||||
|
||||
// move the cursor and update the desired column
|
||||
this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0);
|
||||
|
|
@ -481,7 +482,7 @@ var Selection = function(session) {
|
|||
this.moveCursorTo(position.row, position.column);
|
||||
};
|
||||
|
||||
this.moveCursorTo = function(row, column, preventUpdateDesiredColumn) {
|
||||
this.moveCursorTo = function(row, column, keepDesiredColumn) {
|
||||
// Ensure the row/column is not inside of a fold.
|
||||
var fold = this.session.getFoldAt(row, column, 1);
|
||||
if (fold) {
|
||||
|
|
@ -489,19 +490,17 @@ var Selection = function(session) {
|
|||
column = fold.start.column;
|
||||
}
|
||||
|
||||
this.$preventUpdateDesiredColumnOnChange = true;
|
||||
this.$keepDesiredColumnOnChange = true;
|
||||
this.selectionLead.setPosition(row, column);
|
||||
this.$preventUpdateDesiredColumnOnChange = false;
|
||||
this.$keepDesiredColumnOnChange = false;
|
||||
|
||||
if (!preventUpdateDesiredColumn)
|
||||
this.$updateDesiredColumn(this.selectionLead.column);
|
||||
if (!keepDesiredColumn)
|
||||
this.$desiredColumn = null;
|
||||
};
|
||||
|
||||
this.moveCursorToScreen = function(row, column, preventUpdateDesiredColumn) {
|
||||
this.moveCursorToScreen = function(row, column, keepDesiredColumn) {
|
||||
var pos = this.session.screenToDocumentPosition(row, column);
|
||||
row = pos.row;
|
||||
column = pos.column;
|
||||
this.moveCursorTo(row, column, preventUpdateDesiredColumn);
|
||||
this.moveCursorTo(pos.row, pos.column, keepDesiredColumn);
|
||||
};
|
||||
|
||||
// remove listeners from document
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue