move cursor to mouse on code dragging
This commit is contained in:
parent
c5962cdb8a
commit
b2193f714b
1 changed files with 9 additions and 6 deletions
|
|
@ -126,8 +126,8 @@ var MouseHandler = function(editor) {
|
|||
|
||||
var mousePageX, mousePageY;
|
||||
var overwrite = editor.getOverwrite();
|
||||
var dragCursor = null;
|
||||
var mousedownTime = (new Date()).getTime();
|
||||
var dragCursor, dragRange;
|
||||
|
||||
var onMouseSelection = function(e) {
|
||||
mousePageX = event.getDocumentX(e);
|
||||
|
|
@ -147,6 +147,7 @@ var MouseHandler = function(editor) {
|
|||
|
||||
var onMouseDragSelectionEnd = function() {
|
||||
dom.removeCssClass(editor.container, "ace_dragging");
|
||||
editor.session.removeMarker(dragSelectionMarker);
|
||||
|
||||
if (!self.$clickSelection) {
|
||||
if (!dragCursor) {
|
||||
|
|
@ -158,14 +159,13 @@ var MouseHandler = function(editor) {
|
|||
if (!dragCursor)
|
||||
return;
|
||||
|
||||
var selection = editor.getSelectionRange();
|
||||
if (selection.contains(dragCursor.row, dragCursor.column)) {
|
||||
if (dragRange.contains(dragCursor.row, dragCursor.column)) {
|
||||
dragCursor = null;
|
||||
return;
|
||||
}
|
||||
|
||||
editor.clearSelection();
|
||||
var newRange = editor.moveText(selection, dragCursor);
|
||||
var newRange = editor.moveText(dragRange, dragCursor);
|
||||
if (!newRange) {
|
||||
dragCursor = null;
|
||||
return;
|
||||
|
|
@ -190,6 +190,10 @@ var MouseHandler = function(editor) {
|
|||
onStartSelect(cursor);
|
||||
} else if ((time - mousedownTime) > DRAG_TIMER) {
|
||||
state = STATE_DRAG;
|
||||
dragRange = editor.getSelectionRange();
|
||||
var style = editor.getSelectionStyle();
|
||||
dragSelectionMarker = editor.session.addMarker(dragRange, "ace_selection", style);
|
||||
editor.clearSelection();
|
||||
dom.addCssClass(editor.container, "ace_dragging");
|
||||
}
|
||||
|
||||
|
|
@ -242,8 +246,7 @@ var MouseHandler = function(editor) {
|
|||
dragCursor.row = Math.max(0, Math.min(dragCursor.row,
|
||||
editor.session.getLength() - 1));
|
||||
|
||||
editor.renderer.updateCursor(dragCursor, overwrite);
|
||||
editor.renderer.scrollCursorIntoView();
|
||||
editor.moveCursorToPosition(dragCursor);
|
||||
};
|
||||
|
||||
event.capture(editor.container, onMouseSelection, onMouseSelectionEnd);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue