some more mouse handler fixes

This commit is contained in:
Fabian Jakobs 2011-02-19 11:20:47 +01:00
commit 389d33acac
2 changed files with 30 additions and 19 deletions

View file

@ -42,12 +42,12 @@ define(function(require, exports, module) {
var event = require("pilot/event"); var event = require("pilot/event");
var dom = require("pilot/dom"); var dom = require("pilot/dom");
const STATE_UNKNOWN = 0; var STATE_UNKNOWN = 0;
const STATE_SELECT = 1; var STATE_SELECT = 1;
const STATE_DRAG = 2; var STATE_DRAG = 2;
const DRAG_TIMER = 500; // milliseconds var DRAG_TIMER = 250; // milliseconds
const DRAG_OFFSET = 5; // pixels var DRAG_OFFSET = 5; // pixels
var MouseHandler = function(editor) { var MouseHandler = function(editor) {
this.editor = editor; this.editor = editor;
@ -115,17 +115,9 @@ var MouseHandler = function(editor) {
selectionRange.contains(pos.row, pos.column); selectionRange.contains(pos.row, pos.column);
if (!inSelection) { 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 // Directly pick STATE_SELECT, since the user is not clicking inside
// a selection. // a selection.
state = STATE_SELECT; onStartSelect(pos);
} }
editor.renderer.scrollCursorIntoView(); editor.renderer.scrollCursorIntoView();
@ -143,7 +135,9 @@ var MouseHandler = function(editor) {
var onMouseSelectionEnd = function() { var onMouseSelectionEnd = function() {
clearInterval(timerId); clearInterval(timerId);
if (state == STATE_DRAG) if (state == STATE_UNKNOWN) {
onStartSelect(pos);
} else if (state == STATE_DRAG)
onMouseDragSelectionEnd(); onMouseDragSelectionEnd();
else else
self.$clickSelection = null; self.$clickSelection = null;
@ -189,19 +183,36 @@ var MouseHandler = function(editor) {
var distance = self.$distance(pageX, pageY, mousePageX, mousePageY); var distance = self.$distance(pageX, pageY, mousePageX, mousePageY);
var time = (new Date()).getTime(); var time = (new Date()).getTime();
if (distance > DRAG_OFFSET)
if (distance > DRAG_OFFSET) {
state = STATE_SELECT; 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; state = STATE_DRAG;
dom.addCssClass(editor.container, "ace_dragging"); dom.addCssClass(editor.container, "ace_dragging");
} }
} else if (state == STATE_DRAG) }
if (state == STATE_DRAG)
onDragSelectionInterval(); onDragSelectionInterval();
else if (state == STATE_SELECT) else if (state == STATE_SELECT)
onUpdateSelectionInterval(); 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 onUpdateSelectionInterval = function() {
var cursor = editor.renderer.screenToTextCoordinates(mousePageX, mousePageY); var cursor = editor.renderer.screenToTextCoordinates(mousePageX, mousePageY);
cursor.row = Math.max(0, Math.min(cursor.row, editor.session.getLength()-1)); cursor.row = Math.max(0, Math.min(cursor.row, editor.session.getLength()-1));

@ -1 +1 @@
Subproject commit 6e1fbe1dfdff64020f15cd9e23ea72b7803cf406 Subproject commit cbfac498d30d43fdb7687d198c5b752736222c2f