add selection.moveTo

This commit is contained in:
nightwing 2014-02-15 13:46:07 +04:00
commit 42a368ed02
11 changed files with 46 additions and 44 deletions

View file

@ -86,8 +86,7 @@ var AcePopup = function(parentNode) {
popup.on("mousedown", function(e) { popup.on("mousedown", function(e) {
var pos = e.getDocumentPosition(); var pos = e.getDocumentPosition();
popup.moveCursorToPosition(pos); popup.selection.moveToPosition(pos);
popup.selection.clearSelection();
selectionMarker.start.row = selectionMarker.end.row = pos.row; selectionMarker.start.row = selectionMarker.end.row = pos.row;
e.stop(); e.stop();
}); });

View file

@ -281,13 +281,13 @@ var EditSession = function(text, mode) {
**/ **/
this.setValue = function(text) { this.setValue = function(text) {
this.doc.setValue(text); this.doc.setValue(text);
this.selection.moveCursorTo(0, 0); this.selection.moveTo(0, 0);
this.selection.clearSelection();
this.$resetRowCache(0); this.$resetRowCache(0);
this.$deltas = []; this.$deltas = [];
this.$deltasDoc = []; this.$deltasDoc = [];
this.$deltasFold = []; this.$deltasFold = [];
this.setUndoManager(this.$undoManager);
this.getUndoManager().reset(); this.getUndoManager().reset();
}; };
@ -412,7 +412,7 @@ var EditSession = function(text, mode) {
} }
self.mergeUndoDeltas = false; self.mergeUndoDeltas = false;
self.$deltas = []; self.$deltas = [];
} };
this.$informUndoManager = lang.delayedCall(this.$syncInformUndoManager); this.$informUndoManager = lang.delayedCall(this.$syncInformUndoManager);
} }
}; };
@ -696,7 +696,7 @@ var EditSession = function(text, mode) {
this.$searchHighlight = this.addDynamicMarker(highlight); this.$searchHighlight = this.addDynamicMarker(highlight);
} }
this.$searchHighlight.setRegexp(re); this.$searchHighlight.setRegexp(re);
} };
// experimental // experimental
this.highlightLines = function(startRow, endRow, clazz, inFront) { this.highlightLines = function(startRow, endRow, clazz, inFront) {

View file

@ -1941,8 +1941,7 @@ var Editor = function(renderer, session) {
else else
this.selection.selectTo(pos.row, pos.column); this.selection.selectTo(pos.row, pos.column);
} else { } else {
this.clearSelection(); this.selection.moveTo(pos.row, pos.column);
this.moveCursorTo(pos.row, pos.column);
} }
} }
}; };
@ -1977,8 +1976,7 @@ var Editor = function(renderer, session) {
* @related Editor.moveCursorTo * @related Editor.moveCursorTo
**/ **/
this.navigateTo = function(row, column) { this.navigateTo = function(row, column) {
this.clearSelection(); this.selection.moveTo(row, column);
this.moveCursorTo(row, column);
}; };
/** /**
@ -1993,8 +1991,7 @@ var Editor = function(renderer, session) {
return this.moveCursorToPosition(selectionStart); return this.moveCursorToPosition(selectionStart);
} }
this.selection.clearSelection(); this.selection.clearSelection();
times = times || 1; this.selection.moveCursorBy(-times || -1, 0);
this.selection.moveCursorBy(-times, 0);
}; };
/** /**
@ -2009,8 +2006,7 @@ var Editor = function(renderer, session) {
return this.moveCursorToPosition(selectionEnd); return this.moveCursorToPosition(selectionEnd);
} }
this.selection.clearSelection(); this.selection.clearSelection();
times = times || 1; this.selection.moveCursorBy(times || 1, 0);
this.selection.moveCursorBy(times, 0);
}; };
/** /**
@ -2154,8 +2150,7 @@ var Editor = function(renderer, session) {
this.$blockScrolling += 1; this.$blockScrolling += 1;
var selection = this.getSelectionRange(); var selection = this.getSelectionRange();
this.clearSelection(); this.selection.moveTo(0, 0);
this.selection.moveCursorTo(0, 0);
for (var i = ranges.length - 1; i >= 0; --i) { for (var i = ranges.length - 1; i >= 0; --i) {
if(this.$tryReplace(ranges[i], replacement)) { if(this.$tryReplace(ranges[i], replacement)) {

View file

@ -130,8 +130,7 @@ AceEmmetEditor.prototype = {
*/ */
setCaretPos: function(index){ setCaretPos: function(index){
var pos = this.ace.indexToPosition(index); var pos = this.ace.indexToPosition(index);
this.ace.clearSelection(); this.ace.selection.moveToPosition(pos);
this.ace.selection.moveCursorToPosition(pos);
}, },
/** /**

View file

@ -122,8 +122,7 @@ exports.showErrorMarker = function(editor, dir) {
}; };
} }
editor.session.unfold(pos.row); editor.session.unfold(pos.row);
editor.selection.moveCursorToPosition(pos); editor.selection.moveToPosition(pos);
editor.selection.clearSelection();
var w = { var w = {
row: pos.row, row: pos.row,

View file

@ -201,8 +201,7 @@ var actions = exports.actions = {
//editor.selection.selectLine(); //editor.selection.selectLine();
//editor.selection.selectLeft(); //editor.selection.selectLeft();
var row = editor.getCursorPosition().row; var row = editor.getCursorPosition().row;
editor.selection.clearSelection(); editor.selection.moveTo(row, 0);
editor.selection.moveCursorTo(row, 0);
editor.selection.selectLineEnd(); editor.selection.selectLineEnd();
editor.selection.visualLineStart = row; editor.selection.visualLineStart = row;
@ -582,13 +581,11 @@ var handleCursorMove = exports.onCursorMove = function(editor, e) {
var cursorRow = editor.getCursorPosition().row; var cursorRow = editor.getCursorPosition().row;
if(originRow <= cursorRow) { if(originRow <= cursorRow) {
var endLine = editor.session.getLine(cursorRow); var endLine = editor.session.getLine(cursorRow);
editor.selection.clearSelection(); editor.selection.moveTo(originRow, 0);
editor.selection.moveCursorTo(originRow, 0);
editor.selection.selectTo(cursorRow, endLine.length); editor.selection.selectTo(cursorRow, endLine.length);
} else { } else {
var endLine = editor.session.getLine(originRow); var endLine = editor.session.getLine(originRow);
editor.selection.clearSelection(); editor.selection.moveTo(originRow, endLine.length);
editor.selection.moveCursorTo(originRow, endLine.length);
editor.selection.selectTo(cursorRow, 0); editor.selection.selectTo(cursorRow, 0);
} }
} }

View file

@ -53,8 +53,7 @@ function Motion(m) {
var a = getPos(editor, range, count, param, false); var a = getPos(editor, range, count, param, false);
if (!a) if (!a)
return; return;
editor.clearSelection(); editor.selection.moveTo(a.row, a.column);
editor.moveCursorTo(a.row, a.column);
}; };
m.sel = function(editor, range, count, param) { m.sel = function(editor, range, count, param) {
var a = getPos(editor, range, count, param, true); var a = getPos(editor, range, count, param, true);

View file

@ -122,13 +122,11 @@ module.exports = {
}, },
copyLine: function(editor) { copyLine: function(editor) {
var pos = editor.getCursorPosition(); var pos = editor.getCursorPosition();
editor.selection.clearSelection(); editor.selection.moveTo(pos.row, pos.column);
editor.moveCursorTo(pos.row, pos.column);
editor.selection.selectLine(); editor.selection.selectLine();
registers._default.isLine = true; registers._default.isLine = true;
registers._default.text = editor.getCopyText().replace(/\n$/, ""); registers._default.text = editor.getCopyText().replace(/\n$/, "");
editor.selection.clearSelection(); editor.selection.moveTo(pos.row, pos.column);
editor.moveCursorTo(pos.row, pos.column);
} }
}; };
}); });

View file

@ -72,8 +72,7 @@ function DefaultHandlers(mouseHandler) {
var selectionEmpty = selectionRange.isEmpty(); var selectionEmpty = selectionRange.isEmpty();
if (selectionEmpty) { if (selectionEmpty) {
editor.moveCursorToPosition(pos); editor.selection.moveToPosition(pos);
editor.selection.clearSelection();
} }
// 2: contextmenu, 1: linux paste // 2: contextmenu, 1: linux paste
@ -93,6 +92,7 @@ function DefaultHandlers(mouseHandler) {
} }
} }
this.captureMouse(ev);
if (!inSelection || this.$clickSelection || ev.getShiftKey() || editor.inMultiSelectMode) { if (!inSelection || this.$clickSelection || ev.getShiftKey() || editor.inMultiSelectMode) {
// Directly pick STATE_SELECT, since the user is not clicking inside // Directly pick STATE_SELECT, since the user is not clicking inside
// a selection. // a selection.
@ -101,7 +101,6 @@ function DefaultHandlers(mouseHandler) {
this.mousedownEvent.time = Date.now(); this.mousedownEvent.time = Date.now();
this.startSelect(pos); this.startSelect(pos);
} }
this.captureMouse(ev);
return ev.preventDefault(); return ev.preventDefault();
}; };
@ -114,8 +113,7 @@ function DefaultHandlers(mouseHandler) {
editor.selection.selectToPosition(pos); editor.selection.selectToPosition(pos);
} }
else if (!this.$clickSelection) { else if (!this.$clickSelection) {
editor.moveCursorToPosition(pos); editor.selection.moveToPosition(pos);
editor.selection.clearSelection();
} }
if (editor.renderer.scroller.setCapture) { if (editor.renderer.scroller.setCapture) {
editor.renderer.scroller.setCapture(); editor.renderer.scroller.setCapture();

View file

@ -32,7 +32,6 @@ define(function(require, exports, module) {
var event = require("../lib/event"); var event = require("../lib/event");
// mouse // mouse
function isSamePoint(p1, p2) { function isSamePoint(p1, p2) {
return p1.row == p2.row && p1.column == p2.column; return p1.row == p2.row && p1.column == p2.column;
@ -79,8 +78,7 @@ function onMouseDown(e) {
return; return;
screenCursor = newCursor; screenCursor = newCursor;
editor.selection.moveCursorToPosition(cursor); editor.selection.moveToPosition(cursor);
editor.selection.clearSelection();
editor.renderer.scrollCursorIntoView(); editor.renderer.scrollCursorIntoView();
editor.removeSelectionMarkers(rectSel); editor.removeSelectionMarkers(rectSel);
@ -95,7 +93,7 @@ function onMouseDown(e) {
if (ctrl && !shift && !alt && button == 0) { if (ctrl && !alt && !shift && button === 0) {
if (!isMultiSelect && inSelection) if (!isMultiSelect && inSelection)
return; // dragging return; // dragging
@ -122,7 +120,7 @@ function onMouseDown(e) {
editor.$blockScrolling--; editor.$blockScrolling--;
}); });
} else if (alt && button == 0) { } else if (alt && button === 0) {
e.stop(); e.stop();
if (isMultiSelect && !ctrl) if (isMultiSelect && !ctrl)
@ -135,8 +133,7 @@ function onMouseDown(e) {
screenAnchor = session.documentToScreenPosition(selection.lead); screenAnchor = session.documentToScreenPosition(selection.lead);
blockSelect(); blockSelect();
} else { } else {
selection.moveCursorToPosition(pos); selection.moveToPosition(pos);
selection.clearSelection();
} }

View file

@ -298,6 +298,27 @@ var Selection = function(session) {
}); });
}; };
/**
* Moves the selection cursor to the indicated row and column.
* @param {Number} row The row to select to
* @param {Number} column The column to select to
*
**/
this.moveTo = function(row, column) {
this.clearSelection();
this.moveCursorTo(row, column);
};
/**
* Moves the selection cursor to the row and column indicated by `pos`.
* @param {Object} pos An object containing the row and column
**/
this.moveToPosition = function(pos) {
this.clearSelection();
this.moveCursorToPosition(pos);
};
/** /**
* *
* Moves the selection up one row. * Moves the selection up one row.