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 mousePageX, mousePageY;
|
||||||
var overwrite = editor.getOverwrite();
|
var overwrite = editor.getOverwrite();
|
||||||
var dragCursor = null;
|
|
||||||
var mousedownTime = (new Date()).getTime();
|
var mousedownTime = (new Date()).getTime();
|
||||||
|
var dragCursor, dragRange;
|
||||||
|
|
||||||
var onMouseSelection = function(e) {
|
var onMouseSelection = function(e) {
|
||||||
mousePageX = event.getDocumentX(e);
|
mousePageX = event.getDocumentX(e);
|
||||||
|
|
@ -147,6 +147,7 @@ var MouseHandler = function(editor) {
|
||||||
|
|
||||||
var onMouseDragSelectionEnd = function() {
|
var onMouseDragSelectionEnd = function() {
|
||||||
dom.removeCssClass(editor.container, "ace_dragging");
|
dom.removeCssClass(editor.container, "ace_dragging");
|
||||||
|
editor.session.removeMarker(dragSelectionMarker);
|
||||||
|
|
||||||
if (!self.$clickSelection) {
|
if (!self.$clickSelection) {
|
||||||
if (!dragCursor) {
|
if (!dragCursor) {
|
||||||
|
|
@ -158,14 +159,13 @@ var MouseHandler = function(editor) {
|
||||||
if (!dragCursor)
|
if (!dragCursor)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var selection = editor.getSelectionRange();
|
if (dragRange.contains(dragCursor.row, dragCursor.column)) {
|
||||||
if (selection.contains(dragCursor.row, dragCursor.column)) {
|
|
||||||
dragCursor = null;
|
dragCursor = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
editor.clearSelection();
|
editor.clearSelection();
|
||||||
var newRange = editor.moveText(selection, dragCursor);
|
var newRange = editor.moveText(dragRange, dragCursor);
|
||||||
if (!newRange) {
|
if (!newRange) {
|
||||||
dragCursor = null;
|
dragCursor = null;
|
||||||
return;
|
return;
|
||||||
|
|
@ -190,6 +190,10 @@ var MouseHandler = function(editor) {
|
||||||
onStartSelect(cursor);
|
onStartSelect(cursor);
|
||||||
} else if ((time - mousedownTime) > DRAG_TIMER) {
|
} else if ((time - mousedownTime) > DRAG_TIMER) {
|
||||||
state = STATE_DRAG;
|
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");
|
dom.addCssClass(editor.container, "ace_dragging");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -242,8 +246,7 @@ var MouseHandler = function(editor) {
|
||||||
dragCursor.row = Math.max(0, Math.min(dragCursor.row,
|
dragCursor.row = Math.max(0, Math.min(dragCursor.row,
|
||||||
editor.session.getLength() - 1));
|
editor.session.getLength() - 1));
|
||||||
|
|
||||||
editor.renderer.updateCursor(dragCursor, overwrite);
|
editor.moveCursorToPosition(dragCursor);
|
||||||
editor.renderer.scrollCursorIntoView();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
event.capture(editor.container, onMouseSelection, onMouseSelectionEnd);
|
event.capture(editor.container, onMouseSelection, onMouseSelectionEnd);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue