some more mouse handler fixes
This commit is contained in:
parent
c6b4fc93f2
commit
389d33acac
2 changed files with 30 additions and 19 deletions
|
|
@ -42,12 +42,12 @@ define(function(require, exports, module) {
|
|||
var event = require("pilot/event");
|
||||
var dom = require("pilot/dom");
|
||||
|
||||
const STATE_UNKNOWN = 0;
|
||||
const STATE_SELECT = 1;
|
||||
const STATE_DRAG = 2;
|
||||
var STATE_UNKNOWN = 0;
|
||||
var STATE_SELECT = 1;
|
||||
var STATE_DRAG = 2;
|
||||
|
||||
const DRAG_TIMER = 500; // milliseconds
|
||||
const DRAG_OFFSET = 5; // pixels
|
||||
var DRAG_TIMER = 250; // milliseconds
|
||||
var DRAG_OFFSET = 5; // pixels
|
||||
|
||||
var MouseHandler = function(editor) {
|
||||
this.editor = editor;
|
||||
|
|
@ -115,17 +115,9 @@ var MouseHandler = function(editor) {
|
|||
selectionRange.contains(pos.row, pos.column);
|
||||
|
||||
if (!inSelection) {
|
||||
if (e.shiftKey)
|
||||
editor.selection.selectToPosition(pos)
|
||||
else {
|
||||
editor.moveCursorToPosition(pos);
|
||||
if (!editor.$clickSelection)
|
||||
editor.selection.clearSelection(pos.row, pos.column);
|
||||
}
|
||||
|
||||
// Directly pick STATE_SELECT, since the user is not clicking inside
|
||||
// a selection.
|
||||
state = STATE_SELECT;
|
||||
onStartSelect(pos);
|
||||
}
|
||||
|
||||
editor.renderer.scrollCursorIntoView();
|
||||
|
|
@ -143,7 +135,9 @@ var MouseHandler = function(editor) {
|
|||
|
||||
var onMouseSelectionEnd = function() {
|
||||
clearInterval(timerId);
|
||||
if (state == STATE_DRAG)
|
||||
if (state == STATE_UNKNOWN) {
|
||||
onStartSelect(pos);
|
||||
} else if (state == STATE_DRAG)
|
||||
onMouseDragSelectionEnd();
|
||||
else
|
||||
self.$clickSelection = null;
|
||||
|
|
@ -189,19 +183,36 @@ var MouseHandler = function(editor) {
|
|||
var distance = self.$distance(pageX, pageY, mousePageX, mousePageY);
|
||||
var time = (new Date()).getTime();
|
||||
|
||||
if (distance > DRAG_OFFSET)
|
||||
|
||||
if (distance > DRAG_OFFSET) {
|
||||
state = STATE_SELECT;
|
||||
else if ((time - mousedownTime) > DRAG_TIMER) {
|
||||
var cursor = editor.renderer.screenToTextCoordinates(mousePageX, mousePageY);
|
||||
cursor.row = Math.max(0, Math.min(cursor.row, editor.session.getLength()-1));
|
||||
onStartSelect(cursor);
|
||||
} else if ((time - mousedownTime) > DRAG_TIMER) {
|
||||
state = STATE_DRAG;
|
||||
dom.addCssClass(editor.container, "ace_dragging");
|
||||
}
|
||||
|
||||
} else if (state == STATE_DRAG)
|
||||
}
|
||||
|
||||
if (state == STATE_DRAG)
|
||||
onDragSelectionInterval();
|
||||
else if (state == STATE_SELECT)
|
||||
onUpdateSelectionInterval();
|
||||
};
|
||||
|
||||
function onStartSelect(pos) {
|
||||
if (e.shiftKey)
|
||||
editor.selection.selectToPosition(pos)
|
||||
else {
|
||||
editor.moveCursorToPosition(pos);
|
||||
if (!editor.$clickSelection)
|
||||
editor.selection.clearSelection(pos.row, pos.column);
|
||||
}
|
||||
state = STATE_SELECT;
|
||||
}
|
||||
|
||||
var onUpdateSelectionInterval = function() {
|
||||
var cursor = editor.renderer.screenToTextCoordinates(mousePageX, mousePageY);
|
||||
cursor.row = Math.max(0, Math.min(cursor.row, editor.session.getLength()-1));
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 6e1fbe1dfdff64020f15cd9e23ea72b7803cf406
|
||||
Subproject commit cbfac498d30d43fdb7687d198c5b752736222c2f
|
||||
Loading…
Add table
Add a link
Reference in a new issue